Seems the only problems I have posted to this forum are contactListener-related. *sigh*
At least I have a working sample this time: http://www.andymoore.ca/chemistry/dev/10.swf (243Kb)
(excuse the mess, it's a work in progress - WASD to move)
Short story: contactListener.REMOVE is not being called all the time.
Long story:
The code allows the player to jump only if he is not touching 0 surfaces.
My custom contactListener class increments/decrements this accordingly:
This code works - if you load up the SWF and just hit "W", I've traced out the results:
Here's the strange bit. Go walk up to the left wall and jump while pressing against it (just hold down W and A). The player will start to "jitter" up the wall. After a second of this let go of the keys and you will settle back to the ground. The trace shows:
The groundCounter keeps incrementing every time the player "lands" on the ground surface, which shows ContactListener.ADD is performing properly. REMOVE also works fine as long as you aren't up against that wall. But when up against the wall - remove no longer works.
The above linked .SWF has debugDraw on - the player char is a circle, and you can see another smaller circle overlapping it to the bottom - this is the "GroundSensor". You can see the groundsensor is not colliding with the left wall.
The unfortunate - and game-killing side effect of this - is the GroundCount will now remain above 0 always and the player can "fly" by holding down the jump button. 🙁
Any clues as to what is causing this?
At least I have a working sample this time: http://www.andymoore.ca/chemistry/dev/10.swf (243Kb)
(excuse the mess, it's a work in progress - WASD to move)
Short story: contactListener.REMOVE is not being called all the time.
Long story:
The code allows the player to jump only if he is not touching 0 surfaces.
My custom contactListener class increments/decrements this accordingly:
Code:
public override function Add(point:b2ContactPoint) : void {
if (point.shape1.GetUserData() == "GroundSensor") {
point.shape1.GetBody().GetUserData().groundCount++;
}
if (point.shape2.GetUserData() == "GroundSensor") {
point.shape2.GetBody().GetUserData().groundCount++;
}
}
(remove class identical just -- instead of ++)
if (point.shape1.GetUserData() == "GroundSensor") {
point.shape1.GetBody().GetUserData().groundCount++;
}
if (point.shape2.GetUserData() == "GroundSensor") {
point.shape2.GetBody().GetUserData().groundCount++;
}
}
(remove class identical just -- instead of ++)
This code works - if you load up the SWF and just hit "W", I've traced out the results:
Code:
GroundCount: 0
GroundCount: 1 // player just settled upon execution
Player Jumped // registered "W" keypress
GroundCount: 0 // player is in the air
GroundCount: 1 // player landed again
GroundCount: 1 // player just settled upon execution
Player Jumped // registered "W" keypress
GroundCount: 0 // player is in the air
GroundCount: 1 // player landed again
Here's the strange bit. Go walk up to the left wall and jump while pressing against it (just hold down W and A). The player will start to "jitter" up the wall. After a second of this let go of the keys and you will settle back to the ground. The trace shows:
Code:
GroundCount: 1
Player Jumped
Jumped
Jumped
Jumped
Jumped
GroundCount: 2 // settled back to ground
Jumped
Jumped
Jumped
GroundCount: 3 // settled down again
Player Jumped
Jumped
Jumped
Jumped
Jumped
GroundCount: 2 // settled back to ground
Jumped
Jumped
Jumped
GroundCount: 3 // settled down again
The groundCounter keeps incrementing every time the player "lands" on the ground surface, which shows ContactListener.ADD is performing properly. REMOVE also works fine as long as you aren't up against that wall. But when up against the wall - remove no longer works.
The above linked .SWF has debugDraw on - the player char is a circle, and you can see another smaller circle overlapping it to the bottom - this is the "GroundSensor". You can see the groundsensor is not colliding with the left wall.
The unfortunate - and game-killing side effect of this - is the GroundCount will now remain above 0 always and the player can "fly" by holding down the jump button. 🙁
Any clues as to what is causing this?