[FMX] Complex SwapDepth

I’m not too good in explaining things extensively, so please pay attention to every word I say.
OK here’s the deal:

I’m making a shootout game. In the game there’re many monsters that respawn upon dying. There’s also the gun which follows the mouse’s x value, and a wall which is animated when the player “hides”. The problem is to integrate all those 3 components together:
When I duplicate the monsters, their depth is getting bigger everytime, and therefore they appear as if on top of the gun and the wall, but that’s not what I want. I want the gun and wall always be “the closest” to the player, so they will be above the monsters. I tried using SwapDepth to change the gun and wall depths to be 1 or 2 above the current monster depth every time, but for some reason Flash just DUPLICATES the gun and wall, and everything looks ****ed up.

Can anyone help me please? :q:

jsut change the depth of the gun and the wall the last monster’s depth+1

like if you duplicate a monster:
duplicateMovieClip(“monster”, “monster”+i, i);
then use this:
yourGun.swapDepths(i+1);

It’s as easy as that!

That’s exactly what I did! Please read what I wrote! It duplicates the gun and wall instead of just changing its depth!

This cannot be!:x:
This is inhuman… inflash!
Try making different variables for each action! (e.g. d for duplication and e for depth)

Well it happens, and the seperate variables don’t help! ;(

Put the gun at the depth of 1000001 and the wall at the depth of 1000000 and you should be OK.

this is strange… it suplicates it!!!
OMG! wtf! Must be glitch me thinks :-
i have no idea why it dupicates it!

But Pom, how can I set their depths if it will duplicate them? Because that’s what it does!!

It won’t :slight_smile:
In the first frame of your movie, you should have something like this:

gun.swapDepths(1000001);
wall.swapDepths(1000000);

Nope, it doesn’t help. I still see double guns and walls.
Maybe it’s some kind of bug I dunno.

Can you post a fla? :cyclops:

Yeah I guess I could… Just to note that I’m not the one who did the art.

[edit]Not Available Anymore[/edit]

well it looked fine to me… but in cases like that where you want to make sure that certain things are always below other things, then what you need (or rather could) do is to attach the objects which are supposed to be lower, within a single movieclip and have that movieclip below everything they need to be below. You can just make it an empty movieclip and put it (or create it) at point 0,0 so cooridinates within match the main movie.

[layer 1] gun
[layer 2] wall
[layer 3] wicked outside world

wicked_outside_world.attachMovie(“bug”, “bug” + i, i++);
…etc.

and the bugs will always be below the wall and gun no matter how many are attached and no matter what depth because they are all kept within the wicked_outside_world clip

At last!!! :geek:
Thank you senocular!!! It works! :beam:

But now I still have another problem:

How can I make rapid fire?