PDA

View Full Version : Disallowing flash object to move out of an area



DarkBlood
July 4th, 2008, 14:22
Since I tried three or more different combinations of searching via google including this topic's title: Disallowing a flash object to move out of an area, I've posted this on ActionScript.org (http://www.actionscript.org/forums/showthread.php3?t=175739), but they have yet to reply, at all; so now I'm here as well.

If I have a movement dealie like this tutorial shows (http://www.flash-game-design.com/flash-tutorials/movOb-flash-tutorial.html) how would I stop the movement of the object when it reaches a certain point? Specifically: How do I make it so that the edge of the object being moved doesn't move out of a specified area?

Obviously, I'll be wanting it in ActionScript 2.0 form.

themoose
July 4th, 2008, 15:32
I'm very new to actionscript but I think it's something like this... basic principle:

if(this._x > (predetermined x point1 - numerical)) {
this._x = (pretermined x point1 - numerical);
}
if(this._x < (predetermined x point2 - numerical)) {
this._x = (pretermined x point2 - numerical);
}
if(this._y > (predetermined y point1 - numerical)) {
this._y = (pretermined y point 1- numerical);
}
if(this._y < (predetermined y point2 - numerical)) {
this._y = (pretermined y point2 - numerical);
}

You'll have to figure out where the x and y point parimiters can be.

You can also make an object, give it a label and make it alpha 0&#37; (so it's invisible). then you can use the predetermined points as the object's _x and _y co-ordinates.

DarkBlood
July 4th, 2008, 16:28
I don't think that'll work with multi-sided (more than four)... hrm... I'll go try it out. Right now I was just wondering, I have 512 MB of RAM, and don't have the money to upgrade with even a measely gig (It's SDRAM too) so I'll wait on this cause Windows is eating up a mess of RAM (I had to allocate 10 GB of virtual memory by hand to stop it complaining for now.)

DarkBlood
July 6th, 2008, 11:34
I have this code,


if(square._x > (ExprArea._x - square._x)) {
square._x = (ExprArea._x - square._x);
}
if(square._x < (ExprArea._x - square._x)) {
square._x = (ExprArea._x - square._x);
}
if(square._y > (ExprArea._y - square._y)) {
square._y = (ExprArea._y - square._y);
}
if(square._y < (ExprArea._y - square._y)) {
square._y = (ExprArea._y - square._y);
}

But the square still moves beyond the south and east sides of ExprArea. I found out the following parts don't do anything,


if(square._x > (ExprArea._x - square._x)) {
square._x = (ExprArea._x - square._x);
}
if(square._y > (ExprArea._y - square._y)) {
square._y = (ExprArea._y - square._y);
}

changing the - to + for these two don't do anything.

themoose
July 6th, 2008, 13:24
Make another area (or two) where it can't go, but this time put it on the south and east sides.