diff --git a/source/scripts/engine.js b/source/scripts/engine.js index 1846dfd..4f1d42d 100644 --- a/source/scripts/engine.js +++ b/source/scripts/engine.js @@ -124,6 +124,7 @@ var Window = { } }; + var Color = { white: [255,255,255,255], blue: [84,110,255,255], @@ -311,7 +312,14 @@ var timer = { } var t = clone(this); - t.id = make_timer(this.guardfn.bind(t,fn), secs, obj); + t.callback = fn; + var guardfn = function() { + if (typeof t.callback === 'function') + t.callback(); + else + Log.warn("Timer trying to execute without a function."); + }; + t.id = make_timer(guardfn, secs, obj); return t; }, @@ -336,8 +344,40 @@ var timer = { kill() { cmd(27, this.id); }, set time(x) { cmd(28, this.id, x); }, get time() { return cmd(29, this.id); }, + get pct() { return this.remain / this.time; }, }; +var Tween = { + default: { + ease: "inout", /* easing at end and beginning of tween */ + loop: "restart", /* none, restart, yoyo, increment */ + time: 1, /* seconds to do */ + }, + + start(target, start, end, options) + { + var defn = Object.create(this.default); + Object.apply(defn, options); + + var newtimer = timer.make(null, defn.time, null, true); + newtimer.pause(); + + var tween_fn = function() { + Log.warn(newtimer.pct); + }; + timer.callback = tween_fn; + timer.callback(); + timer.start(); + }, + + lerp(s, e, t) + { + t = Math.clamp(t,0,1); + return ((e - s) * t) + s; + }, +}; + + var animation = { time: 0, loop: false, diff --git a/source/shaders/slice9_f.glsl b/source/shaders/slice9_f.glsl index eb63808..d6524a2 100644 --- a/source/shaders/slice9_f.glsl +++ b/source/shaders/slice9_f.glsl @@ -32,6 +32,6 @@ uv9slice(vec2 uv, vec2 s, vec4 b) void main() { - uv = uv9slice(uv, scale, border); + vec2 nuv = uv9slice(uv, scale, border); color = fcolor * texture(image, uv); } diff --git a/source/shaders/slice9_v.glsl b/source/shaders/slice9_v.glsl index 3ce5ca3..0e18f8c 100644 --- a/source/shaders/slice9_v.glsl +++ b/source/shaders/slice9_v.glsl @@ -1,7 +1,7 @@ #version 330 core layout (location = 0) in vec2 vert; -layout (location = 1) in vec2 uv; +layout (location = 1) in vec2 vuv; layout (location = 2) in vec4 vborder; layout (location = 3) in vec2 vscale; layout (location = 4) in vec4 vcolor; @@ -17,7 +17,7 @@ void main() { gl_Position = projection * vec4(vert, 0.0, 1.0); - uv = vert; + uv = vuv; border = vborder; scale = vscale; fcolor = vcolor;