I am trying to implement a game where there are moving objects(Bitmaps) and I need to detect collision. I used the following code to make objects move(transform) and check hitTest
with mouse hover.
However, the alpha is not changed with the correct mouse position, instead, it detects the left upper corner of the canvas.
rock = new createjs.Bitmap(loader.getResult("rock"));
rock.setTransform(800, 270, 0.5, 0.5);
stage.addChild(rock);
// .....
createjs.Ticker.timingMode = createjs.Ticker.RAF;
createjs.Ticker.addEventListener("tick", tick);
// .....
function tick(event) {
rock.alpha = 0.7;
if (rock.hitTest(stage.mouseX, stage.mouseY)) {//if hit, change alpha
rock.alpha = 1;
}
var deltaS = event.delta / 1000;
rock.x = (rock.x - deltaS * groundSpeed);//to gradually shift the rock
if (rock.x + rock.image.width * rock.scaleX <= 0) {//to re-position the rock
rock.x = w + Math.random() * 1000;
}
stage.update(event);
}