How to scale it from a different "center"


(Secret) #1

Hi guys, whenever I scale the graphic using scaleX or scaleY it always scales relative to the (0,0) position of the graphic. How do I make it so that the scaling comes from the actual center of the graphic?


(Justin Wolf) #2

Use centerOrigin() on your graphic.


(Secret) #3

Thanks. Works like charm


(icemedia) #4

are there any way to set arbitary center of the entity? such as set rotation center(pivot) at any given (x,y) ~


(Jean) #5

On the Image class there is centerX and centerY. That should do the trick.


(icemedia) #6

Hi ,

centerX and centerY are just readonly perperties so can’t set.

see picture below, the upper-left corner small green rect is pivot of the entity? actually setOrigin(x,y)/centerOrigen() have no impact to it. I see only hitbox is affected by setOrigin. are there ways to change pivot to center of the entity?


(Martí Angelats i Ribera) #7

originX and originY. That’s what you are looking for.

centerX and centerY is a only-read property wich is the position of the center in the world.


(Jacob Albano) #8

Entities have originX and originY; those govern the registration point of the hitbox.

To change the center of rotation on a graphic, use centerX and centerY on the graphic itself. Note that they don’t exist on every type; for example, Image and Spritemap both have origins, but Tilemap and Emitter do not.