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();

Similar Messages

  • How create uninstaller for my program with AppBuilder?

    Hello All!
    Tell please how I can create uninstaller for my executable build?
    I can create the INSTALLER, but I have no opportunity to create the UNinstaller.
    I tried to contact with my tech support in Moscow, but I do not receive the answer for three days!
    I wished to find the answer to the question on a site labview.ru, but at this forum is only spam messages! They do not have a moderator there!
    Please help me!
    Best regards

    Hi,
    The LabVIEW Installer Builder uses the Microsoft Installer system (MSI) to create Installers. As such it registers an installation with the Control Panel->Add & Remove Software component and this is the place Microsoft wants users to uninstall and/or manage already installed applications from. As such it has become very common nowadays and most people do expect to uninstall their software from there.
    Benjamin R.
    R&D Software Development Manager
    http://www.fluigent.com/

  • How Does EAX For Games W

    I am afraid that I've never been able to figure out how to configure my EAX Console to ensure that the EAX is working in my gaqmes. For example, in Far Cry, you can enable hardware mixing and, after that, EAX 2. If I enable these, what do I set in the EAX Console? Enable Audio Effects? If so, what audio effect? You use to be able to select EAX Games under special effects, but that option isn't there unless I import it.
    How do I tell what game uses what setting? Other games I want to ensure I have the proper setup for are Half Life 2, Call Of Duty, Medal of Honor, Halo.
    Clarification of the exact procedure would be most welcome.

    Foomobile,
    For games, with this card, you don't need to set anything up except EAX in the game itself. Just choose an EAX option in the game and that's all you need to do. You don't need to adjust anything in EAX console.
    You may want to update to the latest drivers aswell, as they add extra EAX support (EAX 4.0).
    Cat

  • How create URL for see my folio on the web content viewer ?

    Hello,
    I try to create URL for see my folio on the web content viewer but nothing Work
    i have this informations :
    my applicationName
    my accountID
    my publication Name
    and my articleName (even if for this i'm not sure)
    All my articles are free, my folio is published...
    For information my folio is in PDF format with the resolution 1024x768
    Have you one idea why it's doesn't work ?
    Thanks for yours answers

    Rather than cobbling together the individual parts of the URL, create a development app with social sharing enabled and at least one article set to free. When you share the article of the published folio, you'll see your web viewer URL.

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

  • 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 create synonym for more than one user

    Hi,
    In a DB I have more than one schema. For example:
    1) User1 has these tables:
    Menu
    Employes
    Zipcode
    Billing etc..
    2) User2 has only the a personalized table Menu
    3) User3 has only the a personalized table Menu
    How can enable User2, User3 and other to use the tables Employes, Zipcode, Billing etc. of schema User1 ?
    I think with synonyms. Can You help to write a script in order to create this ?
    I hope in Your Help.
    Thank You and Best Regards.
    Gaetano

    Hi Gaetano,
    If I understand your requirement correctly User2, User3 and other users should be able to access tables owned by User1. If that's the case, synonyms won't help at all.
    Read up any English dictionary and you'll understand what a synonym is.
    What you need to do (as User1) is: GRANT the appropriate privilege (SELECT, UPDATE...) on the tables to the other users.
    Oh, btw: what is a 'personalized table Menu'? I never heard that.
    Regards,
    Guido

  • Create timer for my vi

    The portion of my project I'm currently working on requires to keep the time in between iteration of a for loop.
    I want to be able to have a "time keeper" when I start the loop (in an event structure) to be shown in the front panel.
    And also how do I get the "start time" of each iteration as there will be time delay ie wait time which is controlled by user assuming that there is no/negligible time in the processing?
    And finally how do I make the event structure stop automatically after all the iterations are completed (for loop)?
    Thank you.
    Attached is the simplified vi.
    Attachments:
    Timer.jpg ‏45 KB

    Hi,
    First of all, replace the Wait function with a Wait until ms multiple function. This will give a more reproducible timing.
    As to the event case ending after the iterations are done, I think this is automatically implied by your code. As soon as the code within the event case has executed, the event case is finished (unless it's in a loop, when it might be called again depending on user actions....).
    You can also read out the current ms counter at the start of each loop to get the real loop start time if you want. Additionally, getting one at the end of the loop will enable you to find out approximately how long each loop takes. If this is close to, or more than your wait interval, you'll certainly have problems with your timing.
    Hope this helps
    Shane.
    Using LV 6.1 and 8.2.1 on W2k (SP4) and WXP (SP2)

  • How create iview  for a bw query in portal

    How to create a iview for a BW Query.
    Using a Standard templete in WAD integrated a BW Query to a templete in WAD.
    Now i want to create a iview for that templete.
    In Portal>Portal Content>Create Iveiw
    It is showing me options
    IVIEW TEMPLETE
    PORTAL COMPONENT
    WEB DYBPRO
    Please update me step by step procedure on how to create a iview for a bw query in portal
    Thanks

    Hi
    Integrate EP to BI
    1. You have to create a BW system in portal.
    2. create a SAP BW Report iView from the iview templates available
    3. specify the query string in the iview properties
    Check out the links for the procedure
    http://help.sap.com/saphelp_nw04/helpdata/en/6e/325545c62f674e91caee825f308abf/frameset.htm
    http://help.sap.com/saphelp_nw04/helpdata/en/33/39fa40ee14f26fe10000000a1550b0/frameset.htm
    check the pdf below for step by step procedure to integrate ep and bi
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/b0a5216a-349c-2a10-9baf-9d4797349f6a
    check this blog
    The Cloak and Dagger about Portal and BI Connectivity
    Cheers!!
    SJ

  • 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

  • How Create XML for Purcase Order

    Dea all,
    Please advise how to create standard SAP XML for Purchase Order .
    In customizing (WE20) we have set the partner profile, and the PO creates an IDOC on the system.
    Now what should be done to convert it to XML , and where is the definition of the destination for sending the XML file?
    Thanks,
    Moshe

    Various tools are available generate an XML document from a DTD.
    http://www.eclipse.org/webtools/community/tutorials/XMLWizards/XMLWizards.html
    http://www.altova.com/products/xmlspy/dtd_editor.html
    http://www.stylusstudio.com/xml_generator.html

  • How much time for video on 60D?

    Very new here, just bought first Canon 60D, to do short docs that I've done on DV and HD big cameras. Manual says 44 min for either 8GB card or 16GB card. Is it the same for 32GB card?
    Solved!
    Go to Solution.

    Incidentally... this is actually a limitation of the filesystem and not the camera.  The SD cards are formatted using a FAT32 filesystem (same FAT32 used in MS-DOS) because virtually every computer currently in use can read FAT32 without requiring anything special.  
    FAT32, because of the way it works, can not allow any 'single' file to exceed 4 GB.  If you need something bigger, you have to break it into chunks that are all smaller than the limit.  This is true of everything that uses FAT32.
    The good news is because they use this and it's an entrenched standard, everyone can read the data off the card without having to install any special drivers.  Simplicity is the advantage... but the 4GB chunk-size limit is the trade-off.
    Tim Campbell
    5D II, 5D III, 60Da

  • How create SQL for Cross tab in template

    Hi,
    I have been starting to build data templates using SQL to select the data I require. I noticed in the word template-building tool there is an option to create cross tab table. I have tried looking at the standard documentation. I have been unable to work out how I should structure the SQL in my data template to allow me to create a cross tab table in the template?
    Thanks,
    Mark

    Post Author: SunilKanta
    CA Forum: General
    Yes, I had done exactly the same but when tried to display the subreport in new page, some portion of the cross tab is displayed. The page width is not increased proportionately.
    i have passed that sub report in footer of main report.
    But when i overlap this sub report with other cross tabs already present in the main report i can see full width view of sub report.

  • Cannot create accoubt for game center

    Well I recently updated my iPod to 4.2.1 because I wanted game center
    I had a few problems updating but they are now sorted
    After the clean restore , before any restoring my settings or other things
    I tried to make a game center account but after a few minutes after clicking create account, it just kept loading and then showed the error message "Game center account services are currently unavailable please try again later"
    I then put all my settings and apps back on to my iPod but it would still not work
    I waited 1 day and no luck
    When I try to sign in to game center with my iTunes account , it starts loading and says unable to contact server
    Any help would be appreciated. Thanks
    P.S I am not jailbroken so that is not the problem and my internet connection is fine i can view appstore and safari

    Closed. Saw it in the news that there was an issue with the server.

  • How much time for Time Machine's first backup?

    Hello,
    I recently bought a 2TB external hard disk. I partitioned into one disk of 500GB (for storage), and one disk of 1.5TB (for a backup with Time Machine).
    It's connected with the Firewire 800 port of my Macbook Pro mid-2010.
    I know the first backup is slow, but after 30 hours, it has only backed up 67GB, over the 270GB it has to backup.
    I find this very very slow, even for a first backup! Is it normal?
    Does it slow the backup if I use my computer in the mean time?
    Does it slow the backup to have partitioned my external hard disk?
    I already took some folders off the backup, deactivated Spotlight on the external disk, all I found on the web! But it's not going faster...!
    Thank you a lot for your experiences / advices.

    If you're doing a full backup (rather than an incremental backup), you'll have to copy 730 GB of files. If you only have 2 hours, that's 375 Gb/ hour or 106 Mb/ s, which is going to be more than a low-end NAS is going to be able to handle. If you have a 5 hour window, you'd be talking about 41 Mb/s, which is right about the disk I/O a low-end NAS.
    At a minimum, you have to have enough disk bandwidth to handle the backup in your time window. In calculating your available bandwidth, make sure you account for the bandwidth other operations are using (i.e. if you are backing up to the same set of disks your database is running on).
    Justin
    Distributed Database Consulting, Inc.
    http://www.ddbcinc.com/askDDBC

Maybe you are looking for