Show the original image of the sprite

So, I'm familiarizing with the object model and I hit this problem.

I have a sprite, it contains an image and 2 animations to move left and right.

this is the code of onUpdate

if (wade.isKeyDown ('left')) {
    if (this.getSprite().getCurrentAnimationName()!='Walk_left')  this.playAnimation('Walk_left');
} else if (wade.isKeyDown('right')) {
    if (this.getSprite().getCurrentAnimationName()!='Walk_right')  this.playAnimation('Walk_right');
} else {
    // ????? Display the original image of the sprite

I assume that this is the SceneObject so it appears that I can play a sprite animation directly from this and not this.getSprite(). But SceneObjects can have multiple sprites, which may contain animations (maybe with the same names, I will try).

But the real problem is: how do I show the original sprite, the one that appers when the game is loaded, when no keys are currently pressed?

The whole thing is here, if you want to take a look




1 Comment


You are right, you can call playAnimation() on the SceneObject. This, in effect, calls playAnimation on each Sprite of the SceneObject. If you want you can also do this.getSprite().playAnimation() (i.e. call playAnimation on the Sprite) if you need to play a different animation on each Sprite.

To answer your question, you could create an idle animation (with just 1 frame) and call this.playAnimation('idle'). The good news is that Wade does this automatically, and adds a default animation to the Sprite when the Sprite is created (using the Sprite's image file, and 1 single animation frame). So in most cases you can just do:


This displays the whole sprite image as a static animation. So if you are using a spritesheet that contains all your Sprite's animations rather than a separate image for the static animation, then creating a separate idle animation is the way to go.

Post a reply
Add Attachment
Submit Reply
Login to Reply