Two sprite in one game object (z position)

Can you help me with my bug?

I have two sprites in one game object. They have different z coord - 0 and 1. When game object spawns sprites have one z coord.
If I set z value in code both sprites get last value.

local ball_position = vmath.vector3(0, 0, 0)
go.set_position(ball_position, "#ball_sprite")
local icon_position = vmath.vector3(0, -30, 1)
go.set_position(icon_position, "#icon_sprite")

print(" ")
print('.icon_sprite (get_pos)', go.get_position('#icon_sprite'))
print('.ball_sprite (get_pos)', go.get_position('#ball_sprite'))
print(".")

Log:
DEBUG:SCRIPT:
DEBUG:SCRIPT: .icon_sprite (get_pos) vmath.vector3(0, -30, 1)
DEBUG:SCRIPT: .ball_sprite (get_pos) vmath.vector3(0, -30, 1)
DEBUG:SCRIPT: .

go.get_position() returns the position of the game object, not the sprite component. Similarly, go.set_position() sets the position of game objects, not components.

4 Likes

You can’t get or set sprite component positions at runtime. If you notice in the sprite API reference they have no position property. go.get_position() will get the position of the parent game object if you give it a sprite URL. If you want to move them around at runtime you need to put them on separate game objects.

[Edit] Oooh, I am minutes too late!

5 Likes