GithubHelp home page GithubHelp logo

lrrrs / nd2d Goto Github PK

View Code? Open in Web Editor NEW
320.0 320.0 61.0 11.69 MB

A Flash Molehill (Stage3D) GPU accelerated 2D game engine

Home Page: http://www.nulldesign.de/category/experiments/nd2d/

ActionScript 100.00%

nd2d's People

Contributors

komelgman avatar kutu avatar nshen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

nd2d's Issues

Stage is null

For some reason, most Scene2D (= in the tests package) don't work which use the stage, because it is null. MaskTest works for example, it doesn't access the stage object anywhere.

Sprite2D Size not updating immediately

Problem: when using sprite.spritesheet.playAnimation("run"), sprite.width/height is not updated immediately.

Possible Solution 1:
+Sprite2d.as:
public function updateSize():void {
if(spriteSheet) {
_width = spriteSheet.spriteWidth;
_height = spriteSheet.spriteHeight;
}
}

Possible Solution 2:
+Sprite2d.as:
public function playAnimation(value:String ..... ):void {
if(spriteSheet) {
spriteSheet.playAnimation(value ...... );
_width = spriteSheet.spriteWidth;
_height = spriteSheet.spriteHeight;
}
}

getUVRectForFrame() array outside bounds

PostProcessingTest and SideScrollerTest throw this error:

RangeError: Error #1125: Index 2147483647 lies outside valid bounds of 35
at de.nulldesign.nd2d.materials::ASpriteSheetBase/getUVRectForFrame()[C:\Users\pc\Desktop\nd2dnew\src\de\nulldesign\nd2d\materials\ASpriteSheetBase.as:139

All other tests work now, thank you :)

Performance issues

Lately a major performance bottleneck has been identified on older devices, the confirmed ones I know of are: iPhone 4, iPad 1, iPod Touch 4, Nexus One and Galaxy Nexus.

Starling and Genome2D have both optimized for it, and from what they tell me:

The issue relates to these devices having limited fragment shaders when using any type of blending. For objects that have a value of 1.0, if the alpha operation is omitted from the shader, you can yield up to a 3x improvement in performance.

The one drawback is that batching needs to be separated now, instead of one batch to need to split them into alpha and non-alpha, but this only impacts higher end of devices, and the impact is generally minimal.

You can see my latest benchmarks here where I compare all the devices, you can see that Starling is outperforming ND2D 2:1 in most tests, except the iPad 2 where this seems to be a non-issue.
https://github.com/esDotDev/RunnerMark

Current build breaks DynamicTexturePlugin

The dynamic texture plugin needs to subclass ASpriteSheetBase, but a bunch of the properties are marked as internal.

If you'll switch to protected instead, it will resolve the issue.

ASpriteSheetBase @ Line 41:
protected var frames:Vector. = new Vector.();
protected var offsets:Vector. = new Vector.();
protected var sourceSizes:Vector. = new Vector.();
protected var sourceColorRects:Vector. = new Vector.();
protected var frameNameToIndex:Dictionary = new Dictionary();
protected var uvRects:Vector.;
protected var spritesPackedWithoutSpace:Boolean;

TextureAtlas parser API

I think that would be better to have some API for adding custom parsers for TextureAtlas, since some people can't use Zwoptex (no Mac) or TexturePacker (too costly). Something like this:
TextureAtlas.registerParser(name:String, parser:ATextureAtlasParser):void;

setFrameByAnimationName

This could be a pull request, but I thought it was simple enough to just post here.

I found this useful when creating one giant TextureAtlas to hold all my various graphics:

ASpriteSheetBase.as @ Line 185
public function setFrameByAnimationName(name:String):void {
if(animationMap[name]){
frame = animationMap[name].frames[0];
}
}

This way I can easily gotoAndStop on single frame animation.

Workaround would be something like:
s.spriteSheet.playAnimation("cloud");
s.spriteSheet.stopCurrentAnimation();

