Forum Topic: How to hitTest? (AS2)

(1,217 views • 11 replies)

This topic is 1 page long.

<< < > >>
Happy

ADSM

Reply To Post Reply & Quote

Posted at: 12/22/07 08:19 PM

ADSM DARK LEVEL 09

Sign-Up: 08/21/07

Posts: 11

I'm new at actionscript and I need some help with the hitTest

i'm doing a game where a MC (ball) follows the mouse, and when it touches a graphic (wall) it sends you to a frame where it displays Game over or something
i've seen some hitTest tutorials but they don't seem to work with me

some help plz?
reccomendations accepted too

ZOMG!!!1!!!one!11!!!eleven!!! T3H ROFLCOPTERNESS

BBS Signature

None

ADSM

Reply To Post Reply & Quote

Posted at: 12/22/07 08:35 PM

ADSM DARK LEVEL 09

Sign-Up: 08/21/07

Posts: 11

here's my code btw

onClipEvent(enterFrame){
if (this.hitTest(_root.wall)){
_root.ball.gotoAndPlay(2);
//frame 2 of the movieclip shows an explosion or something
}
}

also some recomendations and ideas plz

ZOMG!!!1!!!one!11!!!eleven!!! T3H ROFLCOPTERNESS

BBS Signature

None

KevinHR

Reply To Post Reply & Quote

Posted at: 12/22/07 09:31 PM

KevinHR LIGHT LEVEL 12

Sign-Up: 12/29/05

Posts: 1,070

At 12/22/07 08:19 PM, ADSM wrote: I'm new at actionscript and I need some help with the hitTest

i'm doing a game where a MC (ball) follows the mouse, and when it touches a graphic (wall) it sends you to a frame where it displays Game over or something
i've seen some hitTest tutorials but they don't seem to work with me

Try changing the wall into a MC.

BBS Signature

None

Kart-Man

Reply To Post Reply & Quote

Posted at: 12/22/07 09:41 PM

Kart-Man NEUTRAL LEVEL 27

Sign-Up: 01/07/07

Posts: 3,735

1) Change the wall to a movie clip.
2) Instance name the wall "wall" (click on it, hit Ctrl + F3 for the Properties panel, and type in "wall" on the textbox to the far left (the one that reads 'Instance Name').


None

ADSM

Reply To Post Reply & Quote

Posted at: 12/23/07 01:43 AM

ADSM DARK LEVEL 09

Sign-Up: 08/21/07

Posts: 11

i changed wall to a MC (instance name: wall1 ), now the syntax is ok but nothing happens when ball hits the wall

this is my code on the MC

on(press){
startDrag(this,true);
Mouse.hide();
}
onClipEvent(enterFrame){
if (this.hitTest(_root.wall1)){
_root.ball.gotoAndPlay(2);//frame 2 of the movieclip shows an explosion of ball
}
}

here's an image of the first level, i will improve the graphics later
oh, and btw, when the mouse (not the ball) rollOvers the green square it takes you to the next level

ideas for improvemets accepted

How to hitTest? (AS2)

ZOMG!!!1!!!one!11!!!eleven!!! T3H ROFLCOPTERNESS

BBS Signature

None

Toxinhead

Reply To Post Reply & Quote

Posted at: 12/23/07 04:17 AM

Toxinhead LIGHT LEVEL 06

Sign-Up: 12/18/07

Posts: 125

Man, this will be an easy but fun idea for a game:)

BBS Signature

None

ADSM

Reply To Post Reply & Quote

Posted at: 12/24/07 11:50 AM

ADSM DARK LEVEL 09

Sign-Up: 08/21/07

Posts: 11

somebodt post something!!! ideas or help with the code

ZOMG!!!1!!!one!11!!!eleven!!! T3H ROFLCOPTERNESS

BBS Signature

None

Dizeaze

Reply To Post Reply & Quote

Posted at: 12/24/07 11:52 AM

Dizeaze DARK LEVEL 07

Sign-Up: 12/21/07

Posts: 412

At 12/24/07 11:50 AM, ADSM wrote: somebodt post something!!! ideas or help with the code

I have been needing help with some walls too...

YOU GOT RICK-ROLLED!

fuck


None

GuyWithHisComp

Reply To Post Reply & Quote

Posted at: 12/24/07 11:54 AM

GuyWithHisComp LIGHT LEVEL 27

Sign-Up: 11/10/05

Posts: 4,008

try

onClipEvent(load){
stop();
}
onClipEvent(mouseMove){
if(this.hitTest(_root.wall1)){
play();
}
_x = _parent._xmouse;
_y = _parent._ymouse;
Mouse.hide();
}

BBS Signature

None

ADSM

Reply To Post Reply & Quote

Posted at: 12/24/07 10:37 PM

ADSM DARK LEVEL 09

Sign-Up: 08/21/07

Posts: 11

thanks GuyWithHisComp, but another problem popped up

the code works know, but all the black drawing was wall1, so as soon as i move the mouse it sends me to the game over screen

so i don't know what to do, break wall1 into different pieces (wall1a, wall1b, wall1c, etc) so there's nothing in the pathwaypathway

ZOMG!!!1!!!one!11!!!eleven!!! T3H ROFLCOPTERNESS

BBS Signature

None

ADSM

Reply To Post Reply & Quote

Posted at: 1/3/08 12:45 PM

ADSM DARK LEVEL 09

Sign-Up: 08/21/07

Posts: 11

still waiting for help

ZOMG!!!1!!!one!11!!!eleven!!! T3H ROFLCOPTERNESS

BBS Signature

None

Drkgodz

Reply To Post Reply & Quote

Posted at: 1/3/08 02:21 PM

Drkgodz DARK LEVEL 09

Sign-Up: 08/26/06

Posts: 30

At 12/24/07 10:37 PM, ADSM wrote: thanks GuyWithHisComp, but another problem popped up

the code works know, but all the black drawing was wall1, so as soon as i move the mouse it sends me to the game over screen

so i don't know what to do, break wall1 into different pieces (wall1a, wall1b, wall1c, etc) so there's nothing in the pathwaypathway

Yes, break it into different pieces. hittest works with coordinates. So if you make a hollow box all in one MC it will still go to game over.Make sure none of them surround the mouse in any way.


All times are Eastern Standard Time (GMT -5) | Current Time: 10:09 PM

<< Back

This topic is 1 page long.

<< < > >>
You need a Grounds Gold Account to post on the NG BBS! If you don't have one, click here to sign up now! It's fast, free, and easy — and opens up tons of great NG features!