Recycle when Off Screen Problem

captaincomic

  • *
  • Posts: 6108
Hi!

I have noticed something strange.
I have a beahvior to recycle bullets when they go off screen. When a bullet leaves the screen over the top edge or the left edge it gets recycled correctly, but when it leaves the screen over the bottom edge or the right edge it doesn't get recycled. It just disappears with and no code under
Code: [Select]
if (!(actor.isOnScreen())) gets executed.
I set the offscreen bounds to negative values to see whats happening and I print messages in the "Die When Off Screen"-behavior.
The bullets disappear on each side, but the messages only get printed if it leaves top or left.

If I use "always simulate" for the bullet, everything works as expected, the messages get printed
whenever the bullet leaves the offscreen bounds (no matter which direction).

So using "always simulate" is a workaround, but this behavior is still strange, isn't it?

Joe

  • *
  • Posts: 2478
Actually, that's the intended behavior. In order to optimize performance, Actors stop "simulating" by default when they leave the screen, so their Behaviors -- including your on-screen check -- won't execute. The solution is exactly as you describe. We're looking to make this a setting in the future, with the default being that "always simulate" is true.

captaincomic

  • *
  • Posts: 6108
Ok. Making "always simulate" default sounds good, I'd say for beginners its better to have bad performance than to have an unexpected behavior.
Still I'm surprised that the "when off screen"-behavior executes when the bullet leaves to the top or to the left even without "always simulate". Any idea why that happens?

rob1221

  • *
  • Posts: 9472
Does the off screen block check only the top left pixel?

coleislazy

  • *
  • Posts: 2607
Does the off screen block check only the top left pixel?

I think this is the key. If more than half of an object is off-screen, it will stop simulating. The check is from the top left corner, however.

captaincomic

  • *
  • Posts: 6108
Ok, thank you, I start to understand whats happening.

So when exactly does actor.isOnScreen() evaluate to true/false?
I would make sense if an "simulating" and actor.isOnScreen() would be consistent, i.e. an actor stops simulating if and only if actor.isOnScreen() is false. But it seems that's not the case(?)

captaincomic

  • *
  • Posts: 6108
Ok, I played around with offscreen bounds and debug drawing: actor.isOnScreen() is true as long as the top left pixel is on screen. An actor stops simulating when more than the half is off screen.

Well, I just have to remember to use "always simulate" whenever I check actor.isOnScreen.

captaincomic

  • *
  • Posts: 6108
I have to reply once more to myself :)

Thinking about it once more, actor.isOnScreen() seems pretty unusable for me now.
When you do the following
Code: [Select]
if (!actor.isOnScreen())
{
    recycleActor(actor);
}
it will actually mean that the actor would be recycled while still visible (if leaving to the top or left). I never noticed as my bullets move too fast, but if you use this for something big or slow it will just disappear immediately when it touches the screen edge.
Why doesn't actor.isOnScreen() check if the actor is completly off screen? Is this (really) a performance issue?
I can do the check manually, I'm just wondering ;)

Hectate

  • *
  • Posts: 4643
Are you saying that setting the offscreen bounds has no effect on this? That's the whole point of the offscreen bounds being able to be set - to keep things from registering offscreen before they actually are. It's particularly noticeable with very large actors (since much of them would still be onscreen when "passing" the edge).
:
:
Patience is a Virtue,
But Haste is my Life.
Proud member of the League of Idiotic Stencylers; doing things in Stencyl that probably shouldn't be done.

captaincomic

  • *
  • Posts: 6108
No, the offscreen bounds work fine. It's true, setting the offscreen bounds to something bigger than your biggest actor would help. I didn't think about that. I just thought checking if the actor is completly offscreen would be more straightforward.