SpriteCloud of SpriteClouds

When adding a SpriteCloud to another SpriteCloud, only the first sprite shows up of the child.

i.e.

loop 4
{
loop 20
{
loop 30
{
sprite2d = new sprite2d
spriteCloudChild.addChild(sprite2d);
}
}
masterSpriteCloud.addChild(spriteCloudChild);
}
scene2d.addChild(masterSpriteCloud)

only the first sprite2d of each spriteCloudChild shows up.

Sprite2DCloud drawing 2 sprites only

Here's what I did:
when some.bitmapData is used for the first time
myCloud = new Sprite2DCloud(100, some.bitmapData);
myCloud.addChild(new Sprite2D());

whenever some.bitmapData is used again then Ijust
myCloud.addChild(new Sprite2D());

the result is that only first 2 children of myCloud are drawn, and I can't figure out why.

globalToLocal in Node2D doesn't take camera.x/y into account

Hi,

I was working with localToGlobal on a project and found I was getting odd results when the camera moved. Adding camera.x/y to the localToGlobal output Point fixed my issue.

I have a fork of the project, but didn't think it was worth making a pull request for this, and I've been modifying other things in there that you probably don't want in the framework... feel free to merge it (or ask me to make a pull request) if you want though :)

Have a look at localToGlobal in Node2D.as in this commit, specifically, where the output Point is created/set:
mikedotalmond@a1f936c

Also, the equivalent fix in (my modified version of) globalToLocal:
mikedotalmond@d8af9cd

Thanks for making a fun library :)

Parent alpha

Tweening parent alpha not actualy change child.
I use it for an animated display screen with some elements of.

PS:
Excuse my English, I use a translator))

change order of sprite rendering

i implemented change order of sprite rendering

add Node2D
public var z_order:Number = 0;
private var isReorderChildDirty:Boolean = false;

add method Node2D

        public function addChild(child:Node2D):Node2D {
            return addChildAt(child, children.length);
        }

        public function addChildZ(child:Node2D,z:Number):Node2D {
            isReorderChildDirty = true;
            return addChildAtZ(child, children.length,z);
        }


        public function addChildAtZ(child:Node2D,idx:uint,z:Number):Node2D
        {
            var existingIdx:int = getChildIndex(child);
            if(existingIdx != -1) {
                removeChildAt(existingIdx);
            }

            if(isBatchNode) {
                child.isBatchNode = isBatchNode;
            }
            child.z_order = z
            child.parent = this;
            child.setStageAndCamRef(_stage, camera);
            children.splice(idx, 0, child);

            return child;
        }

        public function addChildAt(child:Node2D, idx:uint):Node2D {

            return this.addChildAtZ(child,idx,children.length);

        }

               protected function sortAllChildren():void
        {
            //q-sort
            if (isReorderChildDirty) {
                if(children.length > 0) {
                    quickSort(children,0,children.length - 1);
                    isReorderChildDirty = false;
                }

            }
        }
        private function quickSort(vector:Vector.<Node2D>, left:Number, right:Number):void {

            var i:Number = 0,j:Number = 0;
            var node:Node2D = null;
            var tempNode:Node2D = null;

            i = left;
            j = right;
//          trace ('i<=j'+i+' <= '+ ' '+j);
            node = children[Math.round((left+right)*0.5)];
            while (i<=j) {
//              trace('vector[i].z_order '+vector[i].z_order);
//              trace('node.z_order) '+node.z_order);
                while (vector[i].z_order < node.z_order) {
                    i++;
                }
                while (vector[j].z_order > node.z_order) {
                    j--;
                }
                if (i<=j) {
                    tempNode = vector[i];
                    vector[i] = vector[j];
                    i++;
                    vector[j] = tempNode;
                    j--;
                }
            }
            if (left < j) {
                quickSort(vector, left, j);
            }
            if (i < right) {
                quickSort(vector, i, right);
            }
            return;
        }

                public function setZorder(z:Number):void
        {
            if (parent) {
                parent.reorderChild(z,this);
            }



        }


              public function reorderChild(z:Number,child:Node2D):void
        {
            if (!child) {
                return;
            }
            child.z_order = z;
            isReorderChildDirty = true;
        }

