Skip to content

Commit 1576509

Browse files
committed
added click animation, which will play when you click a clickable entity. requires 'impact_effect.gif' in the project.
1 parent 3a09e72 commit 1576509

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

taptapir.js

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ LAST_SCENE = null
297297
DEFAULT_FONT = null
298298
TEXT_SIZE_MULTIPLIER = 1
299299

300-
class Entity {
300+
class Entity {
301301
constructor(options=null) {
302302
if (!('type' in options)) {
303303
options['type'] = 'entity'
@@ -347,7 +347,7 @@ class Entity {
347347
options['parent'] = LAST_SCENE
348348
}
349349
else {
350-
this.parent = scene
350+
this.parent = scene
351351
}
352352
if (DEFAULT_FONT) {
353353
this.font = DEFAULT_FONT
@@ -441,7 +441,7 @@ class Entity {
441441
}
442442
else {
443443
this.el.style.visibility = 'hidden'
444-
}
444+
}
445445

446446
this._enabled = value
447447

@@ -1038,7 +1038,7 @@ class StateHandler {
10381038
settings[key] = value
10391039
}
10401040
if (!camera.overlay) {
1041-
camera.overlay = new Entity({parent:camera, name:'overlay', color:color.black, alpha:0, z:-99, scale:[1.1,aspect_ratio*1.1]})
1041+
camera.overlay = new Entity({parent:camera, name:'overlay', color:color.black, alpha:0, z:-99, scale:[1.1,aspect_ratio*1.1]})
10421042
// print('make new overlay')
10431043
}
10441044
this.states = settings['states']
@@ -1148,7 +1148,12 @@ class RainbowSlider extends Entity {
11481148

11491149
update() {
11501150
if (this.active && mouse.left && mouse.hovered_entity === this) {
1151-
this.value = int((mouse.point[0]+.5+(1/this.max)) * this.max)
1151+
if (this.rotation == 0) {
1152+
this.value = int((mouse.point[0]+.5+(1/this.max)) * this.max)
1153+
}
1154+
else if (this.rotation == -90) {
1155+
this.value = int((mouse.point[1]+.5+(1/this.max)) * this.max)
1156+
}
11521157
}
11531158
}
11541159

@@ -1221,6 +1226,10 @@ function _mousedown(event) {
12211226
}
12221227
document.addEventListener('pointerdown', _mousedown)
12231228

1229+
const click_animation = new Entity({'parent':camera.ui, 'scale':.2, 'z':-100, 'texture':'impact_effect.gif', 'enabled':false, 'alpha':.5})
1230+
if (!click_animation.texture) {
1231+
click_animation.visible = false
1232+
}
12241233

12251234
time_of_press = 0
12261235
function _handle_mouse_click(e) {
@@ -1237,6 +1246,9 @@ function _handle_mouse_click(e) {
12371246
if (element_hit && entity) {
12381247
if (entity.on_click) {
12391248
entity.on_click()
1249+
click_animation.xy = mouse.position
1250+
click_animation.enabled = True
1251+
click_animation.texture = 'impact_effect.gif'
12401252
}
12411253
if (entity.draggable) {
12421254
window_position = _game_window.getBoundingClientRect()
@@ -1305,6 +1317,7 @@ function _onmousemove(event) {
13051317
var x = event.clientX - rect.left; //x position within the element.
13061318
var y = event.clientY - rect.top; //y position within the element.
13071319
mouse.point = [(x/rect.width)-.5, .5-(y/rect.height)]
1320+
// print(mouse.point)
13081321
}
13091322
element_hit = document.elementFromPoint(event.pageX - window.pageXOffset, event.pageY - window.pageYOffset);
13101323
_entity = entities[element_hit.entity_index]

0 commit comments

Comments
 (0)