Jump to content

Sprite position in terms of tiles


microspace
 Share

Recommended Posts

Is there a way to determine sprite position in terms of tiles, faster than in the example: 

 update: function () {
      var cposx = Math.floor(player.x / TileSize);
      var cposy = Math.floor(player.y / TileSize);
}

I dont want to load too much calculations inside update function. Maybe there is asynchronous way to do this or maybe there is built-in function to od this.

Link to comment
Share on other sites

Is it necessary to calculate position every frame? Maybe you could update players position only when he is actually moving, or even only once after the move ends. Besides, I do not think that such simple calculations could slow down game in any noticeable way.

Link to comment
Share on other sites

No, I don't need to calculate position every frame, only once he crosses tile boundary. 

On 12/16/2018 at 7:53 PM, nrbdch said:

Besides, I do not think that such simple calculations could slow down game in any noticeable way.

Maybe you are right

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...