Hi I am developing a game using HTML5 canvas. In the game I use a lot of the coordinate x and y, but sometimes they are floating point values. I am not sure if this has positive effects to the performance of the game and the accuracy of the sprites movement in the game. Is it correct to use floating point values of x and y or do I need to convert them into integers?
Asked
Active
Viewed 812 times
3
-
2_I am not sure if this has positive effects to the performance.._ Don't worry about performance. JS has no specific type for integers. All numbers, both float and integers, are stored and handled as floating-point numbers ([ref.](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Numbers_and_dates#Numbers)). – hindmost Jul 07 '16 at 14:25
-
@hindmost thanks. I have read some resources saying I should convert floating point values to integers (http://www.html5rocks.com/en/tutorials/canvas/performance/#toc-avoid-float) but since the documentation says not to worry I am inclined to believe what you put here. – newguy Jul 07 '16 at 14:35
2 Answers
1
I doubt it has any performance benefits or drawbacks.
However, you might encounter blurred shapes when using just integer values but it depends on what you're trying to do. See similar question: Canvas drawings, like lines, are blurry.
0
newguy!
If you need use float values, you can use it, sometimes it's necessary.
1) Make a game;
2) If this game has low performance, try to optimize.

Aleksey Dubinskiy
- 185
- 2
- 11