PDA

View Full Version : borders for a game


cuba
05-04-2002, 11:40 AM
hi everybody

i got a problem in a game. my movie has the following dimensions:
550x400 px. i got a flying object (ship) in the movie. it shouldn't be possible to fly out of the stage. i created 4 clips around the stage and attatched the following script: this is for the left border:
onClipEvent (enterFrame) {
if (this.hitTest(_root.ship)) {
_root.ship._x = _root.ship._x+12;
}
}
it works like this, but not propperly !!! the "ship" gets "nervous" and it's quite difficult to get it out of the "hitTest"

is there another way to stop my object on every side of my movie ???

i hope you'll understand what i mean...

thanks in advance for you help!!!:-)

Ricod
05-04-2002, 02:54 PM
U could include a piece of code stating that the _x of your ship may never be less than 0 + half the width of your ship (assuming that the registration point is in the center) and never more than 550 - half the width of your ship. The same for the _y, but with 400. Just include an if statement in your control code.

cuba
05-04-2002, 03:27 PM
thanks for your reply, could you post an example: do i have to attach the code to the ship ???

thanks a lot

cuba

Ricod
05-04-2002, 03:35 PM
exapmle :

on (keypress=<Right>){ //dunno the keypress thing at the moment, plz check
leftBorder = _root.myShip._width / 2;
rightBorder = 550 - leftMost;
if (_root.myShip._x >= leftMost && _root.myShip <= rightMost) {
// insert here the code that u use to move your ship right, depending on wether u want to take different things in account like speed, upgrades, gravity (?) etc.
}


do the same for left, and for up and down replace 550 with 400 and call the variables upperBorder and lowerBorder or sumthing.

cuba
05-04-2002, 04:59 PM
thanks, i'll try that...