To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here


A Flash Developer Resource Site

Go Back   Flash Kit Community Forums > Flash Help > Flash MX

Reply
 
Thread Tools Search this Thread Display Modes
Old 02-08-2007, 11:21 AM   #1
Gorfy
Member
 
Join Date: Jun 2005
Posts: 45
Prevent movement off screen

Hi,

I curretnyl have this code for moving a character left and right on the stage:

onClipEvent (load) {
speed = 15;
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.LEFT)) {
_x -= speed;
_xscale = -100;
}
if (Key.isDown(Key.RIGHT)) {
_x += speed;
_xscale = 100;
}
}

Is there a way I can make it so that when the player reaches a certain point at the ede of the screen it will prevent them from moving further i nthat direction (perhaps something where once it reaches a certain distance to the left then only the right key will work)

Thanks
Gorfy is offline   Reply With Quote
Old 02-08-2007, 12:04 PM   #2
prabin
Junior Member
 
Join Date: Feb 2007
Posts: 3
I Add some code with urs!

onClipEvent (load) {
speed = 15;
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.LEFT)) {

preXcor=_x;

_x -= speed;
_xscale = -100;

if (_x<0){
_x=preXcor

}
}
if (Key.isDown(Key.RIGHT)) {
preXcor=_x;
_x += speed;
_xscale = 100;
tot=_x+this._width
if (tot>Stage.width){
_x=preXcor;
}


}
}
prabin is offline   Reply With Quote
Old 02-08-2007, 12:21 PM   #3
Gorfy
Member
 
Join Date: Jun 2005
Posts: 45
That works great thanks!
Gorfy is offline   Reply With Quote
Reply

Go Back   Flash Kit Community Forums > Flash Help > Flash MX

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 11:50 PM.


internet.commerce
Be a Commerce Partner
 »  »  »  »  »  »  »
 »  »  »  »  »  »
 

    

Acceptable Use Policy


The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.