Jump to content

Changing World Coordinates relative to camera


matt.hilliard
 Share

Recommended Posts

I'm trying to do what the topic says...

 

I'm doing a tech spike with a requirement that the origin applied to all assets in a game scene can be changed visually--no discernible calculations when adding assets to a scene given world coordinate offsets from said point (for example, the world origin might need to be the center of the canvas) or it might be the top left of an asset bucket of lower resolution than the game's canvas.

 

I've tried growing the world bounds and changing the camera's position, that this seems to update things added to the world prior to the change, but I'm not sure what needs to happen so that everything added to the scene thereafter assumes the offsets.  So, for example trying to move the world origin down and right 100 pixels...

 

            var originOffsetX = 100;
            var originOffsetY = 100;
            game.world.setBounds(0, 0, this.game.scale.width + originOffsetX, game.scale.height + originOffsetY);
            this.game.camera.bounds = null;
            this.game.camera.setPosition(-originOffsetX, -originOffsetY);
Link to comment
Share on other sites

I've done this in my project, it turns the world into a limitless expanse:

        this.world.bounds.x = -Infinity;        this.world.bounds.y = -Infinity;        this.world.bounds.width = Infinity;        this.world.bounds.height = Infinity;        this.camera.bounds.x = -Infinity;        this.camera.bounds.y = -Infinity;        this.camera.bounds.width = Infinity;        this.camera.bounds.height = Infinity;

Now you can always go this.game.camera.setPosition(-x, -y) and the world origin (0, 0) will be at (x, y) in browser space.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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