0

I have a slight problem where i might need some help/ideas. I know the generic check whereby i set the onUpdate to check if my sprite is out of the screen via

If Sprite.getX > camera width and remove it.

However, that will not work in my case.

My sprites are being generated via a time handler and then set to move from point A to point B (A being bottom of the screen to B being top of the screen). This is done so through a moveModifier.

Unfortunately in order to generate the idea of already have a constant motion, i spawn the sprites outside, so they appear to be zooming into the scene.

E.g. Game is in portrait mode, Camera width being 0 to 480 and height being 0 to 800.

The coordinates are spawned randomly at e.g. (33, 810)

In this case, the point A is slightly outside the bottom of the screen and point B would be (33, -20) point B would be slightly outside the top of the screen.

When moveModifier is activated it starts to move the sprite.

But by putting the out of the screen at the top of the onUpdate, it checks it every frame. Thus when the sprite is moving from pointA (33, 810) to become visible at (33, 800), the sprite itself is removed before being visible.

What i need to know if is there is anyway to prevent this removal BEFORE moveModifer is finished, OR to if there is another way to do it.

Thanks!

user2587774
  • 125
  • 9

1 Answers1

0

If the sprites aren't moving when they are not ready:

what If you are trying to add a status (maybe called "spawned"), which indicates if the sprites are ready to move (or to get removed) ?


Another way would be to assign these sprites another frame rectangle, which is the "bounding rectangle". (So you have one rectangle which is the current size of the frame and one which indicates if the Object is ready to get removed)

Mr Monday
  • 11
  • 2
  • Thanks for your fast response, I would prefer your first solution as I don't really understand your second one (if you could explain it more clearly i would appreciate it!), but this is slightly more complicated as it isn't just a single sprite, it's an arraylist. Is there anyway you'd know to be sure to tag it together? Because this can't be done in running order as the same arraylist undergoes collision detection and removal... – user2587774 May 04 '14 at 13:00
  • ok sorry, i will try to explain the second one more clearly: can't you include your ArrayList in an own class? Then you can add a member(the bounding rectangle i mentioned) which is smaller and has a constant size. Now you don't have to check the dimension of the sprites (which are changing their sizes) and you can check the recangle. – Mr Monday May 04 '14 at 13:03
  • Hi sorry I think you misunderstood me. The sprites are moving from the start but while it moves from a to b there's a slight period where it is out of the screen. And when this happens the current method that is removing all items when they are out of screen fails. Is there anyway to add a boolean to on finished move modifier and call it later? – user2587774 May 05 '14 at 08:01
  • isn't there super.onModifierFinished(pItem); ? I would add the boolean in the Sprite class and if your Move is finished, you set the bool to true. When you check if the sprite has to be removed, your are not only checking x > camera but also the bolean. – Mr Monday May 10 '14 at 15:21