From 24c6e785a120a91b343801a023c00357b2d4d4f4 Mon Sep 17 00:00:00 2001 From: Sven Slootweg Date: Thu, 8 May 2014 23:59:21 +0200 Subject: [PATCH] Move shimmer effect to an easing function, and fix circInOut easing bug --- compiled/radium.js | 2 +- gemswap/core.coffee | 40 +-------------------------------------- gemswap/gemswap.js | 37 +----------------------------------- radium/engine.ease.coffee | 2 +- 4 files changed, 4 insertions(+), 77 deletions(-) diff --git a/compiled/radium.js b/compiled/radium.js index d7ccf42..83c2372 100644 --- a/compiled/radium.js +++ b/compiled/radium.js @@ -831,7 +831,7 @@ return -this.change / 2 * (Math.sqrt(1 - time * time) - 1) + this.start; } else { time = time - 2; - return this.change / 2 * (Math.sqrt(1 - time * time) + 1) + this.begin; + return this.change / 2 * (Math.sqrt(1 - time * time) + 1) + this.start; } }; diff --git a/gemswap/core.coffee b/gemswap/core.coffee index a00385c..2546146 100644 --- a/gemswap/core.coffee +++ b/gemswap/core.coffee @@ -58,48 +58,11 @@ $(-> diamond.draw_sprite = false diamond.onCreate = -> - ### - @fade_step = 0.045 - @fade_current_step = @fade_step @fade_value = 0 - @fade_decay_current = 9999 # Disable by default - @fade_decay_max = 8 - ### - @fade_value = 0 - - @shimmer_step = @engine.random.number(0.003, 0.007, 0.0005) * Math.random() - @shimmer_current_step = @shimmer_step - @shimmer_value = 0 - + @shimmer_value = @engine.ease.circInOut(0, 0.8, engine.random.number(200, 350), null, true, true) @gem_type = @engine.random.pick("diamond", "yellow", "blue") diamond.onStep = -> - ### - if @fade_decay_current < Math.pow(2, @fade_decay_max) - @fade_value += @fade_current_step - - max = 1.5 / @fade_decay_current - - if @fade_value > Math.min(max, 1) - @fade_value = Math.min(max, 1) - @fade_current_step = -@fade_step - - if @fade_value <= 0 - @fade_value = 0 - @fade_decay_current *= 1.5 - @fade_current_step = @fade_step - ### - - @shimmer_value += @shimmer_current_step - - if @shimmer_value > 0.7 - @shimmer_value = 0.7 - @shimmer_current_step = -@shimmer_step - - if @shimmer_value < 0 - @shimmer_value = 0 - @shimmer_current_step = @shimmer_step - return true diamond.onDraw = -> @@ -114,7 +77,6 @@ $(-> }) diamond.onMouseOver = -> - #@fade_decay_current = 1 @fade_value = @engine.ease.circOut(0, 1, 10, @engine.ease.bounceOut(1, 0, 35)) cursor = @engine.getObject("cursor").getInstances()[0] diff --git a/gemswap/gemswap.js b/gemswap/gemswap.js index 9fbc1f6..f7cba29 100644 --- a/gemswap/gemswap.js +++ b/gemswap/gemswap.js @@ -41,46 +41,11 @@ diamond.sprite = engine.getSprite("diamond"); diamond.draw_sprite = false; diamond.onCreate = function() { - - /* - @fade_step = 0.045 - @fade_current_step = @fade_step - @fade_value = 0 - @fade_decay_current = 9999 # Disable by default - @fade_decay_max = 8 - */ this.fade_value = 0; - this.shimmer_step = this.engine.random.number(0.003, 0.007, 0.0005) * Math.random(); - this.shimmer_current_step = this.shimmer_step; - this.shimmer_value = 0; + this.shimmer_value = this.engine.ease.circInOut(0, 0.8, engine.random.number(200, 350), null, true, true); return this.gem_type = this.engine.random.pick("diamond", "yellow", "blue"); }; diamond.onStep = function() { - - /* - if @fade_decay_current < Math.pow(2, @fade_decay_max) - @fade_value += @fade_current_step - - max = 1.5 / @fade_decay_current - - if @fade_value > Math.min(max, 1) - @fade_value = Math.min(max, 1) - @fade_current_step = -@fade_step - - if @fade_value <= 0 - @fade_value = 0 - @fade_decay_current *= 1.5 - @fade_current_step = @fade_step - */ - this.shimmer_value += this.shimmer_current_step; - if (this.shimmer_value > 0.7) { - this.shimmer_value = 0.7; - this.shimmer_current_step = -this.shimmer_step; - } - if (this.shimmer_value < 0) { - this.shimmer_value = 0; - this.shimmer_current_step = this.shimmer_step; - } return true; }; diamond.onDraw = function() { diff --git a/radium/engine.ease.coffee b/radium/engine.ease.coffee index 71ada8a..1b991dc 100644 --- a/radium/engine.ease.coffee +++ b/radium/engine.ease.coffee @@ -196,4 +196,4 @@ class Ease return -@change / 2 * (Math.sqrt(1 - time * time) - 1) + @start else time = time - 2 - return @change / 2 * (Math.sqrt(1 - time * time) + 1) + @begin + return @change / 2 * (Math.sqrt(1 - time * time) + 1) + @start