flash actionscript:
I'm making a game where I need variables to kepp track of life points, so that when life_points = 0 gotoAndPlay *Losing Screen* I dont know how to do any of this though so any hep would be appreciated!
life_points = 3; then somewhere else... // when hit/killed etc. life_points --; then : if( life_points ==0){ gotoAndStop("losingScreen"); } now that is the basics... but you would need to do more... function tookDamage(){ life_points --; if( life_points ==0){ gotoAndStop("losingScreen"); } } then when your character gets hits... // whatever tracks hits includes a function call to that.... tookDamage(); does that help, cheers,
That helps, but I want it to take a damage point when a monster hits your character, so would it be like this? if (_root.you, hittest(_root.monster) life_points -- Also, I'm really new at this so could you explain the function thing? I just want to learn this without learning ActionScript Bottom-Up. Thanks
okay, lets think about how to explain it... 2 movieClips... "myCharacter" and "monster" now both have events on them... in particular we are interested in what happens to us... we are the important object so open the myCharacter movieClip and we are going to put some actions on the movieClip... this.onEnterFrame = function(){ // test to see if we get hit if(this.hitTest(_root.monster)){ // we got hit and need to react accordingly life_points --; } } now whilst that will check to see if we got hit and then reduce our life points, it doesn't check to see if we are dead and need to play the losing screen... and remembering that code on a timeline only runs once unless looped, as far as our code is concerned, we haven't told it anything about our new life state... so rather than writing a lot of code in a lot of places, we have a single function that runs each time... in this case I called it 'tookDamage' function tookDamage(){ _root.life_points --; if(_root.life_points ==0){ _root.gotoAndStop("losingScreen"); } } the function will reduce the life_points variable by one... then check to see if you have any life left... so our code then becomes like this : // either on main timeline or relative to your character _root.life_points = 3 function tookDamage(){ _root.life_points --; if(_root.life_points ==0){ _root.gotoAndStop("losingScreen"); } } // then on your myCharacter movieClip : this.onEnterFrame = function(){ // test to see if we get hit if(this.hitTest(_root.monster)){ // we got hit and need to react accordingly _root.tookDamage(); } } does that help? cheers
Don't see what you're looking for? Try a search.
|