PDA

View Full Version : swapDepths issues


Malignus
03-10-2008, 09:40 AM
So, I've been having some problems with swapdepths in the TRPG3 alpha. For some odd reason, the same basic code that worked perfectly in TRPG2 hasn't been working quite right in TRPG3. Every turn, I set turnCounter++, then run the following function to make sure the character whose turn it is ends up on top:

function makeCharHighestDepth () {
if (moveTurn==1) {
char1.swapDepths(40+turnCounter);
}
else if (moveTurn==2) {
char2.swapDepths(40+turnCounter);
}
else if (moveTurn==3) {
char3.swapDepths(40+turnCounter);
}
...
else if (moveTurn==24) {
char24.swapDepths(40+turnCounter);
}
else if (moveTurn==25) {
char25.swapDepths(40+turnCounter);
}
}

For some reason, this has been producing inconsistent results, with the enemies (char16-char25) often ending up on top before their turn has been reached, and player attacks therefore oftentimes showing up underneath them. Any ideas as to what might be wrong?

magcius
03-10-2008, 10:52 AM
Where is moveTurn calculated?

And also, why are you doing that if you could possibly do this for the entire function?


function makeCharHighestDepth () {
this['char'+moveTurn].swapDepths(40+turnCounter);
}

Malignus
03-10-2008, 09:26 PM
Not to worry--I'll rewrite it once I've gotten it working. I appreciate the concern, though. ;)

Anyway, moveTurn is calculated in the changeTurns() function, which (as you might imagine) gets called at the end of every turn. Every time it's called moveTurn++ occurs. Once moveTurn hits 26, it returns to 1.

magcius
03-11-2008, 07:03 AM
I would trace both moveTurn and turnCounter to get a general idea of where the problem might be.

Malignus
03-12-2008, 02:14 AM
I did that--both work perfectly. From what I can tell, it seems to be the swapDepths thing itself that isn't working.

magcius
03-12-2008, 03:15 AM
Make sure the chars are labeled what they are supposed to be labeled.

Also, try tracing charxx.getDepth in the same method to make sure it is working properly.

Malignus
03-12-2008, 10:59 AM
Aha! Thanks, I didn't know there was a getDepth command (I figured there had to be something like it, but I didn't know that actual command).

Well, I'm stumped. The traces return exactly the right results, and yet after the first set of turns, the character whose turn it is shows up beneath enemies with lower depths than it anyway. What could possibly cause that?

magcius
03-12-2008, 11:22 AM
Layers? Layers are on a higher priority than ActionScript depth management(?), however that may be false.

At the start of each turn, try tracing both players' depths and see if they match. It may be that somehow the other player is getting its depth set too.

LizardRob
03-12-2008, 01:55 PM
Are you setting the depth of elements in the animations of the characters?

Malignus
03-12-2008, 04:07 PM
At the start of each turn, try tracing both players' depths and see if they match. It may be that somehow the other player is getting its depth set too.

I did that also, actually--the other characters are maintaining the same, lower depths until their turns are reached. Here is a sample from the output of one battle. Bold text indicates that it is that character's turn:

char5 depth = 45
char16 depth = 1
char17 depth = 2
char18 depth = 3
char19 depth = 4
char20 depth = 5
char21 depth = 6
char22 depth = 7
char6 depth = 46
char16 depth = 1
char17 depth = 2
char18 depth = 3
char19 depth = 4
char20 depth = 5
char21 depth = 6
char22 depth = 7
char16 depth = 56
char17 depth = 57
char18 depth = 58
char19 depth = 59
char20 depth = 60
char21 depth = 61
char22 depth = 62
char1 depth = 66
char16 depth = 56
char17 depth = 57
char18 depth = 58
char19 depth = 59
char20 depth = 60
char21 depth = 61
char22 depth = 62
char2 depth = 67
char16 depth = 56
char17 depth = 57
char18 depth = 58
char19 depth = 59
char20 depth = 60
char21 depth = 61
char22 depth = 62Everything seems to work great on the first turn, when the good characters are still way deeper than the enemies. Once the enemies have all gone, though, the game starts putting them consistently on top, even though they have a lower depth.

Since characters are all attached via actionscript, layers shouldn't be able to play a role here. I also made sure that no two characters share the same depth at any given time, which I know could cause problems, and I definitely don;t set depths in any of the animations. Is there something about Flash's handling of depths I just don't know that could be causing problems here?

magcius
03-12-2008, 04:10 PM
PM the FLA to me. I'll take a look at it and debug it.

arkhan
03-14-2008, 08:51 AM
why do you need to get higher and higher depths? just get a range and swap to top the current character.
even if you fix this..its very likelly it will get buggy once you reach depth 65535..(think of one looong match..)

function makeCharHighestDepth () {//depths 40 to 66..assuming they are already in those positions.
this['char'+moveTurn].swapDepths(66);
}

Malignus
03-17-2008, 01:11 PM
Thanks Arkhan--for some reason, this fixed the bug!

arkhan
03-19-2008, 09:04 AM
and this also adds that you can actually put stuff above the characters..as anything with depth over 66 will STAY on top of the characters..as oposed to bein overlaped as the characters depth goes up.