Skip to content

Commit f618139

Browse files
committed
started adding animation curves other than linear.
1 parent 2b8fbc2 commit f618139

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

taptapir.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,14 @@ function set_fullscreen(value) {
262262
}
263263
}
264264

265+
curves = {
266+
'linear' : (a, b, t) => {
267+
return lerp(a, b, t)},
268+
269+
'out_expo' : (a, b, t) => {
270+
return lerp(a, b, t*t)}
271+
}
272+
265273
ASSETS_FOLDER = ''
266274
TAPTAPIR_TEXTURES = {}
267275
entities = []
@@ -697,7 +705,7 @@ class Entity {
697705
}
698706
}
699707

700-
animate(variable_name, target_value, duration=.1) {
708+
animate(variable_name, target_value, duration=.1, curve=curves.linear) {
701709
// print('animate:', variable_name, target_value)
702710
if (!this.enabled) {return false}
703711
if (duration <= 1/60) {
@@ -721,7 +729,8 @@ class Entity {
721729
if (!entity.enabled) {
722730
return false}
723731
var t = i / duration / 60
724-
entity[variable_name] = lerp(start_value, target_value, t)
732+
// entity[variable_name] = lerp(start_value, target_value, t)
733+
entity[variable_name] = curve(start_value, target_value, t)
725734
},
726735
1000*i/60
727736
)
@@ -977,13 +986,13 @@ function goto_scene(scene_name, fade=True) {
977986

978987
class HealthBar extends Entity {
979988
constructor(options=false) {
980-
let settings = {min:0, max:100, color:'#222222', bar_color:'bb0505', scale:[.8,.05], roundness:.25}
989+
let settings = {min:0, max:100, color:'#222222', bar_color:'bb0505', scale:[.8,.05], roundness:.25, text_color:'#dddddd', text_size:2}
981990
for (const [key, value] of Object.entries(options)) {
982991
settings[key] = value
983992
}
984993
super(settings)
985994
this.bar = new Entity({parent:this, origin:[-.5,0], x:-.5, roundness:.25, scale_x:.25, color:settings['bar_color']})
986-
this.text_entity = new Entity({parent:this, text:'hii', text_color:'#dddddd', color:color.clear, text_origin:[0,0], text_size:2})
995+
this.text_entity = new Entity({parent:this, text:'hii', text_color:settings['text_color'], color:color.clear, text_origin:[0,0], text_size:settings['text_size']})
987996
this.value = settings['max']
988997
}
989998

0 commit comments

Comments
 (0)