Jambutters Posted April 10, 2017 Share Posted April 10, 2017 Noob to game dev here, this is more of a general javascript question but: I'm looking over kittykatattacks spriteUtilities library and var frameRate = 1000 / sprite.fps; //Set the sprite to the starting frame sprite.gotoAndStop(startFrame); //Set the `frameCounter` to the first frame frameCounter = 1; //If the state isn't already `playing`, start it if (!sprite.animating) { timerInterval = setInterval(advanceFrame.bind(this), frameRate); } So how does this(the sprites fps) not conflict with the games fps? Generally you have the main game update loop somewhere that's also a setInterval(gameLoop, fps). and javascript is synchronous right? Quote Link to comment Share on other sites More sharing options...
xerver Posted April 11, 2017 Share Posted April 11, 2017 Yes, JS is a synchronous event loop; but not everything has to run every loop. Similarly if the "fps" of the sprite is faster than display that is OK too since we will just calculate what frame to show not actually simulate each "sprite frame". Quote Link to comment Share on other sites More sharing options...
Taz Posted April 11, 2017 Share Posted April 11, 2017 You can change the sprite's texture and other properties as often as you like, but render is still called at the same rate* (render handles all of the actual drawing to screen). On the other hand, if you were updating the same property at two different time intervals that could be problematic. *well, assuming your interval functions finish quickly enough, etc. That's a different issue thou.. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.