Home Tutorials Forums Articles Blogs Movies Library Employment Press

Go Back   ActionScript.org Forums > General > Gaming and Game Development

Reply
 
Thread Tools Rate Thread Display Modes
Old 12-20-2010, 02:43 AM   #1
Mablargy
Registered User
 
Join Date: Dec 2010
Posts: 10
Default [AS2] Help with attacking sequence.

Hey guys, I'm making a top view shooter kind of thing, so all you pretty much see are circles, but you can see the main circle's hands, to punch things.
So I made an attacking animation, the left hand punching, then the right hand punching.
I already have it set up so that when you click, the left hand punches, but I want to set it up like, once he punches, a timer will go off, and during that timer, if you click again, he would punch with the right hand, and then you'd have to wait till the hands are at their starting positions to punch again, except I can't think of anything that would help me out here.

I've tried this so far, but no luck
ActionScript Code:
if (punchLeft == false) {         onMouseDown = function () {             player_mc.gotoAndPlay(2);             punchLeft = true;         };     }     if (punchLeft == true) {         onMouseDown = function () {             player_mc.gotoAndPlay(11);             punchLeft = false;


Any other method would work too, I just don't it to do what it currently does, which is if I click 3 times, you will see the left punch repeat itself three times.
That's what I'm trying to avoid...

Any help would be greatly appreciated.

Last edited by Mablargy; 12-20-2010 at 02:55 AM.
Mablargy is offline   Reply With Quote
Old 12-21-2010, 07:49 AM   #2
dialectric
Senior Member
 
dialectric's Avatar
 
Join Date: May 2006
Location: USA
Posts: 614
Default

Hi,

Two ways to incorporate a timer - use a setinterval, or onenterframe to update a countdown variable. The timer version is somewhat simpler, and uses an onenterframe function, which you should add into your existing onenterframe function if you already have one. It would look something like:

I've also combined your onMouseDown functions into one to make the code easier to follow:

ActionScript Code:
onenterframe = function (){     if (punchLeft == true){         if (countdown > 0){             countdown--         } else {       punchLeft = false }; onMouseDown = function () {     if (punchLeft == false) {          //first punch thrown starts counter                  player_mc.gotoAndPlay(2);                  punchLeft = true;           countdown = 1000;             } else if (punchLeft == true) {         //counter is still going; show right punch                 player_mc.gotoAndPlay(11); };

(note - this code is untested, and may have minor syntax problems)

- dialectric
dialectric 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 08:28 AM.

///
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.