Can some one help me with canvas

does anyone know how to get center position for image sprite in a canvas

Do you want the centre position of a sprite or to put a sprite in the centre of the canvas ?

1 Like

yes exactly

Which one :smiley:

1 Like

put a sprite in the centre of the canvas

A sprite does not have an "OriginAtCentre" property (like the ball) because the dimensions of the image you use may not be the same (width = height). You will need to know these two dimensions (width and height) of the sprite, then divide each by 2, then remove the resultant values from your sprite X and Y positions. Your sprite will always a be a regular shape (rectangle).

An exaggerated example:

canvas 200px wide by 300px high
canvas centre is X = 100, Y = 150

sprite 40 px wide by 30px high
sprite centre = 20px and 15px

To centre the sprite on the canvas set the sprite X,Y to

X = (100 - 20) px > = 80px
Y = (150 - 15) px > = 135px

1 Like

Thanks it helped a lot

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.