Modify method Node2D

    internal function drawNode(context:Context3D, camera:Camera2D, parentMatrixChanged:Boolean, statsObject:StatsObject):void {

        var myMatrixChanged:Boolean = false;

        if(!_visible) {
            return;
        }

        sortAllChildren();
              ...}

Modify method Scene2D

        override internal function drawNode(context:Context3D, camera:Camera2D, parentMatrixChanged:Boolean,   statsObject:StatsObject):void {


            sortAllChildren();

            for each(var child:Node2D in children) {
                child.drawNode(context, camera, false, statsObject);
            }

Hittest clicking

The current implementation of MouseEvent.click responds to the whole area of the bitmap of the scene. In contrast, the old flash2D clicking only response to non-transparent area whitch was quite handy. Is nd2d going to use the old way later or suggesting some new skills?
The imaginary scenario would be some monsters crowding in an isometric view. The player now wants to shoot one of them, by clicking on its body part that is not covered by another monster.

Feature request:TweenMax linkage

It would be nice to be able to use TweenMax along with Nd2d. TweenMax provides a lot of well tested 2d features. It doesn't have to be some api called 'useTweenMaxHere' but some general api and an instruction of how to use them together is good enough.

SpriteCloud offers no performance boost when using a spritesheets.

In my test, SpriteCloud is not rendering any faster than then normal Sprite2D's, when I'm using SpriteSheet. Same issue exists with SpriteBatch2D.

Using a single spritesheet, shared across all animations, caps out at about 380 @ 60fps, regardless of rendering technique.

Code for adding Sprite2D's is something like this:
texture = Texture2D.textureFromBitmapData(moleData);
spriteSheet = new SpriteSheet(texture.bitmapWidth, texture.bitmapHeight, frameWidth, frameHeight, 60);
spriteSheet.addAnimation("dig", [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19], true);

for(var i:int = particleList.length; i < numParticles; i++){
var s:Sprite2D = new Sprite2D(texture);
s.spriteSheet = spriteSheet;
s.spriteSheet.playAnimation("dig");
scene.addChild(s);
}

Code for adding with cloud, is like this:

texture = Texture2D.textureFromBitmapData(moleData);
cloud = new Sprite2DCloud(500, moleData);
spriteSheet = new SpriteSheet(texture.bitmapWidth, texture.bitmapHeight, frameWidth, frameHeight, 60);
spriteSheet.addAnimation("dig", [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19], true);
scene.addChild(cloud);

for(var i:int = particleList.length; i < numParticles; i++){
var s:Sprite2D = new Sprite2D();
s.spriteSheet = spriteSheet;
s.spriteSheet.playAnimation("dig");
cloud.addChild(s);
}

Obviously all frames are not in sync, and can't all be batched, but I'd assume the framework would be batching identical frames within the cloud, 20 batches for a 20 frame animation...

click only effective on 1/4

On 0.97.swf clicking is only effective on Rectangle(0,0,512,384) area. Is it a bug or I'm missing some config?

[SWF(width="1024", height="768", frameRate="60", backgroundColor="#000000")]
public class ClickTest extends World2D
{
private var _scene:Scene2D;

    public function ClickTest()
    {
        super(Context3DRenderMode.AUTO, 60);

        _scene = new Scene2D();
        _scene.mouseEnabled=true;
        _scene.backGroundColor = 0x00ff00;          
        _scene.addEventListener(MouseEvent.CLICK,clickHandler);
        setActiveScene(_scene);         
    }

    protected function clickHandler(event:MouseEvent):void
    {
        trace('click '+stage.mouseX+','+stage.mouseY);
    }
}

"Scale value must be greater than zero." error

Sprite2DBatchMaterial.as -> processAndRenderNodes()
I've got an error at this line:
clipSpaceMatrix.appendScale(child.spriteSheet.spriteWidth >> 1, child.spriteSheet.spriteHeight >> 1, 1.0)
I've changed it to this:
clipSpaceMatrix.appendScale(child.spriteSheet.spriteWidth * 0.5, child.spriteSheet.spriteHeight * 0.5, 1.0)
And all works fine now.

Pivot and Sprite2DCloud

Hi there! Great engine, thanks for your hard work.
I've found a bug. Pivots can't be used with sprites in the Sprite2DCloud.
Sprite always rotates around 0, 0 point. Regardless of the value of it's pivot.

To repeat this bug open "MassiveSpriteCloudTest.as" and find this function:
private function addSpritesClick(event:MouseEvent = null):void {
var s:Sprite2D;
for(var i:int = 0; i < 100; i++) {
s = new Sprite2D();
s.x = Math.round(Math.random() * 1000);
s.y = Math.round(Math.random() * 1000);
s.vx = (Math.random() - Math.random()) * 3;
s.vy = (Math.random() - Math.random()) * 3;
s.pivot = new Point(100, 100); <-------- And add this
...

Uncomment "s.rotation += 10;" in the "step" function.

P.S:
Is it possible to add _z property to the Node2D for a quick z-sorting? Using Add/RemoveChild in 3d engine is a bit strange...

Node2d/Sprite2d rendering into batches

Hello, I am curious as to why there is no batching of Sprite2ds with the same texture at consecutive levels in the global display hierarchy. This is done in Starling.

Didn't realize there is a forum. This is probably more appropriate for that.

AGALMiniAssembler

Description Resource Path Location Type
File could not be parsed. AGALMiniAssembler.as /nulldesign-nd2d/src/com/adobe/utils Unknown Flash Problem
Found ")" but newline or semicolon was expected at line 262 column 67. AGALMiniAssembler.as /nulldesign-nd2d/src/com/adobe/utils Unknown Flash Problem
Found "true" but newline or semicolon was expected at line 88 column 26. AGALMiniAssembler.as /nulldesign-nd2d/src/com/adobe/utils Unknown Flash Problem
Unexpected Token class at line 586 column 5. AGALMiniAssembler.as /nulldesign-nd2d/src/com/adobe/utils Unknown Flash Problem

ide - fdt 4.

http://code.google.com/p/away3d/source/browse/trunk/broomstick/Away3D/src/com/adobe/utils/AGALMiniAssembler.as parsed without errors

Pivot3d

Please add pivot3d:Vecor3D

MassiveSpritesTest too slow

at present i got 7/60fps if -debug=true via AIR/FP beta6
i think MassiveSpritesTest is faster before beta6?

Masking issues

I've been trying to use the masking and ran into a couple different issues.

  1. The edges of a mask continue out across the entire masked area.
  2. A mask at certain sizes shrink, as noted in this comment: http://www.nulldesign.de/2011/09/02/nd2d-stage3d-masks/#comment-35536

Here is a test swf and project to demonstrate these issues:
www.fapfaprevolution.com/tests/nd2dMaskGlitch/ - press space bar to cycle through the masks
www.fapfaprevolution.com/tests/nd2dMaskGlitch/nd2dMaskGlitch_fdproject.zip

how to understand this?

in a Scene2D class
var tex:Texture2D = ballTexture;
var ball:Sprite2D = new Sprite2D(tex);
ball.alpha = 0.6;
addChild(ball);

var ballOther:Sprite2D = new Sprite2D(tex);
ballOther.alpha = 0.5;
addChild(ballOther);

ballOther.addChild(ball);


I put a break point at drawNode

here is 3 times drawNode and content.drawTriangle
2 by ball , 1 by ballOther
alpha
0.6 , 0.5 , 0.3

but only two ball on sreen
why ?


ps:
i have test atf texture.
alpha ath work right on Sprite2D;
but has white backgroundColor on Sprite2DBatch;

not always , use different asset
i don't find out agal and blendmode has different place.

Better texture management

I find it is very slow to setTexture each frame to make an animation.Because it dispose the old texture very time.

And,I want Sprite2D can play an array of textures or bitmaps.

IOS supported?

I tried compiling a few examples of ND2D with the latest Air 3 RC. Everything works fine when I debug on desktop (IOS profile).
Once I package and installed on IOS, the app doesn't seem to work, it stucks on a blank white screen with a black box which is the stat viewer. Is Stage3D or ND2D supported in IOS at this stage?

Thanks

Pivots and the Sprite2DClouds, again :)

Hi Lars!
Pivots are still a little buggy :)
Just try "MassiveSpriteCloudTest.as" with s.pivot = new Point(0, -15);
(and vx = vy = 0)
While using Sprite2DBatch it is all ok (man rotates around his head). But in Sprite2DCloud it's rotates around bottom point of his legs. In this example it doesn't seem very important. But it ruins all my animations :)

