|
|
|
#1 |
|
Member
Join Date: Jul 2002
Posts: 72
|
restricting movement from arrow keypad
Hi,
I am playing around making a little game from a tutorial and i am having trouble trying to limit where the "car" can travel on the screen. At present it has a free range and will disappear out of view if asked to. Can anyone make a suggestion what code i need to add? I have been searching and trying for two hours but just cant get it to work. This is what i have at present
Basically i just want to limit the cars movement to within the track! Any help or advice would be greatly welcomed. Barry EDIT: Added as tags. - jbum Last edited by jbum; 10-11-2004 at 04:44 PM. |
|
|
|
|
|
#2 |
|
Senior Member
Join Date: Feb 2004
Location: Los Angeles
Posts: 2,920
|
Here are two methods you can use:
Method #1: You can add bounds to your onEnterFrame handler, as follows:
This will keep the car within a rectangle specified by minX-maxX and minY-maxY. Method #2: If you want to restrict the car to a more complicated shape, then you'll probably want to do a hitTest on the track, like so: For example:
|
|
|
|
|
|
#3 |
|
Member
Join Date: Jul 2002
Posts: 72
|
i want a rectangle shape so the first bit of code is fine.
Thank you very much, people like you are priceless! Barry |
|
|
|
![]() |
|
||||||
| Thread Tools | Search this Thread |
| Display Modes | |
|
|