How do you make a game to replenish its lives over time?
I have tried to write codes to my game so that it replenishes the player's lives over time. But I have had no success. For example, in Candy Crush, it's called 'lives'. You can have maximum of 5 lives. And once you start a level, it takes off 1 life from the 5 lives. And then the timer next to the lives label starts counting down from 20 minutes to 0. once it reaches 0, it gives you 1 life back so that you can start a level again. I tried to do this like this: Frame EventListener to count down from 20 minutes to 0 whenever the number of lives is under 5, and once it reaches 5, stop counting down numbers. It sounds simple and it is simple. But what if the player quits the game while the timer is counting down?? Let's say the player left the game at 3:10pm with 3 lives and 10 min left for a life replenish. And the player starts the game again at 3:30pm. Then the player would have 4 lives and 10 min left for a life replenish. I tried to accomplish this by using date class. But the remaining time gets messed up whenever I quit the game and restart the game.
Instead of counting down from an absolute time, count UP until you hit a maximum and dispatch an event when the maximum is reached. Have a separate object that stores the count and can be initialized at any point. When the user quits, store the old count. When they start again, initialize a new instance of the count object with the old count. Display the counting down, if necessary, by subtracting the current value from the maximum.
So your object might look like this:
public class Counter extends EventDispatcher {
protected var _count:int;
protected var _max:int;
protected var timer:Timer = new Timer (1000);
public function Counter(count:int=0, max:int=20):void {
_count = count;
_max = max;
public function start():void {
timer.addEventListener(TimerEvent.TIMER, incrementTime);
timer.start();
public function stop() {
timer.removeEventListener(TimerEvent.TIMER, incrementTime);
timer.stop();
public function incrementTime(e:Event=Null):void {
_count++;
dispatchEvent(new Event('countChanged'));
if (_count==_max) {
dispatchEvent(new Event('countIsMax'));
//optionally could reset _count here
public function get count():int {
return _count;
public function get max():int {
return _max;
public function get countDown():int {
return _max - _count;
Usage would look something like:
public class YourGame extends Sprite {
protected var counter:Counter;
protected var lives:int;
public var countText:TextField;
public var livesText:TextField;
public function YourGame() {
super();
//logic to retrieve stored count here
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 {
lives++;
livesText.text = String(lives);
Similar Messages
-
HT2478 how do you make the setting to change desktop background every time you shut down your mac
how to make setting to change desktop background every time you close your mac
because i want to make it if anybody tries to change my dekstop picture i want it to go backto set desktop pictureDon't let other people access your Mac in admin mode - they might change something a lot more important than the Desktop picture.
However you can use Automator: create an Application in it, and select 'Set the Desktop Picture' from the Library. Choose the picture you want. Save the application, then go to System Preferences>Accounts>Login Items and select the Automator application you just created. This will then run at startup and set your chosen picture. -
How do we make Facebook games (Cityville) show full screen on ipad?
How do we make Facebook games (CItyville) show full screen on ipad?
> Is there a way that I can change something to make the
window with the
> three
> business portraits open to full screen when you click on
the Gallery
> button?
No. Modern browsers are designed to protect users from that
kind of
manipulation. Typically, web users don't want their browsers
windows
manipulated.
Walt
"Bill Artman" <[email protected]> wrote in
message
news:gihqrl$gnq$[email protected]..
> I am using Dreamweaver MX 2004 with Windows XP.
>
> My question is a page from my homepage
www.artmanphoto.com > Portfolio >
> Business Portraits then click on the Gallery button.
When my web designer
> built my site there was only two business portraits and
when you clicked
> on the
> Gallery button the window was smaller and did not expand
to a full screen
> display. Tonight I added a third portrait and the window
is still smaller
> than
> the full screen display so you have to use the
horizontal scroll bar to
> view
> all three images or you can click on the Expand button
in the upper right
> corner of the screen to make the window display full
screen. I thought
> that
> when I added the third portrait the and it was displayed
on my website
> that the
> window would expand to show all three portraits but it
didn't.
>
> Is there a way that I can change something to make the
window with the
> three
> business portraits open to full screen when you click on
the Gallery
> button?
>
> Thanks very much for your help!
>
>
> -
How do you make a web browser?
I would like to make a Web Browser of my own but how did you make FireFox?
Read this:
http://thepattysite.com/window_sizes1.cfm
You don't want to try to launch your site to full screen,
honest, as you'd
drive your (potential) visitors away.
Jo
"Steve Zavodny" <[email protected]> wrote in
message
news:escrfa$s7$[email protected]..
> How do you make a web browser launch your site to a
specific size or even
> full screen?
> Thanks... -
How do you make superscripts and mathematics in Preview's text annotation?
When adding text annotations that include scientific notations, how do you make superscripts, e.g. "3.2 × 10^{-23}"?
Searching Help for 'superscript' turns up nothing, suggesting the command does not exist, as it does under Baseline etc. in iWork. Please tell me this is not the case! If it is, has the situation been improved in the new operating system?
A related issue: I wish to include other mathematics -- is there a way to include mathematics similar to LaTeX? Might Preview incorporate using latex code in the future, so I can easily type "\exp{-\lambda t}" etc and have the math appear?
I'm adding text annotations to PDF lecture notes in Preview, basically filling in blanks the instructor has left so students will pay attention in class, and these annotations include superscripts; I wish to format properly.
Thank you!Once you have the circle shape displayed, long press on the border of the circle. Once it is highlighted, drag horizontally or vertically. This should allow you to distort the circle into an ellipse (or the square into a rectangle).
Hope that helps,
Frank
Sketch Engineering -
How can you make one button preform different actions in Xcode?
How can you make one button "preform a click" and "orderfront"? Is that possible? Because what I am doing is making a welcome window to my application for Mac OS X 10.6, and I have two buttons in that window, one says "Connect" which connects a a WebView to a url and the other button opens up the main window. So how can I a make a button do multiple things at once??
Ah - If you are just using bindings between various objects from Interface Builder, you can reduce your application code a bit (sometimes quite a bit), but there is only so far you can go. Typically variables and routines are defined in your application that Interface Builder hooks into, so that your application code (usually Objective-C, but can be others) can use these variables and routines to determine what is happening in the user interface.
I'm not sure how up-to-date the project code is (or what programming code you are familiar with), but you can take a look at Apple's Cocoa Application Tutorial to see what is (usually) involved in creating an application. -
How can you make the iPod tell the diff between a movie and music video
Greetings!
How can you make iPod tell the difference between a Music Video and Movie? Everything I put up on the iPod falls into Movie. So is it something I have to do in iTunes?
Thanks for the help!Rightclick the video in iTUnes, hit Get info then the "Options" tab. Beside kind you can set it to movie. music video. or TV show
-
How do you make the sentences you input in a drop down list wrap to the next line?
How do you make the sentences that you input in a drop down list to wrap to the next line?
You can't.
see this thread for more info: Can you set drop down list as multi-line??? -
I have multiple devices used by family members, how do you make sure the kids don't see Moms messages from Dad and visa versa?
Hi Roger:
Thanks for the reply. I think I figured out the problem. Apple has confused (at least in my mind) the different IDs that people can have. In the iCloud settings, they use the term Apple ID and not iCloud ID. I guess there really is no such thing as an iCloud ID. There are Apple IDs with various attributes. This is not clearly explained or easy to see (how could I look up to see if my Apple ID is associated with iTunes for example?).
I created, what I thought were iCloud IDs for each family member, but we all use my Apple ID for iTunes.
One other question - why does the syncing of Notes using iCloud require an @me.com email account. That makes no sense to me.
Thanks for your help!
AO -
How do you make a 3d octagon in photoshop cs4 extended?
How do you make a 3d octagon in photoshop cs4 extended that you can map artwork to? I've been searched online for a solution that doesn't involve using a 3D program but can't find anything. Can't you extrude a shape like in Illustrator, or exporta true 3D shape from Illustrator that will work? I'd use Illustrator but the mapping thing is finicky, and doesn't alow wrapping images around angles. (now someones going to say: "Don't mention any other programs in a PHotoshop forum!" Yeah yeah, there should be a forum then about using different Adobe programs together.) End of rant, any suggestions much appreciated.
Thanks,
MikeThanks for your prompt response!
Suggested Bridge Update
It turns out that I got a message that this update had already been installed, which led me to more carefully look at the Bridge window and (finally) see that the Output module had a Quality dropdown: Full, 300 ppi, 150 ppi, 96 ppi and 72 ppi. Thanks! I decided to compare the CS4/Bridge results to those I got in CS2 with its convenient File/Automate/PDF Presentation/Multi-Page Document routine that I like.
My project was an 8-page PDF made from scanned pages of handwritten notes into which some fairly small type had been insert using the Photoshop CS2 Type tool. In Photoshop CS2, I had settled on "medium quality" JPEG compression as giving a "reasonable" file size (about 7 MB) and "very good/excellent" image quality. I experimented with making the PDF in Bridge, using all five Quality levels. See table below. The Bridge "good minus" file was about the same size as the file produced in CS2, which I judged to be "very good/excellent" and slightly better visually than the 300-ppi, 23.5-MB Bridge file.
Bridge Quality:
Full
300 ppi
150 ppi
96 ppi
72 ppi
File Size:
25.2 MB
23.5 MB
7.6 MB
3.2 MB
2.1 MB
Subjective Quality:
Very good
Very good
Good minus
Poor
Useless
I appreciate that you may not be all that interested in these observations, but it seems to me that Adobe has done us no favors in the multi-page PDF department in going from CS2 to CS4!
Install the Old Contact Sheet/Picture Package Plug-Ins
I had already done this some time ago, in order to get in CS4 the File/Automate/Contact Sheet II feature I liked in CS2. It does not appear to me that this plug-in has anything to do with make multi-page PDF's. Perhaps I'm missing something.
Again, thanks for your response! -
I have three device: Macbook Pro (OSX 10.7.5) for work; an iPad and a Blackberry for mobile. I used mail, iCal, and Address Book combine with mobileme (iCloud) to exchange data such as contact, calendar and task from my Mackbook Pro to my iPad but never to Blackberry. The problem is my boss was asking me to change to Outlook 2011 for Mac because some of the email that I sent from Mail did not appear in my client's Blackberry. So how do you sync iCloud (contact, calendar, task) to Outlook 2011 for Mac? and how do you make seemless sync between iCloud to Outlook 2011 to Blackberry device or an iPad?
Best regards,
W. SasongkoMore Like This --------------------------------------->
-
How do you make a MacBook Pro talk to an Epson printer?
MacBook Pro
OS X 10.6.8
(Thinking about getting another MacBook)
I had an Epson Artisan printer, got an Epson Workforce WF-3640 new in Jan, hardly used because I cannot make it do what I want it to do. Wireless connection is good.
With the MacBook Pro, the interface with the Epson printers is not what it used to be on the G4: no ColorSync, no 2-sided, no thick paper, none of those kinds of instructions appear on the generic printer control panel. Which by the way, bears NO resemblance to the Epson manual screenshots, and the instructions in the Epson manual are useless.
How do you make a MacBook Pro talk to an Epson printer? And by the way, I cannot use the scanner either. I have to set up a document to print, then when the printing progress box appears, click on the scanner icon.
Also
Printer has 2 compartments. Top compartment #1 for all types paper.
Bottom compartment #2 for plain paper only.
I load glossy photo paper in #1, it prints plain paper from #2 even though I entered instructions on the control panel on the printer.If you haven't done so already, try resetting the printing system.
Reset Printing System -
How do you make an array of image icons and then call them?
How do you make an array of image icons and then call them, i have searched all over the internet for making an array of icons, but i have
found nothing. Below is my attempt at making an array of icons, but i cant seem to make it work. Basically, i want the image to match the value of the roll of the dice (rollVal)
Any help would be greatly appreciated, some code or link to tuturial, ect.
/** DiceRoller.java
* Roll, print, Gui
import javax.swing.*;
public class DiceRoller extends JFrame
private ImageIcon[] image ;
public String[] images = { "empty", "dice1.jpg",
"dice2.jpg", "dice3.jpg", "dice4.jpg",
"dice5.jpg", "dice6.jpg" };
public Dice die;
private int rollVal;
public int rollNum;
private JLabel j1;
public DiceRoller(){
j1= new JLabel("");
die =new Dice();
int rollVal;
rollVal = die.roll();
image = new ImageIcon[images.length];
for(int i = 0; i < images.length; i++){
image[i] = new ImageIcon(images);
if (image!=null){
j1.setIcon(image[rollVal]);
System.out.println("Roll = "+die.roll());Demo:
import java.awt.*;
import java.net.*;
import javax.swing.*;
public class IconExample {
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable(){
public void run() {
launch();
static void launch() {
try {
Icon[] icons = new Icon[6];
for(int i=0; i<icons.length; ++i) {
String url = "http://www.eureka-puzzle.be/cast/images/dice" + (i + 1) + ".jpg";
icons[i] = new ImageIcon(new URL(url));
display(icons);
} catch (MalformedURLException e) {
throw new RuntimeException(e);
static void display(Icon[] icons) {
JPanel cp = new JPanel();
for(Icon icon : icons) {
cp.add(new JLabel(icon));
JFrame f = new JFrame();
f.setContentPane(cp);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.pack();
f.setLocationRelativeTo(null);
f.setVisible(true);
} -
How do you make the background of an object transparent in Adobe Illustrator?
Hello Forum.
How do you make the background of an object transparent in Adobe Illustrator?
I have been having issues with using the Magic Wand tool in Adobe Illustrator as well as the lasso tool.
Basically, I am trying to put a small graphic into a new Illustrator file.
The first thing I tried to do is to use the magic wand tool. But I found out that this did not work on a jpeg image since it did not have any individual objects to select.
So I tried something new. I opened the file in Adobe Photoshop and used the lasso tool to select an area. Then I coped this area. Then I tried to paste it into Adobe Illustrator. But the background was not transparent for the pasted image.
How do I make the background transparent.
I made this small video to show what I am talking about:
http://youtu.be/2LgMGEF6z10Don't Copy/Paste the image.
Make it transparent in Photoshop, save a PSD and place it in Illustrator -
how do you make room on your start up disk. i am trying to do the update but don't have enough space
Try this:
1. Open "Finder", then navigate to "Movies" on the left side. Click on "iMovie Projects"
2. Move desired movies and clips to trash, or your flash drive.
*PS* Its dangerous to have a full hard drive, I would recommend either trashing, or transferring files to another computer. Trash applications you no longer use as well.
Maybe you are looking for
-
Installing a new hard drive and using Time Machine to Restore system
I just upgraded a Macbook (2006) hard drive and had problems importing the Time Machine backup. The problem was that the initial install discs were for Tiger, which did not support Time Machine. After numerous attempts at a work-around I solved this
-
I have a Sony home cinema amp and the only unused connection is a DMport. I have googled, but can't seem to get a definative answer. Can anyone help?
-
Outlook crashed. Uninstalled and re-installed. All working, except the Contacts folder on Desktop is empty. Contacts on E2 are fine and HotSync Log show that Contacts have HotSync'd. Where has it gone? Could it be an Outlook issue? Any assistance gre
-
All applications unresponsive for 30 seconds, happens regularly, every few minutes
I have a macbook pro I bought in October 2010. Every day I take it to and from work, with virtually identical usage/applications open. Yesterday when I got home and opened the lid, the computer stalled out. I could move the mouse around, but no app
-
when trying to save my ai file for the web, i get the following message: "The process could not be completed. The file was not found." (translation from german, could be a bit different in english). Any ideas what it could be? thanks. it works if i e