View Full Version : Buttons that continue...
Vegas0
05-13-2010, 05:37 PM
Hi, wondering if anyone can help,
I currently have a map image in flash (3000x3000px) it fills the screen and is controlled by buttons, up down, left and right. Quite simply, when a button is pressed the screen reveals more of the map depending on which way you go, this part is fine,
The problem is when the image comes to an end (in any direction) you are able to keep moving using the buttons into a endless display of white,
Is there any way I can make it so you cannot go any further than the image?
Thanks
Michael8818
05-14-2010, 03:59 PM
I'm assuming you have it moving the pictures X and Y axis with the keys....as well as teh actual stage is smaller than the picture....but here is an example
you have the stage set at 800 x 800 and an image is 2000 x 2000.
on the key press you have something like this.....
var leftKeyDown:Boolean=false;
var upKeyDown:Boolean=false;
var rightKeyDown:Boolean=false;
var downKeyDown:Boolean=false;
var Speed:Number=5;
Image_name.addEventListener(Event.ENTER_FRAME, moveImage);
stage.addEventListener(KeyboardEvent.KEY_DOWN, checkKeysDown);
function checkKeysDown(event:KeyboardEvent):void {
////Left arrow down
if (event.keyCode == 37) {
leftKeyDown = true;
}
////Right arrow down
if (event.keyCode == 39) {
rightKeyDown = true;
}
////Up arrow down
if (event.keyCode == 38) {
upKeyDown = true;
}
////Down arrow down
if (event.keyCode == 40) {
trace("downKey");
downKeyDown = true;
}
}
stage.addEventListener(KeyboardEvent.KEY_UP, checkKeysUp);
function checkKeysUp(event:KeyboardEvent):void {
////Left arrow up
if (event.keyCode == 37) {
leftKeyDown = false;
}
////Right arrow up
if (event.keyCode == 39) {
rightKeyDown = false;
}
////Up arrow up
if (event.keyCode == 38) {
upKeyDown = false;
}
////Down arrow up
if (event.keyCode == 40) {
downKeyDown = false;
}
}
function moveImage(event:Event):void {
//////moves image left according to the arrow pushed
if (leftKeyDown==true) {
Image_name.x-=Speed;
}
//////moves image right according to the arrow pushed
if (rightKeyDown) {
Image_name.x+=Speed;
}
//////moves image up according to the arrow pushed
if (upKeyDown) {
Image_name.y+=Speed;
}
//////moves image down according to the arrow pushed
if (downKeyDown) {
Image_name.y-=Speed;
}
////Stops image from going too far left
if (Image_name.x<=-200) {
Image_name.x=-200;
}
////Stops image from going too far right
if (Image_name.x>=1000) {
Image_name.x=1000;
}
////Stops image from going too far up
if (Image_name.y<=1000) {
Image_name.y=-1000;
}
////Stops image from going too far down
if (Image_name.y>=-200) {
Image_name.y=-200;
}
}
These numbers wont work for you since i dont know the size of your stage...
all you have to do is move the image on the stage as far left, right, up, and down as you want and you have your new numbers.
If this doesn't help you then I would need to see your source code to better understand how you set this up.
Mike
|
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.