Createjs - stage.mouseX

I noticed that there is a bug in the latest versions of createjs (0.8.0 and 0.8.1). if you click multiple times from the canvas (stage) and after trying to click inside its stops shows that you have done stage.mouseX and mouseY correctly. it always shows the "old" values.

this error is android only.

http://oligarch.us/temp/createjs/index8.html (error here). click several times outside the scene (gray) and after clicking on the scene (yellow). Nothing happens.

http://oligarch.us/temp/createjs/index7.html (no error using 0.7.1)

any ideas? any suggestions?

my code:

var stage;
var canvas;

var $width  = 500;
var $height = 900;

var box;

window.onload = function()
{
    //fixCocoonEaselJSStageTouch();
    canvas = document.getElementById('canvas');
    ctx = canvas.getContext('2d');
    ctx.imageSmoothingEnabled = ctx.mozImageSmoothingEnabled = true;

    stage = new createjs.Stage(canvas);
    createjs.Touch.enable(stage);

    log("easejs version: " + createjs.EaselJS.version);

    stage.snapToPixelsEnabled  = true;
    stage.enableMouseOver(0);

    //stage.mouseEnabled = false;
    stage.mouseMoveOutside = true;

    //createjs.Touch.enable(stage);
    createjs.Ticker.setFPS(30);
    createjs.Ticker.addEventListener("tick", update);

    //createjs.Ticker.timingMode = createjs.Ticker.useFrames;

    window.addEventListener('resize', resize, false);
    resize();

    var s = new createjs.Shape();
    s.graphics.beginFill("#FFFF00").drawRect(0, 0, 630, 960);
    stage.addChild(s);

    box = new createjs.Container;
    var s = new createjs.Shape();
    s.graphics.beginFill("#FF0000").drawRect(0, 0, 50, 50);
    box.addChild(s);

    stage.addChild(box);

    stage.addEventListener("mousedown",function(){
        log(stage.mouseX)
    })
};

function update(e) {
    stage.update(e);

    box.x = stage.mouseX;
    box.y = stage.mouseY;
 };

function resize() {
    var gameArea = document.getElementById('gameArea');
    var widthToHeight = $width / $height;

    var newWidth = window.innerWidth;
    var newHeight = window.innerHeight;
    var newWidthToHeight = newWidth / newHeight;

    if (newWidthToHeight > widthToHeight) {
        // window width is too wide relative to desired game width
        newWidth = newHeight * widthToHeight;

        gameArea.style.height = (newHeight) + 'px';
        gameArea.style.width = newWidth + 'px';
    } else { // window height is too high relative to desired game height
        newHeight = newWidth / widthToHeight;
        gameArea.style.width = newWidth + 'px';
        gameArea.style.height = newHeight + 'px';
    }

    gameArea.style.marginTop = (-newHeight / 2) + 'px';
    gameArea.style.marginLeft = (-newWidth / 2) + 'px';
}
function log(o){
    console.log(o);
};

      

+3


source to share





All Articles