PDA

View Full Version : going out of bounds - scrolling off screen


angelas
07-23-2001, 07:00 PM
I have a map that is controlled by four directional buttons that can move around in a specified viewing area. My problem is that it scrolls right off the screen if you let it. I used if statements to try to set the bounds, but I think I did something wrong because they aren't stopping the map from going off the screen.

How can I affectively set bounds so my map stays in my viewing area?

For some reason it completely ignores my if statements and continues to scroll off the screen. That is why I'm confused.

Maybe I'm going about it all wrong.

if (_level0.map._y >= -567){
_level0.map._y = _level0.map._y+(_level0:direction*5);
}

Is there another way to do it?
------------------------------------------------------------
Am I putting the code in the wrong places??

My frames contain:

frame 1:
stop();

frame 2:
if (_level0.map._y >= -567){
_level0.map._y = _level0.map._y+(_level0:direction*5);
}

frame 3:
if (_level0.map._y >= 0){
_level0.map._y = _level0.map._y+(_level0:direction*5);
gotoAndPlay(2);
}

frame 4:
if (_level0.map._x >= -605){
_level0.map._x = _level0.map._x+(_level0:direction*5);
}

frame 5:
if (_level0.map._x >= 0){
_level0.map._x = _level0.map._x+(_level0:direction*5);
gotoAndPlay(4);
}

Did I maybe put my conditions in the wrong places? Should they be on the buttons? It just seemed to make sense to put them on the frames where I have them.

Any advice would be greatly appreciated.

ARA Kenny
07-23-2001, 08:50 PM
Sometimes it is the simple things that mess us up. Instead of referring to the level of the movie clip, try just _root.movieClip (if it is located in the _root timeline) if not, do _root.movieClip1.movieClip2. The reason I say this is because often when I am writing a complicated script, and I have a problem, I am just not referencing the movie clip correctly. Your code seems sound, you just have to make sure you are referencing your movie clip correctly. The _level works, unless it's on a different level than you are currently trying to target... try using the direct approach this time>>>>> _root.movieClip.movieClip2

Okay, I just reread your post, and I believe your conditions and actions after the conditions are incorrect look.....

if (_level0.map._y >= -567){
_level0.map._y = _level0.map._y+(_level0:direction*5);
}
should be.....

if (_level0.map._y <= -567){
_level0.map._y = _level0.map._y+(_level0:direction*5);
}

your ">" should be "<"...... if this is not corrected, it will make it scroll off the screen, just like it is doing.
Check to see if you made the same mistake with the _x coordinates also (from what I saw in your post, it looks like it).




Kenny

angelas
07-23-2001, 10:02 PM
Thank you Kenny. :) Changing _level0 to _root did the trick for moving right and down. However, making the change for left and up didn't work. This puzzles me.

Also, changing the ">" to "<" doesn't work because
-700 < -600 and I want to make sure that the map doesn't move farther than -605 in the negative direction.
So if the X and Y coordinates are greater than 0 and
-605/-567 we're going the right direction. I tested your theory anyway just to be sure I wasn't wrong. If I write:
if (_root.map._x <=0 ){
//move the map
}
then the map won't move at all in that direction, it's already at the boundary.
__________________________________________________ __________
Here is my code as it is now:
(NOTE: direction is a variable that is set to either 1 or
-1 in the buttons, depending on which direction you wish to move)

****Frames****
frame 1:
stop();

frame 2:
if (_root.map._y >= -567){
_level0.map._y = _level0.map._y+(_level0:direction*5);
}

frame 3:
if (_root.map._y >= 0){
_level0.map._y = _level0.map._y+(_level0:direction*5);
gotoAndPlay(2);
}

frame 4:
if (_root.map._x >= -605){
_level0.map._x = _level0.map._x+(_level0:direction*5);
}

frame 5:
if (_root.map._x >= 0){
_level0.map._x = _level0.map._x+(_level0:direction*5);
gotoAndPlay(4);
}

****Buttons****
button (up):
on(rollOver){
direction = 1;
_level0.map.gotoAndPlay(2);
}

on(press,release, releaseOutside, rollOut, dragOut){
_level0.map.gotoAndStop(1);
}

button (down):
on(rollOver){
direction = -1;
_level0.map.gotoAndPlay(2);
}

on(press, release, releaseOutside, rollOut, dragOut){
_level0.map.gotoAndStop(1);
}

button(right):
on(rollOver){
direction = 1;
_level.map.gotoAndPlay(4);
}

on(press, release, releaseOutside, rollOut, dragOut){
_level0.map.gotoAndStop(1);
}

button (left):
on(rollOver){
direction = -1;
_level0.map.gotoAndPlay(4);
}

on(press, release, releaseOutside, rollOut, dragOut){
_level0.map.gotoAndStop(1);
}

__________________________________________________ ______
If anyone knows what might be going on with the up and right directions, please point me in the right direction.
All suggestions are greatly appreciated. :)

ARA Kenny
07-23-2001, 10:37 PM
Well, we got that figured out... and for the other two boundaries, look at your code.... it never gets past frame 2 because of your gotoAndPlay(2) action, it just repeats 2-3-2-3-2.... and so on... Also it seems strange that you would separate all your IF statements... try this... put all your if statements in frame 2 and make frame 3 nothing but gotoandplay(2). And if it gets past frame 3, it just loops between frames 4 and 5... we need to rearrange the code just a little bit...

like this:

Frame 1:
stop();


frame 2:
if (_root.map._y >= -567){
_level0.map._y = _level0.map._y+(_level0:direction*5);}

if (_root.map._y >= 0){
_level0.map._y = _level0.map._y+(_level0:direction*5);}

if (_root.map._x >= -605){
_level0.map._x = _level0.map._x+(_level0:direction*5);}

if (_root.map._x >= 0){
_level0.map._x = _level0.map._x+(_level0:direction*5);}

frame 3:
gotoAndPlay(2);


Splitting up all your IF statements can make it more confusing and alot harder to work with. Also when they are all in the same frame, it repositions faster and there is no confusion on the gotoandplay action because you only have to deal with one...

Kenny...


P.S. email me the .FLA so i can see what you are working on, if you would like to...