Skip to main content
Clarified intention.
Source Link
Anko
  • 13.4k
  • 10
  • 55
  • 82

Simplest implementation of blinkingThe simplest way to get such an effect is to literally blink the sprite: Just don't draw it half the time.

var frequency = 200;
if (! blinking || Math.floor(Date.now() / frequency) % 2) {
    ctx.drawImage(...);
}

So theThe idea is that if you setwhen blinking is set to true then it will based on time and frequency, blinking it on and off by just drawing or notthe sprite will flash at the given frequency.

Simplest implementation of blinking:

var frequency = 200;
if (! blinking || Math.floor(Date.now() / frequency) % 2) {
    ctx.drawImage(...);
}

So the idea is that if you set blinking to true then it will based on time and frequency, blinking it on and off by just drawing or not.

The simplest way to get such an effect is to literally blink the sprite: Just don't draw it half the time.

var frequency = 200;
if (! blinking || Math.floor(Date.now() / frequency) % 2) {
    ctx.drawImage(...);
}

The idea is that when blinking is set to true, the sprite will flash at the given frequency.

Source Link

Simplest implementation of blinking:

var frequency = 200;
if (! blinking || Math.floor(Date.now() / frequency) % 2) {
    ctx.drawImage(...);
}

So the idea is that if you set blinking to true then it will based on time and frequency, blinking it on and off by just drawing or not.