Jitter for transition into block

This commit is contained in:
Mononaut 2021-03-31 19:27:58 -06:00
parent f079c51ccf
commit f701af6572
2 changed files with 7 additions and 5 deletions

View File

@ -99,6 +99,7 @@ export default class TxBlockScene extends TxMondrianPoolScene {
}, },
duration: this.laidOut ? 1000 : 1500, duration: this.laidOut ? 1000 : 1500,
delay: 0, delay: 0,
jitter: this.laidOut ? 0 : 1000,
state: 'block' state: 'block'
}) })
} }

View File

@ -2,9 +2,9 @@ import TxSprite from './TxSprite.js'
// converts from this class's update format to TxSprite's update format // converts from this class's update format to TxSprite's update format
// now, id, value, layer, position, size, palette, color, alpha, duration, adjust // now, id, value, layer, position, size, palette, color, alpha, duration, adjust
function toSpriteUpdate(display, duration, start, adjust) { function toSpriteUpdate(display, duration, delay, start, adjust) {
return { return {
now: start || Date.now(), now: (start || Date.now()) + (delay || 0),
duration: duration, duration: duration,
...display, ...display,
...(display.color != null ? { palette: display.color.palette, color: display.color.index, alpha: display.color.alpha } : { color: null }), ...(display.color != null ? { palette: display.color.palette, color: display.color.index, alpha: display.color.alpha } : { color: null }),
@ -37,17 +37,18 @@ export default class TxView {
delay: for queued transitions, how long to wait after current transition delay: for queued transitions, how long to wait after current transition
completes to start. completes to start.
*/ */
update ({ display, duration, delay, state, start, adjust }) { update ({ display, duration, delay, jitter, state, start, adjust }) {
this.state = state this.state = state
if (jitter) delay += (Math.random() * jitter)
if (!this.initialised || !this.sprite) { if (!this.initialised || !this.sprite) {
this.initialised = true this.initialised = true
const update = toSpriteUpdate(display, duration, start) const update = toSpriteUpdate(display, duration, delay, start)
update.id = this.id update.id = this.id
update.value = this.value update.value = this.value
this.sprite = new TxSprite(update, this.vertexArray) this.sprite = new TxSprite(update, this.vertexArray)
} else { } else {
const update = toSpriteUpdate(display, duration, start, adjust) const update = toSpriteUpdate(display, duration, delay, start, adjust)
this.sprite.update(update) this.sprite.update(update)
} }
} }