FlixelCommunity / flixel

Community fork of Adam “Atomic” Saltsman's popular game engine Flixel. Distilled from a variety of Flash games he worked on over the last couple years, including Gravity Hook, Fathom and Canabalt, its primary function is to provide some useful base classes that you can extend to make your own game objects.
http://flixelcommunity.org/
Other
84 stars 17 forks source link

FlxSprite.onScreen() locks the game up if returns false. #147

Closed FlixelCommunityBot closed 11 years ago

FlixelCommunityBot commented 11 years ago

Issue by JonLim from 2012-11-09T19:42:21Z Originally opened as https://github.com/AdamAtomic/flixel/issues/235


Hi!

I'm currently working on a match-3 style puzzle game, coming up with a better algorithm to check all of the spots on the board for matches. I've been pulling my hair out with certain aspects of Actionscript (and also Flixel) but I think I found an easy way to check which squares on my board are currently empty (and should begin the process of queuing up pieces to be generated, and moving the rest of the pieces.)

That said, here's my current process for this:

Very vague, I understand, but the fact is, when I use onScreen() on a sprite that I have just used destroy() on, the entire game just stops. To test it, I tried onScreen() on a sprite that was clearly present and it would spit back "true" in the logs.

Would love an idea of what is going on here. Thanks!

Dovyski commented 11 years ago

It seems you are calling kill() instead of destroy(). If that is the case, the sprite will be marked as non-existent and dead (exists = false and alive = false), however its position won't change, that's why onScreen() continues to return true.

If you are calling destroy(), then you should see an exception.

IQAndreas commented 11 years ago

Is this issue definitely due to user error, or is there anything we can do about it? Shall I close it or leave it open?

moly commented 11 years ago

It's user error. He's trying to use a sprite after it's been destroyed, which is causing a null reference exception. The only thing we could do is to add a check that a FlxObject exists to every one of its public methods.

Dovyski commented 11 years ago

That's certainly user error. About your suggestion, @moly ,I think it is a great addition. We could check for null properties within destroy() (which prevents crash when an object is destroyed twice).

For me this issue can be closed.

IQAndreas commented 11 years ago

We could check for null properties within destroy() (which prevents crash when an object is destroyed twice).

I implemented your idea into a pull request: https://github.com/FlixelCommunity/flixel/pull/153

As this issue is invalid, I'm closing it as such.