microspace

Sprite position in terms of tiles

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.

Share this post


Link to post
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.

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

  • Recently Browsing   0 members

    No registered users viewing this page.