Skip to content

Commit ee3effe

Browse files
Merge branch 'fix-tooltip-module' into 'master'
[FIX][SDK] TooltipModule can't now show multiple info blocks for stacked sprites See merge request codingame/game-engine!222
2 parents a22d375 + c0f2790 commit ee3effe

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

engine/modules/tooltip/src/main/resources/view/tooltip-module/TooltipModule.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,16 @@ import { api as entityModule } from '../entity-module/GraphicEntityModule.js'
33

44
/* global PIXI */
55

6+
function getSpriteMouseMoveFunc (entity, tooltip) {
7+
return function (event) {
8+
if (entity.graphics.containsPoint(event.data.global)) {
9+
tooltip.inside[entity.id] = true
10+
} else {
11+
delete tooltip.inside[entity.id]
12+
}
13+
}
14+
}
15+
616
function getMouseOverFunc (id, tooltip) {
717
return function () {
818
tooltip.inside[id] = true
@@ -136,8 +146,12 @@ export class TooltipModule {
136146
entityModule.entities.forEach(entity => {
137147
if (this.interactive[entity.id]) {
138148
entity.container.interactive = true
139-
entity.container.mouseover = getMouseOverFunc(entity.id, this.tooltip)
140-
entity.container.mouseout = getMouseOutFunc(entity.id, this.tooltip)
149+
if (typeof (entity.graphics && entity.graphics.containsPoint) === 'function') {
150+
entity.container.mousemove = getSpriteMouseMoveFunc(entity, this.tooltip)
151+
} else {
152+
entity.container.mouseover = getMouseOverFunc(entity.id, this.tooltip)
153+
entity.container.mouseout = getMouseOutFunc(entity.id, this.tooltip)
154+
}
141155
}
142156
})
143157
this.container = container

0 commit comments

Comments
 (0)