Background not showing and actor starting position not centered (SOLVED)

Hi all, I am new to Defold and have been practicing with the default demo which has the logo.

I created a separate collection for background so the movement script does not also move the background.

When I run the game

  • first the background does not show

  • second the logo starts at the bottom left edge even though I placed it in middle

How can I fix these 2 things.

function init(self)
	msg.post(".", "acquire_input_focus")

	self.position = go.get_position()
	self.target_position = go.get_position()
end

function update(self, dt)
	self.position = vmath.lerp(0.2, self.position, self.target_position)
	go.set_position(self.position)
end

function on_input(self, action_id, action)
	if action_id == hash("click") and action.pressed then
		self.target_position.x = action.x
		self.target_position.y = action.y		
	end
end

Thanks

Do you have any rotation on any of the game objects? What are their Z values?

It loks like the logo is at position 0,0 (where the green and red axis meet). That is the lower left corner in runtime. The background is probably on a Z value outside of the -1 to 1 range.

Thanks for reply

Background is on -1 Z value while logo is 0 Z value

Ok, check the position of the sprite in the game object too. If the game object is at Z -1 and the sprite at Z -1 then the final position will be Z -2.

3 Likes

Both game object and sprite are at Z 0. Maybe am not getting something right. See current config for all objects and the final result:

background object / sprite property both have X 0, Y 0, Z 0 axis

Logo object and sprite property both have X 0, Y 0, Z 0 axis

But see result when I run game, both background and sprite are appearing from bottom left

Yes, that is expected. X position 0 is at left edge of screen and Y position 0 is at bottom edge of the screen. If you want it centered you need to set the positions to half the screen width and height. If you are using the mobile template, it is preset to screen size 640x1136.

1 Like

Yes I am using mobile template. Why is it that when I move the logo to center of screen, the ordinates is showing X 0, Y 0?

To make the logo appear in center of screen, do i need to write that in code?

You are probably getting confused by the background sprite. It is just another sprite. It does not define where the screen starts and ends. Check this annotated image:

3 Likes

Hmmm, I think I have along way to go. Thanks that answers all my questions :frowning:

1 Like

No, just put the background game object at X 320 and Y 568. Then put the logo game object at the same coordinates.

2 Likes

Yes that’s what I finally did and all looking OK. Thanks for your help.

2 Likes