Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should HTML5 canvas coordinates use floating point or integer?

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?

like image 262
newguy Avatar asked May 11 '26 19:05

newguy


1 Answers

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.

like image 198
martin Avatar answered May 14 '26 10:05

martin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!