cocos2d-js v3.6.1 扑克弹出,缩回例子

前端之家收集整理的这篇文章主要介绍了cocos2d-js v3.6.1 扑克弹出,缩回例子前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。



首先定义一个 poker类:




var Poker = cc.Sprite.extend({
bSelect:false,//是否已选
bDianJi:true,//是否能点击
huaSe:5,//花色:黑0,红1,梅2,方3,王4,无效5
num:0,//牌值
number:0,//总牌值:1-54
local_x:0,//扑克的x值
local_y:0,//扑克y值,点击扑克时做弹出收回操作
ctor:function(menu,Num,x,y){
this._super();

this.number = Num;
if(Num<1 || Num>54){cc.log("input poker number is error!");}
this.local_x = x;
this.local_y = y;
if(Num==1 || Num ==2){
this.huaSe = 4;
this.num = Num;
}else {
this.huaSe = Math.floor(Num/16);
this.num = Num%13;
}
var picName1 = "res/"+ Num + ".jpg";

var menuSprite = cc.MenuItemImage.create(picName1,picName1,this.callback,this);
menuSprite.setAnchorPoint(AnchorPoint.CENTER_MIDDLE);
menu = cc.Menu.create(menuSprite);
menu.setAnchorPoint(AnchorPoint.CENTER_MIDDLE);
menu.setPosition(cc.p(x,y));
menu.setVisible(true);
menu.retain();
m_pk[Num] = menu;
m_this.addChild(menu,20);

return this;
},
onEnter:function(){
this._super();
},
callback:function(){
if(this.bDianji == true){
cc.log("HuaSe="+this.huaSe +",Num="+this.num+"Number="+this.number);
m_curPK = this.number;
if(this.bSelect==false){
this.pokerLuTou();
}else{
this.pokerSuoTou();
}
}else{
cc.log('can not click!');
}
},
pokerLuTou:function(){
cc.log('LuTou.x='+this.local_x+',y='+(this.local_y+PKUpLength));
this.bSelect = true;
m_pk[this.number].setPosition(cc.p(m_pk[this.number].x,m_pk[this.number].y+PKUpLength));
},
pokerSuoTou:function(){
cc.log('SuoTou.x='+this.local_x+',y='+this.local_y-PKUpLength);
this.bSelect = false;
m_pk[this.number].setPosition(cc.p(m_pk[this.number].x,m_pk[this.number].y-PKUpLength));
}

});




调用者:

for(var i=1; i<=54;i++){ m_poker[i] = new Poker(m_pk[i],i,size.width/10+PKJianJu*(i),size.height/4*3); } 如此,便能显示扑克,并且响应点击事件,弹出,缩回扑克

原文链接:https://www.f2er.com/cocos2dx/342192.html

猜你在找的Cocos2d-x相关文章