How to make a game to replenish his life over time?

I tried to write codes in my game it reconstructs the life of the player over time.  But I had no success. For example, in Candy Crush, it's called 'life '. You have 5 lives to the fullest. And once you start a level, he removes 1 5 life point. And then the timer next to the label of life begins to count down from 20 minutes to 0. Once it reaches 0, it gives you 1 point of life back so that you can restart a level. I tried to do it like this: stop Frame EventListener countdown from 20 minutes to 0 whenever the number of life is less than 5 years, and once it reaches 5, numbers count. It sounds simple, and it's simple. But what happens if the player leaves the game so that the countdown timer? Let's say the player to the left of the game at 15:10 with 3 lives and reconstruct the 10 min for a life left. And the player starts the game again at 15:30. The player would then 4 lives and rebuild 10 min for a life left. I tried to do by using the date class. But the remaining time is wasted when I left the game and restart the game.

Instead of an absolute time countdown, count until you reach a maximum and dispatches an event when the maximum is reached. Have a separate object that stores the number and can be initialized at any point. When the user leaves the program, store the former total. When they start again, initialize a new instance of the object of the County with the old County. Display the countdown, if necessary, by subtracting the present value of the maximum value.

If your object might look like this:

Counter/public class extends EventDispatcher {}

protected var _count:int;

protected var _max:int;

protected var timer: Timer = new Timer (1000);

public void Counter(count:int=0,_max:int=20):void {}

_Count = count;

_max = max;

}

public void start (): void {}

timer.addEventListener (TimerEvent.TIMER, incrementTime);

Timer.Start ();

}

public function stop() {}

timer.removeEventListener (TimerEvent.TIMER, incrementTime);

Timer.Stop ();

}

public void incrementTime(e:Event=Null):void {}

_Count ++;

dispatchEvent (new Event ('countChanged'));

If (_count == _max) {}

dispatchEvent (new Event ('countIsMax'));

possibly could reset _count here

}

}

public function get count (): int {}

return _count;

}

public function get max (): int {}

return _max;

}

public function get count (): int {}

return _max - _count;

}

}

Its use might look like:

SerializableAttribute public class votrejeu extends Sprite {}

protected var counter: counter;

protected var life: int;

public var countText:TextField;

public var livesText:TextField;

public void YourGame() {}

Super();
logic to retrieve stored here number

counter = new Counter (storedCountThatYouRetrieved);

counter.addEventListener ('countChanged', updateCountText);

counter.addEventListener ('countIsMax', updateLives);

}

protected function updateCountText(e:Event):void {}

countText.text = String (counter.countDown);

}

protected function updateLives(e:Event):void {}

life ++;

livesText.text = String (lives);

}

}

Tags: Adobe Animate

