var update = function(args, ctx){
// Get the span element from the HTML Entity
var selection = document.getElementById('selected');
// Create a click handler function
ctx.handleClick = function(event){
var x = event.offsetX;
var y = event.offsetY;
ctx.world.gooRunner.pick(x, y, function(index, depth){
if(index !== -1){
var entity = ctx.world.entityManager.getEntityByIndex(index);
selection.innerHTML = entity.name;
} else {
selection.innerHTML = 'Nothing';
}
});
};
// Attach the click handler
ctx.domElement.addEventListener('click', ctx.handleClick);
if (selection.innerHTML === "Nothing"){
console.log("Nothing Selected");
} else if (selection.innerHTML === "12A02") {
console.log("12A02 Selected");
} else if(selection.innerHTML === "12B13") {
console.log("12B13 Selected");
}
}
var cleanup = function(args, ctx){
// Remove the click handler
ctx.domElement.removeEventListener('click', ctx.handleClick);
}
<style>
#hud {
margin: 25px;
background-color: transparent;
font-weight: bold;
font-family: sans-serif;
font-size: 24px;
color: skyblue;
}
</style>
<p id="hud">
You have selected: <span id='selected'>Nothing</span>
</p>



No comments:
Post a Comment