Sprite setPosition problem
clovis2

Hello!

 

To be able to put all my sprites in the same sceneObject, I try to set a sprite position using sprite.setPosition method. Doing so doesn't seem to affect sprite position. However, putting setPosition call inside a onMouseMove method, the sprite effectively move but soon comes back to its original position. That lead to an unexpected alternative movement. Is it possible to use sprite.setPosition method or is it needed to use sceneObject.setPosition? What is the normal use of sprite.setPosition method?

 

Thanks for answer

 

Clovis2

All 2 Comments
Gio

Hi

 

To move an object, the recommended method is SceneObject.setPosition(). You can have multiple sprites in the same SceneObject, and the best way to set each sprite's position (relative to the parent SceneObject), is via SceneObject.setSpriteOffset(spriteIndex, offset). If you do it this way, when the SceneObject moves, all the Sprites that are part of that SceneObject move accordingly.

 

By the way, you can also have a rotation offset if you like.

 

Sprite.setPosition() sets the position of the Sprite directly, but every time you move the parent SceneObject, the position of the Sprite is set again to match its offset relative to the parent. So in most cases, using Sprite.setPosition() directly is not very useful. There are exceptions (e.g. sometimes you need to have sprites that have no parent scene objects), but these cases are fairly rare in my experience.

clovis2

Hi,

 

Thanks a lot for your answer!

 

Clovis2

Post a reply
Add Attachment
Submit Reply
Login to Reply