cocos2d-js 翻牌

cocos2d-js 翻牌,第1张

概述pg.TurnCardLayer = cc.Layer.extend({ okBtn: null});pg.TurnCardLayer.create = function () { var res = new pg.TurnCardLayer(); return (res && res.init()) ? res : null;};pg.TurnCardLaye
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);};
总结

以上是内存溢出为你收集整理的cocos2d-js 翻牌全部内容,希望文章能够帮你解决cocos2d-js 翻牌所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1081426.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-27
下一篇 2022-05-27

发表评论

登录后才能评论

评论列表(0条)

保存