Hi,
I have a game which randomly generates some items and I'm working on trying to make sure the items don't ever overlap each other. Do do that I was calling some functions to do rectangle intersection testing (using BBoxLeft,BBoxRight, etc, in expressions)
The bound box code seems to work, but sometimes the objects don't move like I would expect, I think its because they have "just been created", and I'm encountering the infamous "can't pick properly after creation" issue or something.
(references:
and
)
One thing I don't understand 100% is the "Wait 0 seconds"...."trick".
I put together a small test capx essentially that creates a red sprite randomly anywhere on the screen, and keeps doing so. But after it creates it, it calls a function to take all the rest of the red sprites that already exist, which belong in a family, and tells them all to turn "black" essentially, *IF* their "ID" property does not equal the newly created red sprite's UID.
The weird thing is, this works if you put the code in entirely straight as all sub events.
And it also appears to work even if I call a function to do the for each, the new red box stays red, while all previous ones turn black.
However, if you insert one single "wait 0" in the beginning of the function, now even the newly created red box turns black too! Which to me doesn't make sense..the "ID" property of the red box is set ..
You know what..maybe it's because the function loses its parameters because a "wait 0" goes around for another tick? Maybe the parameter ends up being "empty" or zero? Thus making the condition true for ALL red boxes now?
Screenshot below, of the setup, and the "Wait 0 " in place. If you take out the Wait 0 it works correctly.
http://imgur.com/unYwp4H