Is the way I am using sprite animations for puzzle blocks okay? And is FlxTypedGroup okay for them?



  • The important parts of my block sprite class
    this.memberID = memberID; // so I can access it through flxtypedgroup
    loadGraphic(AssetPaths.cellTileBlocks90__png, true, CELL_SIZE, CELL_SIZE);
    for(i in 0...MAX_ANIMATION_ID){
    animation.add(Std.string(i), [i], 1, false); // just using to change unanimated image
    }

    private function changeAnimation(newBlockID:Int):Void{
    animation.play(Std.string(newBlockID));
    }

    My game is a 8x8 match 3 puzzle type game. It feels wrong to have 64 puzzle blocks all with the exact same animation set up just so I can change what block is currently being displayed. Right now I have around 40 different puzzle blocks the image they each load which means 40 animations each. The blocks are not actually animated though I am just changing the image. I have been thinking maybe it would be better just to loadGraphic a new sprite to change the image rather than changing animation but I am not sure.....

    blockGroup.members[memberID].changeAnimation(Block.GREEN);

    Maybe I am worried for nothing though. If I understand correctly they all share the same instance in the graphics cache. I think I understand that but I am not sure how having lots of different animations might affect things.

    The reason I am asking is because my performance is not really where I want it to be even with nothing happening other than displaying the 64 sprites + some UI. The FlxBunnyMark with the default settings and 1000 bunnies gives me 60 FPS and that should be FAR more intensive than my game.. I tried to get hxScout to work but opening a windows version of the game crashes instantly if I have hxScout open.

    My other question is should I be using FlxTypedSpriteGroup? FlxTypedGroup and FlxTypedSpriteGroup both seem to do the same thing so I am not sure if there is a reason to switch to FlxTypedSpriteGroup.



  • If I understand the question correctly then you want to change animation.frameIndex directly. For this to work there is no need to call animation.add() or animation.play() at all.



  • I think using frameIndex reduced the memory usage by .5 MB but using that method does not work with FlxMouseEventManager it seems.



  • I'm actually using it together with FlxMouseEventManager. What is your problem?



  • When I tested it turns out I commented out one of the functions I thought I did not need. Retested it and it works, thanks.

    The main reason for this topic was kind of hope to get HTML5 working. With how many people keep posting that they also can not get HTML5 performing well I probably just need to give up on it.


Log in to reply