开发者

Java ME. How to animate Sprite

开发者 https://www.devze.com 2023-02-20 14:30 出处:网络
I am having trouble with animating my sprite in Java ME. if ((k & FIRE_PRESSED) != 0) { spriteActive = true;

I am having trouble with animating my sprite in Java ME.

   if ((k & FIRE_PRESSED) != 0) {
        spriteActive = true;
        boxer.nextFram开发者_运维技巧e();
        if (boxer.getFrame() == boxer.getFrameSequenceLength() - 6) {
            spriteActive = false;
        }
    }
}

    // TO re-start a game...

    public void update() {
        if(boxer.getRawFrameCount() == 5 && spriteActive == false){
            boxer.setFrame(0);
        }

    }

When the enter key is pressed, spriteActive is set true but only changes the frame by one. I intend to have it animating the entire sequence but it is not doing that. Just animates 1 frame at a time with every press.

Does anyone have any ideas/advice of how I should approach this?

Thanks for the time and help!


Do you have any code that checks whether spriteActive is true and then sets the next frame? I am no expert on Java but I would suspect you'd need to implement something like this:

if (spriteActive == true)
{
     boxer.nextFrame();
}
0

精彩评论

暂无评论...
验证码 换一张
取 消