Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411582 Posts in 69386 Topics- by 58445 Members - Latest Member: Mansreign

May 06, 2024, 02:33:59 AM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)AS2 swapDepths question
Pages: [1]
Print
Author Topic: AS2 swapDepths question  (Read 2588 times)
Snow
Guest
« on: July 02, 2010, 05:45:47 PM »

I entered the "A Game By It's Cover" compo. I'm doing Spy vs. Sniper: http://forums.tigsource.com/index.php?topic=13512.0

In the game, in the final level, I may have up to 100 "people" objects scrolling in 4 directions, with about 20 to 30 "prop" objects (trees, bushes, etc) on screen. As you can see the game is pretty much isometric. I need to make sure that objects are at a specific depth per _y coordinate. So if the y coordinate of a people object is 1 less than the y coordinate of a prop or other people object, it will properly show up behind. I was thinking of assigning depths as follows for moving objects:

this.swapDepths(_y);

As the y coordinate increases, so does the depth... er well the depth decreases.. you know what I mean.

Is it safe to do that? There is a possibility that multiple objects could share the same depth at any given time. Save for one dynamic object that gets attached to "people" objects (the briefcase... if you read through the game description and posts), no moving object ever gets removed - they continually stay in play.

I'm still very much a beginner at actionscript, so please don't bite off my head if this is a stupid depth cheat that won't work. Smiley Thank you for your time.
« Last Edit: July 02, 2010, 11:27:29 PM by Snow » Logged
Snow
Guest
« Reply #1 on: July 02, 2010, 11:40:26 PM »

I found the best possible solution: this.swapDepths(this._x + this._y*world_width);

Now I just have to make sure I can keep map objects at appropriate levels.
Logged
agj
Level 10
*****



View Profile WWW
« Reply #2 on: July 04, 2010, 08:51:30 PM »

I hate swapDepths (not much of a fan of AS2 in general, but have to use it for work...). What you say should work as long as the world's dimensions aren't too large; there's actually some limits to the depth values. Let me see if I can find an article on that...

Okay, here we go.

An alternative would be to just use the _y value for the depth, multiplied by some constant, but first check if there's something at that precise depth, and if there is, try the next depth, and so on. If you use a constant of 5, you'll get to place 5 objects at the 'same' depth.
Logged

Snow
Guest
« Reply #3 on: July 05, 2010, 07:22:36 PM »

Hey thanks agj. My world won't be that large and I ran a few tests already. I also ran a test with having 2 objects at exactly the same depth.. there was no problem.. both stayed on stage and continued moving as they were supposed to and at proper depths. I also traced 2 objects given identical initial depths and yet both numbers were different, one was higher than the other, making me think that there is some automatic ordering going on (of course I could be wrong, I haven't completely read through the kirupa articles yet). I'll keep your suggestion in mind. Better to be safe than have a headache. Thanks for your response. Smiley
Logged
agj
Level 10
*****



View Profile WWW
« Reply #4 on: July 05, 2010, 09:33:13 PM »

FYI, the swapDepths() method actually swaps the depths of the two conflicting objects.
Logged

Snow
Guest
« Reply #5 on: July 06, 2010, 09:18:31 AM »

FYI, the swapDepths() method actually swaps the depths of the two conflicting objects.

I know, but it works for what I need. Plus, all of the samples of code I've seen so far for assigning depth to several movieclips use swapDepth().
Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic