Allow for stacked easings through recalculation of the change on each easing value update

feature/coffeescript
Sven Slootweg 10 years ago
parent 29aab13dcd
commit b594fe3e05

@ -872,6 +872,7 @@
this.type = type; this.type = type;
this.infinite = infinite; this.infinite = infinite;
this.start = start; this.start = start;
this.end = end;
this.start_frame = start_frame; this.start_frame = start_frame;
this.duration = duration; this.duration = duration;
this.invert_repeat = invert_repeat; this.invert_repeat = invert_repeat;
@ -903,7 +904,7 @@
this.updateValue = __bind(this.updateValue, this); this.updateValue = __bind(this.updateValue, this);
this.goToNext = __bind(this.goToNext, this); this.goToNext = __bind(this.goToNext, this);
this.func = this[this.type]; this.func = this[this.type];
this.change = end - this.start; this.change = this.end - this.start;
this.value = this.start; this.value = this.start;
this.last_updated = this.start_frame; this.last_updated = this.start_frame;
this.finished = false; this.finished = false;
@ -925,6 +926,7 @@
}; };
Ease.prototype.updateValue = function(current_frame) { Ease.prototype.updateValue = function(current_frame) {
this.change = this.end - this.start;
if (current_frame >= this.start_frame + this.duration) { if (current_frame >= this.start_frame + this.duration) {
if (this.infinite) { if (this.infinite) {
this.start_frame = current_frame; this.start_frame = current_frame;

@ -20,8 +20,8 @@ $(->
cursor.sprite = engine.getSprite("cursor") cursor.sprite = engine.getSprite("cursor")
cursor.onClickGlobal = (event) -> cursor.onClickGlobal = (event) ->
@x = @engine.ease.quadInOut(@x, event.x - 41, 15) @x = @engine.ease.quadInOut(@x, event.x - 41, 35)
@y = @engine.ease.quadInOut(@y, event.y - 41, 15) @y = @engine.ease.quadInOut(@y, event.y - 41, 35)
cursor.onStep = -> cursor.onStep = ->
return true return true

@ -15,8 +15,8 @@
cursor = engine.createObject("cursor"); cursor = engine.createObject("cursor");
cursor.sprite = engine.getSprite("cursor"); cursor.sprite = engine.getSprite("cursor");
cursor.onClickGlobal = function(event) { cursor.onClickGlobal = function(event) {
this.x = this.engine.ease.quadInOut(this.x, event.x - 41, 15); this.x = this.engine.ease.quadInOut(this.x, event.x - 41, 35);
return this.y = this.engine.ease.quadInOut(this.y, event.y - 41, 15); return this.y = this.engine.ease.quadInOut(this.y, event.y - 41, 35);
}; };
cursor.onStep = function() { cursor.onStep = function() {
return true; return true;

@ -86,9 +86,9 @@ Engine::ease =
class Ease class Ease
# Port based on https://github.com/jimjeffers/Easie. I don't think this qualifies as a "bad thing" :) # Port based on https://github.com/jimjeffers/Easie. I don't think this qualifies as a "bad thing" :)
constructor: (@engine, @type, @infinite, @start, end, @start_frame, @duration, @invert_repeat, @next, @params...) -> constructor: (@engine, @type, @infinite, @start, @end, @start_frame, @duration, @invert_repeat, @next, @params...) ->
@func = this[@type] @func = this[@type]
@change = end - @start @change = @end - @start
@value = @start @value = @start
@last_updated = @start_frame @last_updated = @start_frame
@finished = false @finished = false
@ -113,6 +113,12 @@ class Ease
@next = @next.next @next = @next.next
updateValue: (current_frame) => updateValue: (current_frame) =>
# We recalculate here, to deal with 'stacked' easings. If we don't do this, letting multiple
# easings operate on each other will result in the final value being different from 'end',
# because the change was calculated once based on the value of the previous easing *at that
# moment*, rather than the actual value.
@change = @end - @start
if current_frame >= @start_frame + @duration if current_frame >= @start_frame + @duration
if @infinite if @infinite
@start_frame = current_frame @start_frame = current_frame

Loading…
Cancel
Save