Comments (4)
onStep is based on interval which is set to 25
onRender is using requestAnimationFrame which will run as fast as possible
You should use delta in your formulas like
x += speed * delta / 1000;
Speed is in pixels per second. Try to put that in both render and step and you will notice that they go at the same speed.
from canvasquery.
Thank you for your reply, I should have used delta before but I was missing a formula so double thanks.
But why don't the 2 methods use requestAnimationFrame ?
from canvasquery.
Well this is really simple.
When you change the tab in the browser.
requestAnimationFrame stops - which is something you really want because it also stops to drain users CPU
but the setInterval is still going - that's why we use it for logic update - because usually you want the game to proceed - same as you are alt-tabbing in windows.
Why not put logic in animationFrame? Because logic can be really heavy - for example when using physics - and you don't need 60 updates per second for physics - it could just kill the performance.
ps: well you can decrease FPS rate manually in requestAnimationFrame, so this is not 100% accurate answer :)
from canvasquery.
I was using requestAnimationFrame for everything, thinking it would boost my games' performance but it was not the right way of using it.
Thanks for the explanation.
from canvasquery.
Related Issues (20)
- Are colors broken right now? HOT 2
- Demos or tutorials? HOT 1
- Version 0.9.1 HOT 1
- drawSprite missing HOT 1
- text size HOT 1
- Logitech Universal Reciever is incorrectly recognised as a gamepad HOT 1
- Old browsers compatibility requestAnimationFrame HOT 2
- preventContextMenu not working HOT 1
- Sprites in Playground HOT 15
- Align HOT 8
- drawAtlasFrame() does not use x,y HOT 1
- Touchend is unreliable in multitouch HOT 4
- Integrating Playground with THREE.js
- Plugins in Playground HOT 1
- Mouselock Movement-Delta unprecise and IExplorer incompatible
- npm and browserify support HOT 14
- playground.Keyboard.prototype.keypress Event is an empty Function. HOT 7
- swapping color palettes
- cq.loadImages can not to use!
- Flip Sprite HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from canvasquery.