Access to sprite position property

Right now I can only control the scale of a sprite. I want to set the position of a sprite, both directly and with animation.

Example:

go.animate("#sprite_pusher", "position.y", go.PLAYBACK_ONCE_PINGPONG, 20, go.EASING_INQUAD, 1)
2 Likes

The way to currently go is to put the sprite component in a game object. That gives you the full range of runtime movement, rotation and scale possibilities.

1 Like

Hello @sicher

I don’t know how engine works internally , so i don’t know why scale property is accessible and in the other hand position is not. Also there is a position property for sprites on editor’s property panel, i can set manually sprite position within gameObject’s space.

But good thing is; it works how you offer to handle this situation.


*Pros : Dont know yet. Maybe learn benefits in future.

  • Cons : You have lots of gameObject around.

Best Regards,

As long as the game objects don’t have scripts associated with them, the extra runtime cost is not high.

What if I have several sprites, do I need a game object for each sprite? I want to animate each sprite separately.

Yes, that would require one game object per sprite then. This is perfectly fine and how the engine is designed and supposed to work.

3 Likes

Yup, I’m doing that, is there a way to group game objects?

Yes, you can child a game object to a parent game object. You can do it in the editor while in a collection by drag and dropping a game object on another in the Outline. At runtime you do it via the set_parent message

3 Likes

Why is it not possible to allow setting position of a component with go.set_position()? It’s individual position can be set in the editor, but not in the code, why?

5 Likes

I’ll let @Johan_Beck-Noren or @sven answer this one.

2 Likes

Looking forward to seeing their reply.

3 Likes

So, I can change “scale” of the #sprite component from code by go.set("#sprite", "scale", scale) but can’t change scale in Editor.

But I can change #sprite position in editor, but there is no way to change position from code?

That looks weird. I want to change my sprite’s position from code (and scale in Editor will be also nice)

3 Likes

We will look into exposing the sprite scale from within the editor.

You are not able to change the position of any component at runtime. This is likely not going to change anytime soon.

Change the position of the game object. Or put the sprite in a child game object and move that object instead.

3 Likes