Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
206 views
in Technique[技术] by (71.8m points)

javascript - Canvas Game Animation

So I a making a game and got the idea of having a semi transparent png animation from a spritesheet to appear when the player gets put back to the start after he dies.

http://www.youtube.com/watch?v=s2Vwyqo_y_A

It's just I have never gotten around to animation yet a for some reason I think the manipulating the animrequestframe thingy kinda confusing. I have it set so my game refreshes every 60 times a second.

Would love some advice to help me out! :/ It's my first 'proper' game!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

If you're struggling getting your head around requestFrameAnimation, I suggest you read these couple of links, they explain it really well:

  1. The secret to silky smooth JavaScript animation!
  2. Using requestAnimationFrame

The simplest example given:

function gameLoop() {
  // Game logic
  requestAnimationFrame(gameLoop);
}
requestAnimationFrame(gameLoop);

EDIT: You mention you want your game to run every at 60 FPS. Request animation will run your game as fast as it can - which is a good thing - but there are tricks to set the actual FPS. However, unless you're aiming for a lower FPS, like 30, I wouldn't bother.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...