Stick Page Forums Archive

Hit Test + Moving [Flash][Actionscript]

Started by: Micky moox2 | Replies: 10 | Views: 5,066

Micky moox2
2

Posts: 110
Joined: Aug 2005
Rep: 119

View Profile
Sep 2, 2005 8:24 PM #365
first you need to create a new object, a circle for example

select it and push F8. make it a movieclip. then go to its properties and give it the instance name of circle.

go into its actionscript and add this text (to make it move)

onClipEvent(load){
moveSpeed = 5;
}

onClipEvent(enterFrame){
if(Key.isDown(Key.UP)){
this._y -= moveSpeed;
}
if(Key.isDown(Key.DOWN)){
this._y += moveSpeed;
}
if(Key.isDown(Key.RIGHT)){
this._x += moveSpeed;
}
if(Key.isDown(Key.LEFT)){
this._x -= moveSpeed;
}
}

next you will create a new object, a square for instance. make it a movieclip aswell, and give it the instance name square.

now put this in the circle:

onClipEvent(enterFrame){
if(this.hitTest(_root.square)){
_root.gotoAndStop(2);
}
}

this will make it so that when this(the circle) hits the square, the movie will go to the next frame (if you wanted you could put this in the sqaure and change the _root.square to _root.circle)

on each frame, one and two, put:
stop();

on the second frame you can put something like "well done" if you want.

you can replace the "gotoAndStop(2);" with whatever you want

for example, if you wanted a wall, draw a line along the right handside of the frame, and make it a movieclip, call it rightWall in instance name.

then you'd replace the _root.square with _root.rightWall and replace the "gotoAndStop(2);" with:

this._x -= moveSpeed;

this will make it so when the circle hits the wall it will be stopped from moving anyfurther, as when you move right at movespeed you will also be moved left. making no movement

hope this helped all you budding young game makers... probably not, but hey...
LXXXIII

Posts: 0
Joined: Jun 2025
Sep 2, 2005 9:13 PM #367
o.O ...............................wow....jibberish.....gj micky.....heres a cookie

.
^ thats a really small cookie
master tenku

Posts: 0
Joined: Jun 2025
Dec 11, 2005 7:05 PM #2693
Nice tutorial... Can i ask what flash program your using with this, i'm trying to decide which one to buy.
ultimitss

Posts: 0
Joined: Jun 2025
Dec 11, 2005 7:59 PM #2695
yeah... well im a total noob to this, i followed your tutorial but nothing happens when the circle hits the square :confused:
FrAnKeH
2

Posts: 602
Joined: Aug 2005
Rep: 91

View Profile
Dec 11, 2005 11:58 PM #2701
Quote from master tenku
Nice tutorial... Can i ask what flash program your using with this, i'm trying to decide which one to buy.


Flash 8
Buy flash 8.
funnyav
2

Posts: 95
Joined: Oct 2005
Rep: 10

View Profile
Jan 26, 2006 8:05 PM #4348
yeh, nothing happens, and im using flash 8 aswell.
general_zim
2

Posts: 62
Joined: Oct 2005
Rep: 10

View Profile
Jan 30, 2006 2:25 AM #4430
Same with me. I'm using Flash MX 2004. I get this problem with hitTest all the time. I think its retarded that Flash can't make it work. Come on, Macromedia! Make hitTest actually WORK instead of displaying friggin output or not working at all! :mad: :mad: :mad: :mad: :mad: :mad: :mad: :mad: :mad: :mad:
FrAnKeH
2

Posts: 602
Joined: Aug 2005
Rep: 91

View Profile
Jan 30, 2006 2:31 AM #4431
I use flash8, all my hitTests work.
You must be blaming the program for your short comings.
general_zim
2

Posts: 62
Joined: Oct 2005
Rep: 10

View Profile
Jan 30, 2006 2:36 AM #4432
I don't know what the problem is, but absoulutley NO hitTests work for me at all, and it kills me. I can't even make a simple game where you have a circle that trys to walk through the door, and, lo and behold, it doesn't go to the nextFrame();!! Jesus. Whew. Sorry. Let me catch my breathe.......................................ahem.................ok. sorry 'bout that. Anyway, yup.
Polnareff
2

Posts: 17
Joined: Nov 2005
Rep: 10

View Profile
Jan 30, 2006 2:02 PM #4435
Maybe because you forgot a "_root" before the "nextFrame();"

=)

Learn about target paths, especially when you are putting code on a movieclip. Just by forgetting "_root" in one place, you can render an entire piece of code completely useless.

A good idea is to never have two of the same clip event handlers on one movieclip. In this tutorial, Micky says to put two "onClipEvent (enterFrame)" on the same movieclip. You should always avoid doing this, it will cause problems. Try merging the two, and see if it works.
gamer_33

Posts: 0
Joined: Jun 2025
Feb 1, 2006 9:42 PM #4474
for me it work just i want to ask if anyone know how to put animation when your caracter is moving. i know all the moving jump speed aceleration stuff but how can you just make that on your car the whelle turn whene you drive or to make your caracter walk. anyway pls answer fast!
Website Version: 1.0.4
© 2025 Max Games. All rights reserved.