Jump to content

setOrigin : For Placement or for Pivot/Offset point?


AdamRyanGameDev
 Share

Recommended Posts

In the labs it seems the origin()  is used for pivot/offset, see:

https://labs.phaser.io/edit.html?src=src\transform\rotation and origin.js

While the getting started guide, seems to indicate it would be for positional purposes

Part 2 says "this.add.image(0, 0, 'sky').setOrigin(0, 0) would reset the drawing position of the image to the top-left. In Phaser 2 this was achieved via the anchor property but in Phaser 3 it's the originX and originY properties instead."

 

Is this right? So I would need to basically position a sprite by its eventual offset/pivot point?

(Just checking because I am bit more used to positional anchor always using topLeft of sprite and then an offset point being declared separately)

 

Link to comment
Share on other sites

It's all of those. I guess it depends on what you mean by offset/positioning.

setOrigin(0.5) places the center of the texture on (sprite.x, sprite.y).

setOrigin(0) places the top-left of the texture on (sprite.x, sprite.y).

If you scale or rotate the sprite, the drawing position moves only if the origin isn't (0.5, 0.5). But none of that changes the sprite's position (x, y). 

Link to comment
Share on other sites

Thanks!

5 hours ago, samme said:

If you scale or rotate the sprite, the drawing position moves only if the origin isn't (0.5, 0.5). But none of that changes the sprite's position (x, y). 

Not absolutely sure I follow. What is the "drawing position" that moves?

 I always thought of it as placed at world(x,y) and then transformed not drawn. And so the (relative to sprite) pivot point (px,py) is indeed stationary (obviously!), the world(x.y) is constant too, but there are then transformations: Am I missing something? What position is being changed?

My Thinking Process (irrespective of texture postioning): position @ world x,y >>THEN>> define offset/pivot point x,y ** >>THEN>>> rotate around px,py

This seems to be 

position @ world x,y >>THEN>> define texture positioning tx,ty **  >THEN >> rotate around tx,ty

(**relative to sprite)

Am I confused? If the sprite texture position is equal to its pivot point for rotation this means it cannot rotate around a point external to the sprite. Eg a pendulum or swinging sprite (unless the sprite image included the empty space between the graphic that is 'swinging' and the pivot point.)

 

Link to comment
Share on other sites

I find this behaviour to be rather erratic.

If we look at the labs sandbox

https://labs.phaser.io/edit.html?src=src\transform\rotation and origin.js

And we delete just the rotation command for an image, we see that the sprite changes position. This means that the sprite is positioned in the canvas x,y because of its rotation status. It also means origin() needs to be set or reset each time rotation is /is not applied.

Is this desired behaviour? No problem just needs to be stated

Link to comment
Share on other sites

Back at my desktop computer and I cannot recreate what I thought I could see yesterday on my phone.

Disregard previous post, rotation() does not change world x,y. My bad, apologies.

However, it still stands that origin is used as both texture placement coordinates AND as pivot point, and that I would contend these should be two separate parameters.

Is there an offset() variable that I haven-t come across yet?

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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