Here is an example, first with Sprite2DBatch:
http://dl.dropbox.com/u/43384235/ok.html

And Sprite2DCloud:
http://dl.dropbox.com/u/43384235/bad.html

BitmapData and Sprite2D(BitmapData) visually not the same

package {

    import de.nulldesign.nd2d.display.Scene2D;
    import de.nulldesign.nd2d.display.Sprite2D;
    import de.nulldesign.nd2d.display.World2D;

    import flash.display.Bitmap;
    import flash.display.BitmapData;
    import flash.display.Shape;
    import flash.display.StageAlign;
    import flash.display.StageScaleMode;
    import flash.display3D.Context3DRenderMode;

    [SWF(width=1280, height=720, backgroundColor=0, frameRate=60)]

    public class Rect extends World2D {

        public function Rect() {
            stage.scaleMode = StageScaleMode.NO_SCALE;
            stage.align = StageAlign.TOP_LEFT;
            super(Context3DRenderMode.AUTO, 60, true);

            const scene:Scene2D = new Scene2D();

            const sh:Shape = new Shape();
            sh.graphics.beginFill(0xFFCC00);
            sh.graphics.drawRect(1, 1, 10, 10);
            sh.graphics.drawRect(3, 3, 6, 6);
            const bmd:BitmapData = new BitmapData(16, 16, false, 0);
            bmd.draw(sh);

            const sp:Sprite2D = new Sprite2D(bmd);
            sp.pivot.x = sp.pivot.y = -8;
            sp.x = 30;
            sp.y = 10;
            scene.addChild(sp);

            setActiveScene(scene);
            start();

            const bmp:Bitmap = new Bitmap(bmd);
            bmp.x = 10;
            bmp.y = 10;
            addChild(bmp);
        }

    }

}

