An onsceen timer for game???

Hi,
I have to make a computer game in java3d and I'm pretty clueless, any help I could get here would be great.
Current problem : Once the user presses a "Start" button I want a timer counting down from 5 mins. I want to timer to be on screen so the user can see it the whole time he is playing the game and when the timer is up a message appears ie GAME OVER! and the game stops running.
Does anyone have any ideas or have done this before?? Heres some code on it I've hacked together so far.
Thanks,
Sean
//create start button to start game/timer
private Buttton go = new Button("Start");
Panel p = new Panel( );
p.add(go);
add("North",p);
go.addActionListener(this);
go.addKeyListener(this);
public void actionPerformed(ActionEvent e ) {
// start timer when button is pressed
if (e.getSource()==go){
//if (time timer is not running) ???
{ //start timer +display timer ???
//when timer == 0.00 add "game over" message to screen + stop game ???

That's how you would do it in Java2D, for sure.
If you want to put some Java2D stuff around your canvas, this kind of thing should work fine.
If you want to incorporate it into your 3d scene (the way most games work) you will need to find a way to write it into your Java3D scene. There are a few different ways of doing this- I have had some success by writing the text into a graphic and then using the graphic I have just created as a texture on a plane attached to my viewPlatform. I believe there is something clever you can do to write it directly onto the view instead of using geometry in the scene, but I don't recall what...

Similar Messages

  • How create timer for game?

    I want to know how much time player spend in the game.
    For this i want create a timer.
    I thing it must be something like this:
    player come to the game (time 0:00), player plaing for example 22 minutes, gameover game (player spend 22 minutes and 0 sec).
    code:
    import flash.utils.getTimer;
    var gameStartTime:uint;
    var gameTime:uint;
    var gameTimeField:TextField;
    function mainFunction():void
         gameTimeField = new TextField();
         addChild(gameTimeField);
         gameStartTime=getTimer();
         gameTime=0;
         addEventListener(Event.ENTER_FRAME,showTime);
    function showTime(event:Event)
         gameTime=getTimer()-gameStartTime;
         gameTimeField.text="You plaing: "+clockTime(gameTime)+"min";
    function clockTime(ms:int)
         var seconds:int=Math.floor(ms/1000);
         var minutes:int=Math.floor(seconds/60);
         seconds-=minutes*60;
         var timeString:String=minutes+":"+String(seconds+100).substr(1,2);
         return timeString;
    mainFunction();
    Is this correct way?
    If you know how to make code smaller can you please share?
    Maybe exist standart component or something else for this?
    Thank you.

    Thank you guys!
    Just asking how to make timer correct:)
    I thout maybe you know existing standart coder or standart component for it?
    For example i use the same timer for 5 games.. and for every game i need create code..  Is it possible to make code just one time and create something like standart components in Flash IDE ? Or maybe adobe have place where everyone can create components and share whit other? Or its all not possible, and need create the same code again?
    By the way why i dont see my secons here?:
    var gameStartTime:uint;
    var gameTime:uint;
    function mainFunction():void
         gameStartTime=getTimer();
         gameTime=0;
         addEventListener(Event.ENTER_FRAME,showTime);
    function showTime(event:Event)
         gameTime=getTimer()-gameStartTime;
         myText.text="Time: "+clockTime(gameTime);
    function clockTime(ms:int)
         var seconds:int=Math.floor(ms/1000);
         var timeString:String=String(seconds+100).substr(1,2);
    mainFunction();

  • Timer for game program.

    Hello all,
    I am making a game program and I need a way to implement a timer so that it the game will end if the time expires.
    Is there any easy function to help me with this task?

    Thanks for the reply and I just found that class.
    Thanks

  • Need countdown timer for game

    i'm making a shooting game i need a timer that counts down
    and then when it gets to 0 it goes to a certain frame. This is the
    code i'm using:
    var seconds:Number=10;
    time_txt.text="";
    function countDown(){
    var time=seconds--;
    time_txt.text=time;
    if(time=0){
    gotoAndStop("lose");
    clearInterval(counter);
    counter=setInterval(countDown, 1000);
    can any one help

    just in case this might help anyone tries to help
    here is the code i'm using for the game:
    stop();
    //Set global highScore variables
    highScore = 0;
    //Set the properties for the game elements
    _root.lastframe = false;
    //Stop bullets
    //See AS for bullet MC for details
    setProperty(_root.crosshair, _visible, true);
    setProperty(_root.bullet, _visible, false);
    //Individual destroyed target images hidden until needed
    setProperty(_root.target1d, _visible, false);
    setProperty(_root.target2d, _visible, false);
    setProperty(_root.target3d, _visible, false);
    //As above. Individual highlighted target images hidden until
    needed
    setProperty(_root.target1Image, _visible, false);
    setProperty(_root.target2Image, _visible, false);
    setProperty(_root.target3Image, _visible, false);
    mouse.hide();
    //hide mouse to use cross-hairs
    //select a target to shoot at random then add that target
    //to the array of selected targets so that it isn't used
    //again in this game.
    //When the number of direct hits against the selected
    //target has been reached. Find another random target.
    //Check whether it exists in the array. If yes, select
    //again. If no, make visible.
    _root.targets = new Array();
    //create array on the main
    //timeline so that it is
    //easily accessed by all MCs
    _root.targets[0] = "target1";
    _root.targets[1] = "target2";
    _root.targets[2] = "target3";
    //3 targets we are using in
    //tutorial
    n = _root.targets.length;
    //get length of array
    ran = random(n);
    //get random number location to select from array
    target = _root.targets[ran];
    //show random array location
    _root.activeTarget = target;
    //create target variable
    setProperty("_root."+target+"Image", _visible, true);
    //show target
    _root.targets.splice(ran, 1);
    //remove the random element
    //from the array. splice
    //the random number found and
    //to the depth of one so only
    //one element is removed.
    var seconds:Number = 10;
    time_txt.text = "";
    function countDown() {
    var time = seconds--;
    time_txt.text = time;
    if (time == -10) {
    gotoAndStop("lose");
    clearInterval(counter);
    counter = setInterval(countDown, 1000);
    any help will be appreciated
    Spud

  • How do I set up an email for face time and Game Center for my child's ipod

    How do I set up an email account for my sons iPod so he can do face time and Game Center with friends?

    I would create a NEW account using these instructions. Make sure you follow the instructions. Many do not and if you do not you will not get the None option. You must use an email address that you have not used with Apple before. You have to do it in your mane if he is not yet 13.
    Creating an iTunes Store, App Store, iBookstore, and Mac App Store account without a credit card
    Then use that account for Settings>FaceTime and Gamecent
    If yo want it can also be used for:
    - Settings>Messages>Send and receive to allow him to Message
    - Settings>iCloud to allow him to have his own calendar and contacts
    Continue to use the common ID for Setting>iTunes and App Stores

  • HT3702 I can not connect to iTunes Store.... & I was charged 3 times for the same game.

    I was charged 3 times for the same game.  I need a refund on them & reimbursement for overcharge fee... 

    I just posted about this.  I see now I'm not the only one.  They are thieves!

  • TS1424 Hello! Tell me, why I paid two times for one game? Stray Souls: Dollhouse Story - Collector's Edition HD, Collector's Edition???

    Hello! Tell me, why I paid two times for one game? Stray Souls: Dollhouse Story - Collector's Edition HD, Collector's Edition???

    Check your purchase history. The second charge may be for unlocking someting in the game or might be in-game items.

  • I was charged two times for the same game

    I was charged two times for the same game...how can I get my money back?  I even was emailed a receipt for them both...no one noticed?  Please help me.

    How to report an issue with Your iTunes Store purchase

  • I don't remember my security answer and it's not my 1st time for using this device,i using this before..but the last time I try to buy some games using iTunes card its saying this is your 1st time using this device so I need to answer the security questio

    i don't remember my security answer and it's not my 1st time for using this device,i using this before..but the last time I try to buy some games using iTunes card its saying this is your 1st time using this device so I need to answer the security questio

    https://expresslane.apple.com/

  • HT201407 i have a old iphone 4 i want to use for games only but my apple id and password is gone i cant find it i have tryed several times and cant get in to phone what can  i do

    i have iphone 4 I wantr to use just for games but I don't have my password or apple id for phone how do I fully restore it

    You go to https://iforgot.apple.com/appleid if you don't remember the ID.
    If you know the ID but not the password, you go to https://iforgot.apple.com and reset it.
    If you can't do either of those, you call Apple and speak to someone in account security.

  • Finalize() method being called multiple times for same object?

    I got a dilly of a pickle here.
    Looks like according to the Tomcat output log file that the finalize method of class User is being called MANY more times than is being constructed.
    Here is the User class:
    package com.db.multi;
    import java.io.*;
    import com.db.ui.*;
    import java.util.*;
    * @author DBriscoe
    public class User implements Serializable {
        private String userName = null;
        private int score = 0;
        private SocketImage img = null;
        private boolean gflag = false;
        private Calendar timeStamp = Calendar.getInstance();
        private static int counter = 0;
        /** Creates a new instance of User */
        public User() { counter++;     
        public User(String userName) {
            this.userName = userName;
            counter++;
        public void setGflag(boolean gflag) {
            this.gflag = gflag;
        public boolean getGflag() {
            return gflag;
        public void setScore(int score) {
            this.score = score;
        public int getScore() {
            return score;
        public void setUserName(String userName) {
            this.userName = userName;
        public String getUserName() {
            return userName;
        public void setImage(SocketImage img) {
            this.img = img;
        public SocketImage getImage() {
            return img;
        public void setTimeStamp(Calendar c) {
            this.timeStamp = c;
        public Calendar getTimeStamp() {
            return this.timeStamp;
        public boolean equals(Object obj) {
            try {
                if (obj instanceof User) {
                    User comp = (User)obj;
                    return comp.getUserName().equals(userName);
                } else {
                    return false;
            } catch (NullPointerException npe) {
                return false;
        public void finalize() {
            if (userName != null && !userName.startsWith("OUTOFDATE"))
                System.out.println("User " + userName + " destroyed. " + counter);
        }As you can see...
    Every time a User object is created, a static counter variable is incremented and then when an object is destroyed it appends the current value of that static member to the Tomcat log file (via System.out.println being executed on server side).
    Below is the log file from an example run in my webapp.
    Dustin
    User Queue Empty, Adding User: com.db.multi.User@1a5af9f
    User Dustin destroyed. 0
    User Dustin destroyed. 0
    User Dustin destroyed. 0
    User Dustin destroyed. 0
    User Dustin destroyed. 0
    USER QUEUE: false
    INSIDE METHOD: false
    AFTER METHOD: false
    User Dustin destroyed. 1
    User Dustin destroyed. 1
    User Dustin destroyed. 1
    User Dustin destroyed. 1
    USER QUEUE: false
    INSIDE METHOD: false
    AFTER METHOD: false
    User Dustin destroyed. 2
    User Dustin destroyed. 2
    User Dustin destroyed. 2
    User Dustin destroyed. 2
    User Dustin destroyed. 2
    User Dustin destroyed. 2
    User Dustin destroyed. 2
    User Dustin destroyed. 2
    USER QUEUE: false
    INSIDE METHOD: false
    AFTER METHOD: false
    User Dustin destroyed. 3
    User Dustin destroyed. 3
    User Dustin destroyed. 3
    User Dustin destroyed. 3
    User Dustin destroyed. 3
    User Dustin destroyed. 3
    User Dustin destroyed. 3
    User Dustin destroyed. 3
    User Dustin destroyed. 3
    USER QUEUE: false
    INSIDE METHOD: false
    AFTER METHOD: false
    User Dustin destroyed. 4
    User Dustin destroyed. 4
    User Dustin destroyed. 4
    User Dustin destroyed. 4
    User Dustin destroyed. 4
    User Dustin destroyed. 4
    User Dustin destroyed. 4
    User Dustin destroyed. 4
    User Dustin destroyed. 4
    USER QUEUE: false
    INSIDE METHOD: false
    AFTER METHOD: false
    User Dustin destroyed. 5
    User Dustin destroyed. 5
    User Dustin destroyed. 5
    User Dustin destroyed. 5
    User Dustin destroyed. 5
    User Dustin destroyed. 5
    User Dustin destroyed. 5
    User Dustin destroyed. 5
    User Dustin destroyed. 5
    USER QUEUE: false
    INSIDE METHOD: false
    AFTER METHOD: false
    User Dustin destroyed. 6
    User Dustin destroyed. 6
    User Dustin destroyed. 6
    User Dustin destroyed. 6
    User Dustin destroyed. 6
    User Dustin destroyed. 6
    User Dustin destroyed. 6
    User Dustin destroyed. 6
    User Dustin destroyed. 6
    User Dustin destroyed. 6
    Joe
    USER QUEUE: false
    INSIDE METHOD: false
    AFTER METHOD: false
    User Dustin pulled from Queue, Game created: Joe
    User Already Placed: Dustin with Joe
    User Dustin destroyed. 7
    User Dustin destroyed. 7
    User Dustin destroyed. 7
    User Dustin destroyed. 7
    User Dustin destroyed. 7
    User Dustin destroyed. 7
    User Dustin destroyed. 7
    User Dustin destroyed. 7
    User Dustin destroyed. 7
    User Dustin destroyed. 7
    INSIDE METHOD: false
    INSIDE METHOD: false
    USER QUEUE: true
    INSIDE METHOD: false
    INSIDE METHOD: false
    User Dustin destroyed. 9
    User Joe destroyed. 9
    User Dustin destroyed. 9
    User Dustin destroyed. 9
    User Dustin destroyed. 9
    User Dustin destroyed. 9
    INSIDE METHOD: true
    INSIDE METHOD: false
    USER QUEUE: true
    INSIDE METHOD: false
    INSIDE METHOD: false
    INSIDE METHOD: true
    INSIDE METHOD: false
    USER QUEUE: true
    INSIDE METHOD: false
    INSIDE METHOD: false
    It really does seem to me like finalize is being called multiple times for the same object.
    That number should incremement for every instantiated User, and finalize can only be called once for each User object.
    I thought this was impossible?
    Any help is appreciated!

    Thanks...
    I am already thinking of ideas to limit the number of threads.
    Unfortunately there are two threads of execution in the servlet handler, one handles requests and the other parses the collection of User objects to check for out of date timestamps, and then eliminates them if they are out of date.
    The collection parsing thread is currently a javax.swing.Timer thread (Bad design I know...) so I believe that I can routinely check for timestamps in another way and fix that problem.
    Just found out too that Tomcat was throwing me a ConcurrentModificationException as well, which may help explain the slew of mysterious behavior from my servlet!
    The Timer thread has to go. I got to think of a better way to routinely weed out User objects from the collection.
    Or perhaps, maybe I can attempt to make it thread safe???
    Eg. make my User collection volatile?
    Any opinions on the best approach are well appreciated.

  • I  was billed four times for $8.98 and I do not  know why

    I logged on to iTunes 9/192013 and had to update my billing info. I updated Netflix and downloaded 2 free game apps. My iTunes account lists no charges.
    However, when I checked my bank statement online I saw that iTunes had billed me four times for $8.98 on 9/1/2013 (listed as pending charges). Today, 9/3/2013 one of those pending chages was paid on 9/2/2013 and the other three were still pending.
    I did not authorize any charges that day.
    How do I contact iTunes billing about this? The phone number on my bank statement only refers me to this website: apple.com/support/cc.
    Why did this happen and how can I get my money back?

    You've checked the purchase history on your account via the Store > View Account menu option on your computer's iTunes, and have you got any auto-renewing subscriptions ?  If you can't find the charge, or don't recognise it, then you can contact iTunes Support via this page : http://www.apple.com/support/itunes/contact/ - click on Contact iTunes Store Support on the right-hand side of the page, then Purchases, Billing & Redemption

  • IPad constantly glitching/freezing/crashing/parts of screen unresponsive - time for a factory reset OR a trip to the Apple store???

    iPad constantly glitching/freezing/crashing/parts of screen unresponsive - time for a factory reset OR a trip to the Apple store???
    My son has nothing but problems with his iPad Mini.  It is less than a year old and it constantly freezes/crashes/glitches and parts of the screen are unresponsive.  This happens while playing games, watching movies, surfing the net etc etc
    The iPad has been in a heavy duty Survivor case from day 1 and has been very well taken care of - so I don't think it's a damage issue
    I have tried numerous resets (just holding the 2 buttons) and have disabled every feature on the iPad that might be causing memory/RAM issues (?)  all to no avail.
    I haven't tried resetting to factory settings as I don't want to lose all the data on the iPad (mostly his game achievements and Minecraft maps that he has worked so hard on!!!)
    SO - any suggestions:
    1) Take it in to the Apple Store - I have never gone to Apple over an issue, is this possibly covered by warranty???
    2) Factory Reset - If I do this can I save all his game achievements/data???
    Cheers,
    Todd

    Try this  - Reset the iPad by holding down on the Sleep and Home buttons at the same time for about 10-15 seconds until the Apple Logo appears - ignore the red slider - let go of the buttons. (This is equivalent to rebooting your computer.) No data/files will be erased. http://support.apple.com/kb/ht1430
    Frozen or unresponsive iPad
    Resolve these most common issues:
        •    Display remains black or blank
        •    Touch screen not responding
        •    Application unexpectedly closes or freezes
    http://www.apple.com/support/ipad/assistant/ipad/
    iPhone, iPad, iPod Touch: Troubleshooting Touchscreen Response
    http://support.apple.com/kb/ts1827
    iPad Frozen, not responding, how to fix
    http://appletoolbox.com/2012/07/ipad-frozen-not-responding-how-to-fix/
    iPad Frozen? How to Force Quit an App, Reset or Restart Your iPad
    http://ipadacademy.com/2010/11/ipad-frozen-how-to-force-quit-an-app-reset-or-res tart-your-ipad
    Black or Blank Screen on iPad or iPhone
    http://appletoolbox.com/2012/10/black-or-blank-screen-on-ipad-or-iphone/
    What to Do When Your iPad Won't Turn On
    http://ipad.about.com/od/iPad_Troubleshooting/ss/What-To-Do-When-Your-Ipad-Wo-No t-Turn-On.htm
    iOS: Not responding or does not turn on
    http://support.apple.com/kb/TS3281
    iPad: Basic troubleshooting
    http://support.apple.com/kb/TS3274
    Not normal. Take it to an Apple Store for evaluation. You're covered by Apple's 1-year warranty.
    Make a Genius Bar Reservation
    http://www.apple.com/retail/geniusbar/
     Cheers, Tom

  • How do I stop getting updates for games through the app store on my macbook?

    I'm continually getting updates for games (also for the usual stuff, but that's fine), is there a way to edit what updates you get? 
    Thanks!

    If you have more than one user account, these instructions must be carried out as an administrator.
    Launch the Console application in any of the following ways:
    ☞ Enter the first few letters of its name into a Spotlight search. Select it in the results (it should be at the top.)
    ☞ In the Finder, select Go ▹ Utilities from the menu bar, or press the key combination shift-command-U. The application is in the folder that opens.
    ☞ Open LaunchPad. Click Utilities, then Console in the icon grid.
    Select "/var/log/install.log" from the file list on the left. If you don't see that list, select
    View ▹ Show Log List
    from the menu bar. Then select the messages from the last installation or update attempt, starting from the time when you initiated it. If you're not sure when that was, start over and note the time. Copy them to the Clipboard (command-C). Paste into a reply to this message (command-V).
    If there are runs of repeated messages, post only one example of each. Don’t post many repetitions of the same message.
    When posting a log extract, be selective. Don't post more than is requested.
    Please do not indiscriminately dump thousands of lines from the log into this discussion.
    Important: Some private information, such as your name, may appear in the log. Edit it out by search-and-replace in a text editor before posting.

  • Is iMac 5K good for games !?

    Hello, I want to ask you  is the new iMac good for video games. By video games I mean games with very good graphics like Far Cry 4, GTA 5, CoD AW, Dying Light and other like them   or I should get a cheeper gaming pc? Please, answer me if you can.

    The only way to play high games with high response times on an IMac is to get an IMac with high end specs and that'll make it a very expensive gaming machine.
    You need to check the sites for the games you play for the nominal (average) hardware specs as well as the higher end hardware specs.
    None of the 21 inch screen IMacs will hack it for high end gaming as their GPUs top out at 1 GB VRAM and the i7 CPUs are NOT the fastest available.
    The only 5K retina iMac is the 27 inch screen model that starts at $2500 U.S.D. and the 27 inch screen models are the only models to get all of the bells and whistles needed like maybe a top of the line i7 CPU(for games the i7 CPU is really needed over the more common i5 CPUs), top of the line GPU (or  see if you can get away with the base (2 GB VRAM GPUs) and faster 7200 RPM hard drives (the 21 inch screen iMacs only come now with laptop standard 5400 RPM hard drives, now) or faster/larger Fusion or SSD/Flash based drives.
    You'll be close to the $3000 mark or more if you go with both the fastest CPU (4.0 Ghz) AND the 4 GB VRAM GPU.
    If you are trying to compare an iMac gaming machine to a cheap PC for gaming, it sounds as if to me you do not have the budget for a $2500 IMac???
    Even the non-retina 27 inch iMacs will set you back, at least $2000 U.S.D. for the higher spec'd. model.
    If you are really considering the cheap PC route (which won't be as cheap as you think for a comparable PC with good gaming hardware specs), maybe just stick to your PC for gaming.
    It seems to me that the budget is not there or realistic for a IMac with the specs you are going to need.
    Good Luck!

Maybe you are looking for

  • Why did my replacement iPod Touch come with iOS 4.3.5?

    My other iPod wasn't working so I got a new one but this one comes with iOS 4.3.5? Why did that happen? And it is slow too, is that from 4.3.5 too? Should I update or no? Cause I had battery issues on 5.1.1 on my old iPod and I don't want that happen

  • Pdf attachments won't open from outlook?

    I have adobe reader version 10.1.6 and for the last few weeks, when I double click on a attachment in outlook nothing happens.  Sometimes after clicking 10 to 20 times it will finally open.  This problem does not exist if I am simply opening a pdf fr

  • Protected videos and iPod classic

    Hello, I recently bought a new iPod Classic (7th gen, 160 GB) to replace a stolen 120GB iPod.  When I tried to sync all of my movies to the iPod, I got the 'can't be played on this iPod' message.  They are all standard definition movies, and they syn

  • Non stock item requisition from the order

    Dear all, Material is not available in stores,i have enter the item category as N in the maintenance order ,system created the Purchase requisition & reservation of same material which will be further converted to Purchase order. When material goods

  • Font size adjustment

    I installed Photoshop Elements 11 on my PC with no problems.  However, once I use the program the font size on all screens, e.g., Organizer and Editor, is very small.  I don't know where to make the adjustment so I can view the program in at least 12