Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 01-13-2011, 11:35 PM   #1
coutts14
Registered User
 
Join Date: Jan 2011
Posts: 8
Default [AS2] hittest help

I am kinda new to actionscript and stuff so i really need some help here.

I am creating a game where the cursor has to shoot moving targets and you will get ten points for some of the targets hit and 15 for the others.

The cursor has been replaced wuth a crosshair and is a movie clip named cursor_mc (instance name: cursornew). One of the targets is a movie clip called racoon_mc (same instance name).

I have a dynamic text box with a var:score and instance name of score.

PLEASE HELP!!
coutts14 is offline   Reply With Quote
Old 01-13-2011, 11:37 PM   #2
coutts14
Registered User
 
Join Date: Jan 2011
Posts: 8
Default Urgent need help with hit-test!!!!

I am kinda new to actionscript and stuff so i really need some help here.

I am creating a game where the cursor has to shoot moving targets and you will get ten points for some of the targets hit and 15 for the others.

The cursor has been replaced wuth a crosshair and is a movie clip named cursor_mc (instance name: cursornew). One of the targets is a movie clip called racoon_mc (same instance name).

I have a dynamic text box with a var:score and instance name of score.

PLEASE HELP!!
coutts14 is offline   Reply With Quote
Old 01-13-2011, 11:40 PM   #3
zyxstand
Platinum Member
 
Join Date: Dec 2010
Posts: 193
Default

as2 or as3?
as3:
Code:
var myscore:int = 0;
racoonmc.addEventListener(MouseEvent.MOUSE_DOWN, mousedown);

funciton mousedown(e:MouseEvent)
{
if (racoonmc.hitTestPoint(e.mouseX, e.mouseY, true)) {
myscore++;
score.text = myscore.toString();  // where score is the textbox
}
}
hope that helps
zyxstand is offline   Reply With Quote
Old 01-14-2011, 08:09 AM   #4
pezmetal
thrasher
 
Join Date: Feb 2010
Location: West Yorkshire
Posts: 45
Default

Is this a game in which you simply click the targets to "shoot" them? or do you have a character who shoots in the direction you click?

If it is the former then you don't necessarily need hitTest, only "onClick" functions.

Can you clarify exactly what you're trying to do?
pezmetal is offline   Reply With Quote
Old 01-14-2011, 11:57 AM   #5
orange gold
got as?
 
Join Date: May 2007
Posts: 628
Default

On Frame 1: (This isn't hit test by the way)
ActionScript Code:
PlayerScore = 0; //variable for number set. score.text = PlayerScore; //set the score text equal to the number (variable) of the current score (in this case the player starts at 0) racoon_mc.onPress = function() { //When the click the racoon. (spelled raccoon* by the way)      PlayerScore ++; // add 1 to the score.      score.text = PlayerScore; //set the score text equal to the number (variable) of the current score }// end the (when click) function
__________________
Feel free to PM me if you have a question
orange gold is offline   Reply With Quote
Old 01-14-2011, 12:54 PM   #6
coutts14
Registered User
 
Join Date: Jan 2011
Posts: 8
Default

Quote:
Originally Posted by pezmetal View Post
Is this a game in which you simply click the targets to "shoot" them? or do you have a character who shoots in the direction you click?

If it is the former then you don't necessarily need hitTest, only "onClick" functions.

Can you clarify exactly what you're trying to do?
Yeh you just click the targets to shoot them. The targets just pop up and down and you have to hit them, kinda l ike a game you would see at a fun fare or somin.
coutts14 is offline   Reply With Quote
Old 01-14-2011, 12:55 PM   #7
orange gold
got as?
 
Join Date: May 2007
Posts: 628
Default

Did you get my code running properly?
__________________
Feel free to PM me if you have a question
orange gold is offline   Reply With Quote
Old 01-14-2011, 12:58 PM   #8
coutts14
Registered User
 
Join Date: Jan 2011
Posts: 8
Default

Quote:
Originally Posted by zyxstand View Post
as2 or as3?
as3:
Code:
var myscore:int = 0;
racoonmc.addEventListener(MouseEvent.MOUSE_DOWN, mousedown);

funciton mousedown(e:MouseEvent)
{
if (racoonmc.hitTestPoint(e.mouseX, e.mouseY, true)) {
myscore++;
score.text = myscore.toString();  // where score is the textbox
}
}
hope that helps
Its AS2 thanks anyway.
coutts14 is offline   Reply With Quote
Old 01-14-2011, 03:30 PM   #9
pezmetal
thrasher
 
Join Date: Feb 2010
Location: West Yorkshire
Posts: 45
Default

Quote:
Originally Posted by orange gold View Post
On Frame 1: (This isn't hit test by the way)
ActionScript Code:
PlayerScore = 0; //variable for number set. score.text = PlayerScore; //set the score text equal to the number (variable) of the current score (in this case the player starts at 0) racoon_mc.onPress = function() { //When the click the racoon. (spelled raccoon* by the way)      PlayerScore ++; // add 1 to the score.      score.text = PlayerScore; //set the score text equal to the number (variable) of the current score }// end the (when click) function
yeah, this is pretty much what I would suggest...
though you may want a function to make the raccoons go back down when you hit them, as well:
If you already have a way that they go back down, simply call that function (or gotoAndPlay that frame) within the onPress function, after the score increment
e.g.

ActionScript Code:
racoon_mc.onPress = function() {      PlayerScore ++;      score.text = PlayerScore;      racoon_mc.gotoAndPlay("hide"); }
or...

ActionScript Code:
racoon_mc.onPress = function() {      PlayerScore ++;      score.text = PlayerScore;      hideRaccoon(); }
pezmetal is offline   Reply With Quote
Old 01-14-2011, 03:46 PM   #10
coutts14
Registered User
 
Join Date: Jan 2011
Posts: 8
Default

Quote:
Originally Posted by pezmetal View Post
yeah, this is pretty much what I would suggest...
though you may want a function to make the raccoons go back down when you hit them, as well:
If you already have a way that they go back down, simply call that function (or gotoAndPlay that frame) within the onPress function, after the score increment
e.g.

ActionScript Code:
racoon_mc.onPress = function() {      PlayerScore ++;      score.text = PlayerScore;      racoon_mc.gotoAndPlay("hide"); }
or...

ActionScript Code:
racoon_mc.onPress = function() {      PlayerScore ++;      score.text = PlayerScore;      hideRaccoon(); }
Thanks for the feeback. The targets move and down on a tween. Do i need to put the code on the mc itself ? or just on my actions layer?
coutts14 is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

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. The time now is 09:28 PM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.