Z-depth??, addChild remove child bug

Bug 1) depth works a bit different in the engine then in regular actionscript 3. and depth seems to work on sprite2d's but not sprite2d's that are in clouds.

Bug 2) to change depth of a sprite2d (not in cloud) you have to remove it from the scene and re-add it, instead of just scene.addChild(scene.getChildAt(0)) to bring it foremost, you have to say scene.removeChild(0); scene.addChild(sameSprite);

Here is example of modified hierarchy class:

package tests {
import de.nulldesign.nd2d.display.Node2D;
import de.nulldesign.nd2d.display.Scene2D;
import de.nulldesign.nd2d.display.Sprite2D;
import de.nulldesign.nd2d.display.Sprite2DCloud;
import de.nulldesign.nd2d.materials.BlendModePresets;
import de.nulldesign.nd2d.materials.SpriteSheet;

import flash.display.BitmapData;
import flash.events.MouseEvent;
import flash.geom.Point;

public class SpriteHierarchyTest2 extends Scene2D {

    [Embed(source="/assets/crate.jpg")]
    private var spriteTexture:Class;

    [Embed(source="/assets/spritechar2.png")]
    private var spriteTexture2:Class;

    private var s:Sprite2D;
    private var s2:Sprite2D;
    private var s3:Sprite2D;

    private var sc:Sprite2DCloud;

    public function SpriteHierarchyTest2() 
    {
        sc = new Sprite2DCloud(3,new spriteTexture().bitmapData);
        for(var i:int = 0; i < 3; i++)
        {
            s = new Sprite2D();
            s.addEventListener(MouseEvent.CLICK,sendToBack);
            s.scaleX = s.scaleY = 3-i;
            s.position = new Point(200, 200);
            sc.addChild(s);
        }
        addChild(sc);

        s = new Sprite2D(new spriteTexture().bitmapData);
        s.mouseEnabled = true;
       /* s.addEventListener(MouseEvent.MOUSE_OVER, mouseOver);
        s.addEventListener(MouseEvent.MOUSE_OUT, mouseOut);*/
        s.addEventListener(MouseEvent.CLICK,sendToBack);
        addChild(s);

        s2 = new Sprite2D(new spriteTexture().bitmapData);
        s2.mouseEnabled = true;
        /*s2.addEventListener(MouseEvent.MOUSE_OVER, mouseOver);
        s2.addEventListener(MouseEvent.MOUSE_OUT, mouseOut);*/
        s2.addEventListener(MouseEvent.CLICK,sendToBack);
        s2.x = s.x+80;
        s2.y = s.x+80;
        s2.scaleX = 0.5;
        s2.scaleY = 0.5;
        addChild(s2);

        var bmp:BitmapData = new spriteTexture2().bitmapData;

        var sheet:SpriteSheet = new SpriteSheet(bmp, 24, 32, 5);
        sheet.addAnimation("up", [6, 7, 8], true);

        s3 = new Sprite2D(null, sheet);
        s3.mouseEnabled = true;
        s3.addEventListener(MouseEvent.MOUSE_OVER, mouseOver);
        s3.addEventListener(MouseEvent.MOUSE_OUT, mouseOut);
        s3.scaleX = s3.scaleY = 4.0;
        s3.addEventListener(MouseEvent.CLICK,sendToBack);
        addChild(s3);
        s3.x = s2.x;
        s3.y = s2.y;

        s3.blendMode = BlendModePresets.NORMAL;
    }

    protected function sendToBack(event:MouseEvent):void
    {
        sendBack(event.currentTarget as Sprite2D);

        switch(event.currentTarget)
        {
            case s:
                sendBack(sc.getChildAt(0) as Sprite2D);
                break;
            case s2:
                sendBack(sc.getChildAt(1) as Sprite2D);
                break;
            case s3:
                sendBack(sc.getChildAt(2) as Sprite2D);
                break;
        }
    }

    private function sendBack(sprite2d:Sprite2D):void
    {
        var parent:Node2D = sprite2d.parent as Node2D;
        parent.removeChild(sprite2d);
        parent.addChildAt(sprite2d,0);
    }

    private function mouseOut(event:MouseEvent):void {
        event.target.tint = 0xffffff;
    }

    private function mouseOver(event:MouseEvent):void {
        event.target.tint = Math.random() * 0xffffff;
    }

    override protected function step(elapsed:Number):void {

        //s.x = stage.stageWidth / 2;
        //s.y = stage.stageHeight / 2;
        s.position = new Point(stage.stageWidth / 2, stage.stageHeight / 2);
        s2.position = s.position;
        s3.position = s2.position;
        //s.alpha = 0.5 + 0.5 * Math.sin(getTimer() / 500);
        s.rotation += 0.1;

        //s.pivot = new Point(Math.sin(getTimer() / 800) * 64, Math.cos(getTimer() / 800) * 64);

        s2.rotation -= 0.5;

        s3.rotation -= 0.5;
    }
}

}

