• AttachMovie Depth making me rage (AS2)
    1 replies, posted
[code]d = 25; a = 0; var timer:Number = setInterval(Poop, a); var cap:Number = d; var numberOfMovieclips:Number = 0; function Poop():Void { bubble = _root.attachMovie("mushroom_1", "mushroom_1"+numberOfMovieclips++, getNextHighestDepth(a)); if (numberOfMovieclips>cap) { bubble._y = Math.random()*500+0; bubble._x = Math.random()*500+0; bubble.dead = false; bubble.onEnterFrame = goLeft; numberOfMovieclips = 0; } } function goLeft():Void { this.swapDepths(_root.player); }[/code] Posted this on newgrounds forums but help there is rare due to a low member count and an even lower count of people who know what they're doing. Anyways, as of now all this code does is spawn the mushrooms randomly, which is exactly what I want, the only problem is I can't for the life of me figure out how to get the depth (what layer the mushroom is on) to go below everything, it just starts on top, like one will spawn on a tree or when the player walks over it, it'll overlap. It should be the simplest thing to do in the whole code but without it it's god damn game breaking, I probably don't even need to change much.
You could simply swap the mushrooms to that certain number + 500, then you have 500 positions to swap other elements to beneath the mushrooms. [code] d = 25; a = 0; var timer:Number = setInterval(Poop, a); var cap:Number = d; var numberOfMovieclips:Number = 0; function Poop():Void { bubble = _root.attachMovie("mushroom_1", "mushroom_1"+numberOfMovieclips++, getNextHighestDepth(a) + 500); if (numberOfMovieclips>cap) { bubble._y = Math.random()*500+0; bubble._x = Math.random()*500+0; bubble.dead = false; bubble.onEnterFrame = goLeft; numberOfMovieclips = 0; } } function goLeft():Void { this.swapDepths(_root.player); } [/code] OR you could have two containers, one for mushrooms and one for background objects. As far as I remember (haven't coded AS2 for a long time, moved over to AS3) and then add all the objects to those containers, instead of adding them to _root.
Sorry, you need to Log In to post a reply to this thread.