-
Problem with boundaries
I've been struggling with making boundaries with my game. I've managed to make boundaries, but in stead of my game character not moving across that border it just bounces back. Which is not the effect I want.
Here's my code
onClipEvent (enterFrame) {
if (Key.isDown(Key.LEFT)) {
xspeed -= power;
}
if (Key.isDown(Key.RIGHT)) {
xspeed += power;
}
if (Key.isDown(Key.UP)) {
yspeed -= power;
}
if (Key.isDown(Key.DOWN)) {
yspeed += power;
}
xspeed *= friction;
yspeed *= friction;
_y += yspeed;
_x += xspeed;
//BOUNDARIES
if(this._x <0){
this._x += 10;
}
if(this._x> 720){
this._x -= 10;
}
if(this._y <50){
this._y += 10;
}
if(this._y> 500){
this._y -= 10;
}
}
Thanks a lot
-
var x:Number = 1; x /= 0;
What kind of boundaries are you looking to have?
-
I'm sorry.
It's boundaries so that the player wont be able to go outside the stage (what you can "see").
And right now with that code, it doesn't really work. It can easily go outside the bounds (but there is some boundry, but the caracter just seem to bounce into the wall. It doesn't look great. I just want it to not be able to go outside the stage so that it stops there instead of bouncing back and forth)
-
var x:Number = 1; x /= 0;
if(this._x <0){
this._x=0;
}
if(this._x> 720){
this._x =720;
}
if(this._y <50){
this._y = 50;
}
if(this._y> 500){
this._y = 500;
}
}
That's one approach. You may have to tweak some numbers, but that's the general concept.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|