Pop and push scenes

I'm a game developer from Tinime Games who are now using nd2d to develop a new flash game for our client and I want to say thank you so much for the talented work .

Is there a way like cocos2d to push and pop scene in the game world? I think it would be very useful .It would be great if you consider to add this feature in the future version. : )

Alpha not working in Sprite2D?

Hopefully I'm not doing something stupid here but setting the alpha property on Sprite2D doesn't seem to do anything. I experimented with SpriteTest from the examples and couldn't see any alpha transparency being rendered.

feature: custom shape in hitTest (processMouseEvents)

Add additional mouse capturing strategy. Current implementation not cover all variants of usage (example: custom shape button).

As a workaround, you can use:

  1. Alpha channel of texture in Sprite2D class and some custom treshold (not a perfect solution)
  2. Add shapeMask field (of type BitmapData) to Node2D and use binary bitmap for handling custom shapes (I vote for this solution)

I'm Back! spriteSheet.playAnimation and spriteSheet.frame

When using a spritesheet and you play an animation on just one sprite2d, you can no longer set a frame number on any other sprite2d inside the same cloud by using .frame. You have to set animations for all other items.

What I said may not make sense, so I made a demo of the issue. The middle guy is playing an animation, the rest of them have spritesheet.frame =

package tests {
import de.nulldesign.nd2d.display.Scene2D;
import de.nulldesign.nd2d.display.Sprite2D;
import de.nulldesign.nd2d.display.Sprite2DCloud;
import de.nulldesign.nd2d.display.World2D;
import de.nulldesign.nd2d.materials.SpriteSheet;

import flash.events.Event;

public class SpriteAnimTest2 extends Scene2D {

    [Embed(source="/assets/spritechar1.png")]
    private var spriteTexture:Class;

    private var sc:Sprite2DCloud;
    private var numOfSprites:int = 5;
    public function SpriteAnimTest2() {

        var sheet:SpriteSheet = new SpriteSheet(new spriteTexture().bitmapData, 24, 32, 5);
        sheet.addAnimation("up", [0, 1, 2], true);
        sheet.addAnimation("right", [3, 4, 5], true);
        sheet.addAnimation("down", [6, 7, 8], true);
        sheet.addAnimation("left", [9, 10, 11], true);

        sc = new Sprite2DCloud(numOfSprites,null,sheet);
        addChild(sc);
        addEventListener(Event.ADDED_TO_STAGE,sceneAdded);
        }

    protected function sceneAdded(event:Event):void
    {
        // TODO Auto-generated method stub
        removeEventListener(Event.ADDED_TO_STAGE,sceneAdded);
        for(var i:int = 0; i < numOfSprites; i++)
        {
            var s:Sprite2D = new Sprite2D();
            sc.addChild(s);

            //places in center
            s.y = stage.stageHeight/2;
            s.x = ((i-numOfSprites)*50)+stage.stageWidth/2;

            if(i == int(numOfSprites/2))
                s.spriteSheet.playAnimation("down");
            else
                s.spriteSheet.frame = i;
    }
}
}

}

Thanks!

Sprite2D.setMaterial problem

Hi there.
I'm tring to use nd2d for making a game.
And, I found some bug at Sprite2D.setMaterial method.

If make Sprite2D object first, and then assign Sprite2DMaterial later, like below,
I can't see any rendering image.

var sp:Sprite2D = new Sprite2D();
var sheet:SpriteSheet = new SpriteSheet(imageBitmapData, 100, 100, 5);
sheet.addAnimation('idle',[0,1,2],true);
var mat:Sprite2DMaterial = new Sprite2DMaterial(null, sheet);
sp.setMaterial(mat); // can't see any

So, I added some codes at Sprite2D.seMaterial

this.spriteSheet = material.spriteSheet;
if (material.bitmapData === null) material.bitmapData = this.spriteSheet.bitmapData;

Then, It works~!
I hope this helps.

Thanks for nice api.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.