If you haven't already viewed the following tutorial I suggest you do.
8 Way Movement Tutorial
- First make sure you gave your charector the instance name of "man"
- Then draw your wall (can just be a line if you want)
- Select your wall
- Hit "F8"
- Name your wall and select "Movieclip"
- Then click "OK"
- Now skip to the Action Scripting Section below
You will have to put a different action script based on the way your charector will be hitting the wall (from what side). He can hit it from the top, the bottom, the left, or the right. Choose below and add the opproperiate Action Script.
Hit From Above:
- onClipEvent (enterFrame) {
- if (this.hitTest(_root.man)) {
- _root.map._y -=5;
- }
- }
Hit From Below:
- onClipEvent (enterFrame) {
- if (this.hitTest(_root.man)) {
- _root.map._y +=5;
- }
- }
Hit From Left:
- onClipEvent (enterFrame) {
- if (this.hitTest(_root.man)) {
- _root.map._x +=5;
- }
- }
Hit From Right:
- onClipEvent (enterFrame) {
- if (this.hitTest(_root.man)) {
- _root.map._y -=5;
- }
- }
Thats It, Now Test Your Game/Movie!
Please let me know how this went for you...
8 comments:
Just a correction...
In the code of the wall
the code are root the map objet,
this word have to be the instance name of the player, in this case "man".
ex:
onClipEvent (enterFrame) {
if (this.hitTest(_root.man)) {
_root.man._y -= 5;
}
}
well, yes you would do that if u wanted to have the player move around the screen, but this way makes the map or background move while your player apears to be moveing. Either way is fine, but in the way that was posted you can have bigger maps.
it didnt work for me i put all the scripts in and made my man jump hoping he'd hit it and fall back down but he just went through it have i done something rong??
Thanks, that helped HEAPS. I've been trying to get a hitTest that works for a couple of days now, Thanks!
Worked great. Thanks a lot. Now my Pac Man game works.
My guy just went through, hit the ground and then rose up to the platform until he was ._y-=5; from the platform... how can i make it so when he touches the platform he stops?
I tried to get it to work at first it did and then it didn't Which mean I must have done something wrong idk what this was the
code I used for the Walls (I put the code from the appropriate wall)
onClipEvent (enterFrame) {
if (this.hitTest(_root.jack)) {
_root.map._y -=5;
}
}
onClipEvent (enterFrame) {
if (this.hitTest(_root.jack)) {
_root.map._y +=5;
}
}
onClipEvent (enterFrame) {
if (this.hitTest(_root.jack)) {
_root.map._x +=5;
}
}
onClipEvent (enterFrame) {
if (this.hitTest(_root.jack)) {
_root.map._y -=5;
}
}
Post a Comment