Hot answers tagged

10 votes
Accepted

Converting time of day into a smooth day/night variable?

tl;dr Func 1 on Wolfram Alpha: 1 - 2 * |(x mod 2) - 1| Or in your specific case: ...
user avatar
  • 10.5k
7 votes
Accepted

Creating a countdown Timer in Unity

Alternatively, you could use System.Timers.Timer which is probably the most performant of any solution. The following example shows a countdown for 100 seconds. ...
user avatar
  • 2,041
6 votes
Accepted

How to PRECISELY measure execution time of a code?

For the kind of micro-optimisation that you are trying to do, nothing will beat real-life usage patterns, with your algorithm embedded in a real program, consuming and producing real data. There are ...
user avatar
  • 14.6k
5 votes
Accepted

Good techniques for syncing gameplay actions to specific animation timings?

For synchronisation, you need to decide who (your code, animations, or neither) is the timing authority—the "beat" that everyone else "dances" to. Different arrangements suit different games: ...
user avatar
  • 13.3k
5 votes

How should I implement a timer in a strategy game?

I'm inclined to assign this task to the server for security and integrity reasons, but i'm not sure on the way i can accomplish that. Yes, definitely; never trust clients. Clients sometimes "predict" ...
user avatar
  • 3,634
5 votes
Accepted

Score over time

You can do this with a timer like this: In your Create event (or where you want to start your counting): alarm[0] = 1; Then in your Alarm 0 event: ...
user avatar
  • 166
5 votes
Accepted

How do I blink a sprite a few times before it disappears?

It appears you want Blink to be executed as a coroutine. But you are executing it directly. If you call an IEnumerator method directly, you receive an ...
user avatar
  • 112k
4 votes

How to have an event occur after x seconds?

There's no magic way to do this in MonoGame that I know of. The basic idea is fairly simple though; create a variable to keep track of the delay and when it gets to zero fire your method. The ...
user avatar
4 votes

synchronizing client-server actions

The short of it is that your game design and art both need to be built around the realities of networked play. When the user clicks, they should not immediately attack. Instead, the animation/effects ...
user avatar
4 votes

I want to delay 3 sec to load next level after the collision in C#

You are destroying the GameObject on which this script is running as soon as it collides with an enemy. (Destroy (gameObject);) That means it can't wait 3 seconds ...
user avatar
  • 115k
4 votes

Finding average input value over time in seconds

Expanding on Stormwind's lead, I'd be curious whether your application needs a windowed average with equal weights per unit of time, or if an exponential moving average may suffice. The latter is very ...
user avatar
  • 115k
4 votes
Accepted

Is Time.deltaTime different on various devices?

On some platforms the game actually starts running before the splash screen is gone. So this may give the illusion of a defective timer if you test it right at the start. Another issue on slow ...
user avatar
4 votes
Accepted

Saving total play time could be fine?

Floating point precision is unlikely to be the problem here. Since you're not trying to coordinate simultaneous use, but just determine which of two sequential sessions came earlier/later, you'll ...
user avatar
  • 115k
3 votes

Creating a countdown Timer in Unity

Coroutines are you friend I think on this one... http://docs.unity3d.com/Manual/Coroutines.html Here is an example: ...
user avatar
3 votes
Accepted

In Unity, how do I set up a delay before an action?

You could create a variable for example called timer of type float and make it equal to the amount of seconds you would like to wait, then in the ...
user avatar
  • 1,217
3 votes

How to structure a game that continue even when closed?

The proper way to do this is, when you exit the game, save the current time somewhere in your project. My .Net skills are awful, but a quick google search suggests ...
user avatar
  • 4,238
3 votes

Time based events separate from the game loop

Time elapsed events are not separate from the game loop but are controlled from the game loop. The easiest way to achieve the effect is to have a floating-point value that represents the number of ...
user avatar
  • 1,986
3 votes
Accepted

Time based events separate from the game loop

This is a very wide question, and difficult to answer specifically, so I will be general instead: Any "over time" effects will still be based on your game loop, but have their own "tick" of time they ...
user avatar
  • 2,565
3 votes

Timer as part of a condition

Myself, I'd recommend separating the jobs of reading from the sensor, running your timer, and coordinating your scene transitions. This way each script can do one simple job, so you don't end up with ...
user avatar
  • 115k
3 votes
Accepted

Timer breaks after changing scenes

Time.time returns the number of seconds since the start of the game. "Start of the game" refers to the moment the game was launched, not the moment the current ...
user avatar
3 votes

How do I blink a sprite a few times before it disappears?

When you call Blink you are discarding its return value: Blink(itemClone); You do not want to do that. I believe you want to ...
user avatar
  • 18.9k
3 votes
Accepted

Phaser 3 - How to trigger an event every 1 second?

In your scene's update method you receive both the current timestamp, and the delta since the last update call (see https://photonstorm.github.io/phaser3-docs/Phaser.Scene.html#update__anchor) You ...
user avatar
2 votes
Accepted

How do I draw text once a countdown ends?

The simple way to do this is to have two objects and then use instance_change() two swap into the next object when the countdown finishes. Example: ...
user avatar
2 votes
Accepted

Creating A TickRate Class

The approach by Narrateur du chaos is commonly called the delta-t approach. But there is also another approach, the game-tick approach. In this approach you keep track of how long the game is running ...
user avatar
  • 112k
2 votes

Timer.schedule(task, 0, 100) never fires

The scheduleTask function's source suggests that it expects the input in terms of seconds instead of milliseconds. ...
user avatar
  • 935
2 votes

Can't consistently add to TimeSpan for Unity Game

My output is always 00:00:01. Look at how you initialize your values, though: timer will default to zero t will initialize ...
user avatar
  • 726
2 votes
Accepted

Game Maker Studio - how do I disable mouse click for a duration of time?

I would do this if(mouse_check_button_pressed(mb_left) && click) { click = false; alarm[0] = 30; } Then in your alarm[0] event say ...
user avatar
  • 146
2 votes

In Unity, how do I set up a delay before an action?

Multiple choices, but you will have to use Coroutine sometimes, so try to figure out why its not working here. My tips : careful to not call StartCoroutine in Update() without protection. Exemple: ...
user avatar
2 votes
Accepted

Creating a GUI Countdown Timer Unity5

There are basically two ways to access the GUIText. One way would be a public reference in the class or, like you already did, GetComponent. The advantage of using a public reference is, that you do ...
user avatar

Only top scored, non community-wiki answers of a minimum length are eligible