Center On Screen An Off Screen Sprite?

Hi,

I have a sprite off of the screen which I am trying to center on the screen.
Please take a look at my source code and let me know what I am doing wrong:
NOTE: The position of the sprite is (-500, -500) & the screen size is (360x640)

function init(self)
	-- Add initialization code here
	-- Remove this function if not needed

	go.set("#FAS-Statue", "scale.x", 0.65)
	go.set("#FAS-Statue", "scale.y", 0.65)

	local sprPosOld = go.get_world_position("#FAS-Statue") -- Position set to (-500, -500)
	sprPosOld.x = sprPosOld.x * -1
	sprPosOld.y = sprPosOld.y * -1
	local sprPos = vmath.vector3( sprPosOld.x+(360/2), sprPosOld.y+(640/2), 1 ) -- Trying to center on screen, screen is (360x640)
	go.set_position( sprPos,"#FAS-Statue" )
	-- More to come soon!
end

Thanks!

Jesse
www.FallenAngelSoftware.com

500 + 360/2 is 680
500 + 640/2 is 820

680, 820, 1 is off-screen.

Furthermore. You try to get and set the position of a component (a sprite?), not a game object. You can’t do that.

1 Like

Hi,

I have something that is working, but not sure if it’s correct?
Builds with no errors in Defold console and runs fine.
Please take a look at below dev screenshot:

Thanks in advance…

Jesse