Hello Guest

Author Topic: [Solved] Sprite not moving (position) in runtime, moves in editor just fine.  (Read 8294 times)

Moran

  • Newbie
  • *
  • Posts: 9
    • View Profile
EDIT: I'll save you the trouble of scrolling through this shameful mess: Check that your objects aren't "static"!

In my scene are two screens, one under the other.
In each screen, several sprites, including two background images sprites for each screen (each screen has 2 sprites as background).
Both screen gameobjects are under a container gameobject, since I want to simulate a scroll animation by moving that container up and down on the Y axis.
When I move the container in the editor, everything moves fine.

When I'm in Play mode, during run time, if I change the container's Y position, everything in the scene moves except the background sprites of BOTH screens. The top screen's background is not moving and the bottom one stays at the bottom. The anchor gizmo that shows where the object's anchor is, is actually moving, but the sprites are not moving with it.

Nowhere in the code am I addressing these particular sprite's positions.

WTF? Help!
« Last Edit: January 21, 2013, 04:16:03 pm by Moran »

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Sprite not moving (position) in runtime, moves in editor just fine.
« Reply #1 on: January 17, 2013, 04:26:56 pm »
Are you trying to move the anchor object? If so, you can't - the anchor repositions itself every frame while the game is running. You should add a child game object, link all your sprites to that, and move that game object instead.
« Last Edit: January 17, 2013, 04:31:25 pm by unikron »

Moran

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Sprite not moving (position) in runtime, moves in editor just fine.
« Reply #2 on: January 20, 2013, 09:11:22 am »
Thank you for your reply!

Are you trying to move the anchor object? If so, you can't - the anchor repositions itself every frame while the game is running. You should add a child game object, link all your sprites to that, and move that game object instead.

There is no anchor object, it is only a parent of the child objects by unity's transform, no anchor script or anything. BUT, the background images that arent moving are set to "anchor left" and "anchor right"... Maybe that's the reason.

How do I link sprites to gameobjects? Must the linked GO be a child GO? Can I link them to the parent container GO?


Thanks again!

EDIT: Just to be clear, let me specify what I'm trying to achieve:
Container object (no scripts)
- Screen Object (with my scripts)
-- Background object (no scripts)
--- Left (tk2d sprite, anchored mid-right)
--- Right (tk2d sprite, anchored mid-left)
-- Props objects (no scripts)
--- many objects, including sprites

- Another screen object with similar structure to previous)

I'm moving the container object at runtime, everything, including props sprites, move with it, EXCEPT the background sprites on both screens, which are not moving, but should.
« Last Edit: January 20, 2013, 09:35:48 am by Moran »

Moran

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Sprite not moving (position) in runtime, moves in editor just fine.
« Reply #3 on: January 21, 2013, 09:19:13 am »
Help?

chro

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Sprite not moving (position) in runtime, moves in editor just fine.
« Reply #4 on: January 21, 2013, 10:07:35 am »
could it be that your camera is a child of your background object ? and so that it moves too when you move your background ?
also, if your camera is orthographic, translation along the z axis will not always have visual effect. (although you state that it is on the y axis).

Moran

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Sprite not moving (position) in runtime, moves in editor just fine.
« Reply #5 on: January 21, 2013, 10:16:21 am »
could it be that your camera is a child of your background object ? and so that it moves too when you move your background ?
also, if your camera is orthographic, translation along the z axis will not always have visual effect. (although you state that it is on the y axis).

The camera in question, which is the main camera, is in the root. Movement is indeed on the Y axis (up/down in my orientation) - It works well in Edit mode, but in runtime all the sprites move except the background objects.

Thanks for your reply!

chro

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Sprite not moving (position) in runtime, moves in editor just fine.
« Reply #6 on: January 21, 2013, 12:53:28 pm »
when you mean edit mode, do you mean pressing play in the editor vs a real build ? if that's the case you should probably have a look at the logs of the game (somewhere inside the build directory, can't remember where exactly). you might have some error message there. also try with a debug build maybe. worst come to worst, you can try to recreate your background from scratch and see what happens.

Moran

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Sprite not moving (position) in runtime, moves in editor just fine.
« Reply #7 on: January 21, 2013, 01:00:18 pm »
when you mean edit mode, do you mean pressing play in the editor vs a real build ? if that's the case you should probably have a look at the logs of the game (somewhere inside the build directory, can't remember where exactly). you might have some error message there. also try with a debug build maybe. worst come to worst, you can try to recreate your background from scratch and see what happens.

I meant pressing play vs. manually dragging the object around when play is not pressed.

On runtime (play is pressed), the background objects are not moving with the rest of the sprites.

Moran

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Sprite not moving (position) in runtime, moves in editor just fine.
« Reply #8 on: January 21, 2013, 04:14:44 pm »
Stupid thing - The prefabs I used for the background sprites were set to be "static" which I missed initially... The shame: :-[

Thanks for all your help!

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Glad its sorted.