Jump to content

How to animate sprite


Oroton
 Share

Recommended Posts

and play here..
www.brissyriders.com/turtlewiz/index.htm

What i am wanting is to know how do I animate the character. and how can i animate the enemies.
I have extended the character (turtle.png) sprite sheet, but I don't know how to animate it when he walks. Or how to Animate the enimies, can anyone help me?

Thanks.

 

Turtlewiz_files.zip

Link to comment
Share on other sites

So, you can see where all the added Animation code is..
with //Added by Oroton.

Any help here would be good. I just can't figure out why it isn't animating I think it's a syntax error.

Found around Here..


Sprite.prototype.draw = function() {
    if (!this.flashOn) {
        ctx.drawImage(
            this.tileset.image,           /*         Obscure everthing below this           */          //Added by Oroton
            this.states[this.currentState].frames[this.states[this.currentState].currentFrame].split(',')[0] * this.tileset.tileWidth,
            this.states[this.currentState].frames[this.states[this.currentState].currentFrame].split(',')[1] * this.tileset.tileHeight,
            this.tileset.tileWidth,       /*         Obscure everthing above this           */          //Added by Oroton
            this.tileset.tileHeight,
            Math.round(this.x),
            Math.round(this.y),
            this.width,
            this.height
        );
    }
}

wizAnim.zip

Link to comment
Share on other sites

Try to change the current sprite every X frames.

I use a counter for this task. Its value is raised by 1 every thime I refresh the screen. So if I update the screen 60 times per second (which means it's running with 60 FPS), I tell my objects which one of their costumes should they wear for the first 10 frames, then the next 10 and so on until their cycle is finished, then I set the counter back to 0.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...