cocos2d-js 카드 뒤집기

20370 단어 Cocos2d-JS
pg.TurnCardLayer = cc.Layer.extend({
    okBtn: null
});

pg.TurnCardLayer.create = function () {
    var res = new pg.TurnCardLayer();
    return (res && res.init()) ? res : null;
};

pg.TurnCardLayer.prototype.ctor = function () {
    cc.Layer.prototype.ctor.call(this);

    //  
    console.log("TurnCardLayer:init");
    //  
    var winSize = cc.winSize;

    //  
    pg.setDefaultTextureFormat(cc.Texture2D.PIXEL_FORMAT_RGB565);

    //  
    var bgSprite = new cc.Sprite(res.StartBG_568_png);
    bgSprite.setPosition(winSize.width / 2, winSize.height / 2);
    this.addChild(bgSprite);

    //  
    pg.setDefaultTextureFormat(cc.Texture2D.PIXEL_FORMAT_RGBA4444);

    var okBtnItem = cc.MenuItemImage.create(res.Start_png);
    okBtnItem.setPosition(winSize.width / 2, winSize.height / 2);

    var menu = new cc.Menu(okBtnItem);
    menu.setPosition(0, 0);
    this.addChild(menu, 10);

    //  
    pg.dumpTextureInfo();
};

pg.TurnCardLayer.prototype.init = function () {

    return true;
};

pg.TurnCardLayer.prototype.onClear = function () {
    pg.Layer.prototype.onClear();
    console.log("TurnCardLayer:clear");
    pg.removeTextureForKey(res.StartBG_568_png);
};


pg.TurnCardScene = cc.Scene.extend({
    actionIsDone: false
});

pg.TurnCardScene.create = function (num) {
    var res = new pg.TurnCardScene();
    if (res && res.init(num)) {
        // var layer = pg.TurnCardLayer.create();
        // res.addChild(layer);
        return res;
    }
    return null;
};

pg.TurnCardScene.prototype.init = function (num) {
    // 
    // var background = cc.LayerColor.create(cc.color(255, 180, 255, 255), cc.size.width, cc.size.height);
    // this.addChild(background);

    this.actionIsDone = true;//  

    this.createPoker();      //  

    this.createListener();   //  

    return true;
};

//  
pg.TurnCardScene.prototype.createPoker = function () {
    //  
    //  

    // var pokerFront = new cc.Sprite(res.Card_Clubs_2_png);
    // pokerFront.setVisible(true);
    // pokerFront.setPosition(cc.p(cc.winSize.width / 2, cc.winSize.height / 2));
    // this.addChild(pokerFront, 1, 123);
    //
    //  
    var pokerBack = new cc.Sprite(res.Card_BackGround_Normal_png);
    pokerBack.setPosition(cc.p(cc.winSize.width / 2, cc.winSize.height / 2));
    this.addChild(pokerBack, 1, 321);
};

//  
pg.TurnCardScene.prototype.startOrbitAction = function () {
    // //  
    // var pokerFront = this.getChildByTag(123);
    // //  
    var pokerBack = this.getChildByTag(321);

    var actionBy = cc.rotateBy(0.2, 0, -90);

    pokerBack.runAction(cc.sequence(actionBy,
        cc.callFunc( function() {
            pokerBack.setTexture(res.Card_Clubs_2_png);
            pokerBack.setFlippedX(true);
        }),
        actionBy
    ));
};

pg.TurnCardScene.prototype.actionIsDownFunc = function () {
    this.actionIsDone = true;
};

pg.TurnCardScene.prototype.createListener = function() {
    var listener = cc.EventListener.create({
        event: cc.EventListener.TOUCH_ALL_AT_ONCE,
        swallowTouches: true,
        onTouchesBegan: function (touches, event) {

            var target = event.getCurrentTarget();
            target.onTouchBegan(touches);

            return true;
        },
        onTouchesMoved: function (touches, event) {

            var target = event.getCurrentTarget();
            target.onTouchMoved(touches);
        },
        onTouchesEnded: function (touches, event) {

            var target = event.getCurrentTarget();
            target.onTouchEnded(touches);
        }
    });
    cc.eventManager.addListener(listener, this);
};

pg.TurnCardScene.prototype.onTouchBegan = function (touches) {
    var touch = touches[0];
    var convertedLocation = touch.getLocation();

    this.startOrbitAction();
    return true;
};

pg.TurnCardScene.prototype.onTouchMoved = function (touches) {
    var touch = touches[0];
    var convertedLocation = touch.getLocation();
};

pg.TurnCardScene.prototype.onTouchEnded = function (touches) {

};

pg.TurnCardScene.prototype.onEnter = function () {
    cc.Layer.prototype.onEnter.call(this);
};

pg.TurnCardScene.prototype.onExit = function (){
    cc.Layer.prototype.onExit.call(this);
};

좋은 웹페이지 즐겨찾기