Similar Questions

  • How to make a unique clip fade to white over time?

    I was chugging along using the full version of first Pro CC for a few months now and I need to make an image of the object in my new intro to natural color change it's pure white over a short period of time just before he explodes with electricity, I tried the effect of color change , but this doesn't seem to work with the color white for some reason any... Please help ASAP! Any help will be greatly appreciated!

    Fade to white video effect.

  • How to make a label (javafx) to display the current time dynamically?

    Hi all

    How to make a label (javafx) to display the current time dynamically?

    I have not found a Type of event related to the time in javafx API.

    Please give me some suggestions. Thank you!

    Sage

    There are lots of examples of JavaFX clocks available, for example https://gist.github.com/jewelsea/3388637 or http://blog.crisp.se/2012/08/09/perlundholm/an-analog-clock-in-javafx

    For a simple label displaying the time, the simplest thing is to create a Timeline with duration 1 second and the number of indefinite cycle, which triggers an event handler that updates the label:

    final Label clock = new Label();
    final DateFormat format = DateFormat.getInstance();
    final Timeline timeline = new Timeline(new KeyFrame(Duration.seconds(1), new EventHandler() {
         @Override
         public void handle(ActionEvent event) {
              final Calendar cal = Calendar.getInstance();
              clock.setText(format.format(cal.getTime());
         }
    });
    timeline.setCycleCount(Animation.INDEFINITE);
    timeline.play();
    

    (If you use Java 8, use the new time API, which is much more pleasant than calendar.)

  • Help, please... I need to know how to crop my video segments?  I also need to know how to make several clips to run at the same time by dividing the screens?  How to fade a clip?

    Help, please... I need to know how to crop my video segments?  I also need to know how to make several clips to run at the same time by dividing the screens?  How to fade a clip?

    I watched the video tutorials.  I need to know also how to add additional video tracks to my screen.  Any help please?

  • How to make a clip to close a number of times in Flash?

    Does anyone know how to get a clip to a certain number of times in Flash in a loop? I know how to stop a clip of looping using the this.stop (); order by placing the command in a separate layer from the Action Script, in a keyframe within the video clip timeline. This allows the clip to play through both, and then stop. But I need to clip loop more than once, maybe 2 or 3 times and then go back to the main timeline. Anyone know the code for this?

    Also, is it possible to place a break (I'm guessing, perhaps using a timer of some kind?) between the loops, so that the film is going to pause a few seconds before the loop is executed again, then stop? Please note that I must not the clip to stop when there's an event like a reversal or whatever it is. I just need to play a couple of times, pause between pieces and then stop and return to the main timeline. Please let me know if anyone can help.

    Thank you

    Sarah

    PS is there a reference work good, easy to use, anyone can recommend to create specific things in Flash using Script of Action? Guys do you have a favorite for beginners like me?

    There are different ways to do... the simplest is probably to put a bit of code directly in the scenario of your clip. Assuming that your frame 1 is a 'pause' with a stop() in there, you can add the following text:

    var loopCounter:int = 0;

    Stop();

    Then in the last frame of the clip:

    loopCounter ++;

    if(loopCounter == 3) {}

    dispatchEvent (new Event ("clipDoneLooping"));

    gotoAndStop (1);

    } else {}

    gotoAndPlay (2);

    }

    So in your main time line you have a condition that tells the clip to play with a gotoAndPlay (2); If you need to know the video has looped three times and has finished you can listen to the clipDoneLooping to ship.

    myClip.addEventListener ("clipDoneLooping", doSomething);

    And will be called the doSomething function.

    To place a pause between loops, you can use a timer object. Instead of the gotoAndPlay (2) conditional above, you should just start a timer.

  • How to make a game installed on the available for standard users administrator account?

    I installed a game on my administrator account, and it is only available on the administrator account. How can I make available to standard users? Thank you.

    Hello

    I suggest you follow the steps suggested by Malkeleah which has the same problem from the link:

    http://answers.Microsoft.com/en-us/Windows/Forum/Windows_7-security/standard-user-account-cant-access-programs/270e7f00-e744-4233-9ECB-53b12d2c4e8b

    If you need further assistance on this topic, let know us and we will be happy to help you.

  • How to make a game on iTunes (Mac App Store) using credit?

    So I got a $10 gift card for my birthday and I want to use it to get 'Fortune of Leo"($9.99). It says that I need to fill my billing information to get it. Please tell me how to solve this problem. Thank you! (BTW, it's on the Mac App Store)

    A $10 credit isn't enough to buy a game for $9.99 in the Mac App Store. The system adds the local sales tax in the final stages of the sale in most American States. You will need to buy a 2nd gift card or the credit card required for feeding compleete sale.

    By the end of 2012 mini Mac, OS X El Capitan 10.11.5 beta 2;  Watch, 38 mm silver AL, Watch OS 2.1; iPad 2 Air & iPhone 6 + iOS 9.3.2 beta 2;  Apple Airport Express

  • Help me: how to make a games record that was created for windows 2000, xp and vista on my new laptop windows 7?

    What should you change?

    What game? What type of disc (CD, diskette)?

    You can usually install games as you normally would. I'm trying to install a game as usual first and get back to us. There are steps to take if the normal routine does not work.

  • How to make a game

    Like a real game you can copyright and you add your website

    Hmm?

    Bohdan Pike

    Founder of BohdanGames

    Empire

    And I know that the cleverest kid

    11 YEARS OLD

    you forgot to add: Master Chief of the spectrum, thrush and Smersh

    Perhaps since you are in the beginning phase, then you can study the site MSDN Web and download a free visual basic program to see if the programming is in your blood.

  • How to make a game which is blacking out of work?

    Restart and reinstall does not work.

    If deletion and redownloading the app has not been set, and you also tried a soft-reset/reboot of the iPad (press and hold sleep and home for about 10 to 15 seconds buttons, ignore the "slide to power off", after which the Apple logo should appear so it could restart), then you could try contact the developer of the application (there of recent reviews of the app in the store mentioned a similar problem?)

  • How to make a script to stop his execution?

    I am brand new to scripting in Photoshop and coding in Java, and I need help. I want to ask the user and if they say 'yes' I want the script to stop completely. If 'no', I want to keep it.

    Is there a way to do this? I've seen examples that look like the one below using 'return', and they all say that it will work. But what is the function, not the whole script stop.

    =============

    function EndScript() {}

    return;

    Alert ("this line will never run '");

    }

    var PromptUser = confirm ("do you want to stop?");

    If (PromptUser) {}

    EndScript();

    }

    Alert ("If the user clicks Yes, I don't want this line to be executed.");

    =============

    Is there a kind of statement that stops just everything?

    Thanks for your help.

    By definition, return leaves only the function you are currently, so you cannot leave a part of the script that is not inside a function. What you want to do is put the script inside a function and then just call back in the case. Such as:

    function Script() { 
    
        var PromptUser = confirm("Do you want to stop?");
    
        if(PromptUser ){
            return;
            alert('this line will never execute');
         }
        alert("If the user clicks yes, I don't want this line to execute.");
    }
    
    Script();
    
  • How to make audio and video playback at the same time in movie maker?

    I've done some films with a flip camera and edited with Movie Maker.  However, when I played movies the sound does not match the video.  The sound was going faster.  How to synchronize the two together?

    Try to download windows media encoder 9 series, microsoft, download utilities

    also... Once installed, open it, select "convert video", change how data

    is to convert, convert a folder that you have created.

  • How to make text disappear when the mouse is over a button?

    Hello, I'm completely new to Flash, and well I need help. I created a page that contains static text in the Center.

    Page has buttons on the side and when I rollover a button text is displayed, but the problem is that when I rollover a button, static text in the Center is here and I want to hide as I can't read anything either because the texts are overlapping.

    How can I make the text in the centre disappear / hide when I rollover a button and how do I make it reappear when the mouse is the off button?

    I hope what I said makes sense.

    You can assign the code onRollOver and onRollOut buttons to the dispappear of text, but you will need make the text a movieclip with instance name that you can use to target to make it invisible.  In the example below, the button has an instance name of "btn" and the movieclip of text has an instance name of "text_mc".

    btn.onRollOver = function() {}

    text_mc._visible = false;

    }

    btn.onRollOut = function() {}

    text_mc._visible = true;

    }

  • How to make the password does not expire at all times.

    Hi all


    I have to set passwords for users do not expire, I have to change the password every six months.

    How can I make password does not expire at all times.

    Default tablespace, SPODIL
    Temporary tablespace, TEMP
    DEFAULT profile
    User created, XXXXXX
    (Locked) status, OPEN
    Password expires Date, 6/27 / 20105:59: 39 PM (I do this expiration date forever)
    Date of the lock,
    External name


    You can help.


    Thank you

    So what profile do you want to not apply the limitation of password change?
    Choose 1 & change it, and then make sure that this profile is applied to all users

  • Sleekbook 15b032el: how to make a recovery USB drive right the first time

    Hello. I just got a 15b032el running Windows 8 Sleekbook. I am in a process of making a recovery USB drive and I want to just do it right the first time. I understand that it is only possible at the same time. I was wondering how many gigabytes of capacity must have the USB key. Anyone of you who knows? Thank you. Rgds.

    Hello

    The USB Flash drive is 32 GB - for a complete description of the process of creating a recovery Image on a USB Flash drive, see the following HP document.

    Creating recovery media - Windows 8.

    Kind regards

    DP - K

Maybe you are looking for

  • App store search won't work; Enter name

    Search App Store no longer works. I'm getting the name. Even if it appears in the list and I hit search, nothing happens.  I can update applications; can download apps via 'Explorer' and 'top charts' but no research.

  • iPhone IMEI number 6 stolen necessary

    6 iPhone stolen from my former employer. Without box or invoices. And the various countries of the company to contact. All possible means to get the IMEI number to use to locate the iphone app for the police?

  • MathScript transpose a table 1 d?

    Hello I had a problem with some Mathscript stuff, but I've found a workaround. Problem now is that I do not understand why the workaround works... I put a table of column 1 d in a Mathscript node and without him doing anything out. BUT the output has

  • G3 250 HP not drivers

    Hello. I just got my new laptop g3 250 hp. I installed win 8 and when I went to download driver there is no drivers. Please give download link

  • reset the wizard import identity in windows live mail

    Ayuh, I'm trying to move from XP to W7. I remember seeing in migrating from OE to WLM FRONT operating system. (Because the WLM for W7 version lacks the import OE account available in the XP compatible version Wizard?) I installed WLM on XP, and all m