Jump to content

Making Countdown Timer for game starting


vazono4ok
 Share

Recommended Posts

Hello.
I'm newbie to Phaser.

I need to create countdown timer for game starting. It should looks like counting from 3 to 1, then the game should be started. I'll be using images as a numbers.

i Have  the following game state's

  1. Boot
  2. StartMenu
  3. Game
  4. GameOver

I thought that i need to create state "PreGame", where will be countdown timer code. Is this correct? And help me pls with writing timer using images. 

Could someone help me with this.

Link to comment
Share on other sites

Welcome!

You can modify/steal from the examples. Here is an example for generic preloader:
http://phaser.io/examples/v2/loader/load-events


I created a small pen to illustrate some steps towards a countdown for you:
http://codepen.io/Fenchurchh/pen/PZKdWa

 

If you want to render the countdown using images you might want to check out the sprite or text examples (http://phaser.io/examples/v2/category/text)

 

 

Link to comment
Share on other sites

42 minutes ago, P.Uri.Tanner said:

Welcome!

You can modify/steal from the examples. Here is an example for generic preloader:
http://phaser.io/examples/v2/loader/load-events


I created a small pen to illustrate some steps towards a countdown for you:
http://codepen.io/Fenchurchh/pen/PZKdWa

 

If you want to render the countdown using images you might want to check out the sprite or text examples (http://phaser.io/examples/v2/category/text)

 

 

Thnx for your response 
i've already written the counter, but could i create state e.g. "PreGame" where will be the counter and onComplete i'll start my main game state or there were other possibilities in Phaser to create countdown in the same game state?

Link to comment
Share on other sites

Exactly as you said! 

game.state.add('countdownState', {...} ) // your countdown
game.state.add('game', {...}) // your gamestate

// start the countdown 
game.state.start('countdownState')

// after your countdown completes
game.state.start('game')

 

For a small use case you could just wrap the render and update functions to only render the countdown XOR the game. 

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...