Jump to content

Invert World Y coordinates


Paumonsu
 Share

Recommended Posts

Hello.

 

I'm having trouble with the current coordinate system.

 

The website I'm making is a platform-like "game", so I want the Y 0 world coordinate to be at the bottom of the canvas, not the top.

 

The way I've done it:

y = game.world.height - sceneSprite.y - sceneSprite.height;

But I find it very ugly. I just want assign 0 to the y coordinate so it positions at the bottom.

 

Can't find any documentation for inverting world coordinates, is there any way of doing this?

Link to comment
Share on other sites

This typical of computer-based coordinate systems and is present in pretty much every framework and system, including Flash. You may want to set the anchor.y of the sprite to 1, which will set its origin to the bottom, then you could create your own translation function though, something like this:

function invertY(y) {  return game.world.height - y;}sceneSprite.y = invertY(0);

You could even extend the sprite and make this all happen automatically, so the anchor would be set upon creating the extended sprite, and setting the y property of the sprite would automatically invert it as above.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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