Diddy - Leaving a Screen, Re-entering?

Monkey Forums/Monkey Programming/Diddy - Leaving a Screen, Re-entering?

Amon(Posted 2012) [#1]
Is there a part in diddy that handles the code I insert to deal with leaving a screen?

It would be handy because then I could do any resetting of lists/objects etc!

Apologies if there is something there and I'm just not looking properly!

[edit] I'm not using the current Monkey version released a few days ago, also using the current diddy compatible with the previous version of Monkey, Monkey 66

[edit] Ok! I figured I could use the start method of each screen for this. Basically check if things exist already when entering the screen and if so null them and reset any globals etc! Seems to work fine so far!


therevills(Posted 2012) [#2]
Yep, I normally reset stuff in the Start method or you could use the Kill() method. Kill() gets called once the current screen has finished fading.


Samah(Posted 2012) [#3]
I would just create a new Screen instance every time.


Amon(Posted 2012) [#4]
Hi! Good point but I may have things I want to keep active. If not then yes that seems a better way.

Unrelated to that; diddy's RectsOverlap does not take in to account midhandled images; or does it?

I'm just passing the x, y and width, height to rectsoverlap and the collision is way off!


therevills(Posted 2012) [#5]
diddy's RectsOverlap does not take in to account midhandled images; or does it?


If you are just using the function RectsOverlap(x, y, width, height) then no, as it doesn't know anything about the image you are applying it to.

You could do this:[monkeycode]
img = new GameImage("blah")
x = 100
y = 100
If RectsOverlap(x - img.image.HandleX(), y - img.image.HandleY(), img.w, img.h) Then Print "BOOM!"
[/monkeycode]

If you are using a sprite, it will automatically set up a hitbox for you using the image handles, then use the sprite.Collide(sprite) method.


Amon(Posted 2012) [#6]
That is deffo juicy! :) Thanks!

[edit] Just tried that and it produces the same result.I think I know what the problem is. If the image is say 100x50 but is a .png with alpha and the visible sprite is actually 80x30 then the methods used take in to account the whole image and not the image with alpha or the actual area covered by the image.

A little math and I have it fixed now.