var FPS = FPS || {};
FPS.time = 0;
FPS.FPS = 0;
FPS.showText = "";
FPS.startFPS = function (stage, pos = { x: 0, y: 0 }, app) {
    FPS.app = app;
    FPS.pos = pos;
    FPS.shape = new createjs.Shape();
    FPS.shape.graphics.beginFill("#2dffda").drawRect(pos.x, pos.y, 140, 50);
    FPS.shape.alpha = .5;
    FPS.txt = new createjs.Text("COUNT:", "24px Arial", "#ffffff");
    FPS.txt.x = 20;
    FPS.txt.y = pos.y + 10;
    FPS.container = new createjs.Container();
    if (FPS.app.debug) {
        stage.addChild(FPS.container);
    }
    // FPS.container.addChild(FPS.shape)
    // FPS.container.addChild(FPS.txt);
    FPS.container.cache(pos.x, pos.y, 140, 50);
    createjs.Ticker.addEventListener("tick", FPS.TickerFPS);

    //    setInterval(FPS.TickerFPS,18)
}
FPS.TickerFPS = function (event) {
    FPS.date = new Date();
    FPS.currentTime = FPS.date.getTime();
    if (FPS.time != 0) {
        FPS.FPS = Math.ceil(1000 / (FPS.currentTime - FPS.time));
    }
    FPS.time = FPS.currentTime;
    FPS.txt.text = "FPS: " + FPS.FPS + "\n" + FPS.showText;
    FPS.container.cache(FPS.pos.x, FPS.pos.y, 140, 50);
}
FPS.startFPS2 = function (stage) {
    FPS.txt = document.getElementById("fps");
    createjs.Ticker.addEventListener("tick", FPS.TickerFPS2);
}
FPS.TickerFPS2 = function (event) {
    FPS.date = new Date();
    FPS.currentTime = FPS.date.getTime();
    if (FPS.time != 0) {
        FPS.FPS = Math.ceil(1000 / (FPS.currentTime - FPS.time));
    }
    FPS.time = FPS.currentTime;
    FPS.txt.innerText = "FPS: " + FPS.FPS;
}

module.exports = FPS;