jiggibidy -> RE: Flash Q&A Thread 5 - Flash Has Shares In Your Soul (7/23/2009 18:41:58)
|
Well, I'm just mucking around with a few ideas for some code, and I thought I'd try a simple walking engine, using the up, down, left and right keys. I have a mC, 'Block' with an instance name 'block' and a mC, 'Player' with an instance name, 'player' The problem I have encountered is that when 'player' collides with 'block', 'player' always seem to go left, no matter what direction it collides with 'block' from. I used the trace command to see what variables show up, as the variable 'facing' changes to the name of what key was pressed last, and when 'player' is colliding with 'block' the 'facing' variable seems to change to 'left' for some reason. I've checked my code and there's nothing that states that 'facing' should be changed to 'left' in any of the code. All of the code is in the 'player' mC: onClipEvent (load) {
this.speed = 5;
this.facing = 0
}
on (keyPress "<Left>") {
this._x -= this.speed;
this.facing = "left"
}
on (keyPress "<Right>") {
this._x += this.speed;
this.facing = "right"
}
on (keyPress "<Up>") {
this._y -= this.speed;
this.facing = "up"
}
on (keyPress "<Down>") {
this._y += this.speed;
this.facing = "down"
}
onClipEvent (enterFrame) {
trace (this.facing)
if (hitTest(_root.block)) {
if (this.facing = "left") {
this._x += 5;
}else if (this.facing = "right") {
this._x -= 5;
}else if (this.facing = "up") {
this._y += 5;
}else if (this.facing ="down") {
this._y -= 5;
}
}
} I hope you can help me with this.
|
|
|
|