本文主要讲解以下几个方面:
- card model
- 滑动处理
- 阴影
- 选择
- 出牌
Card Model
首先,牌有两个属性:数字、花型;
ps:本文现在是,用数字和花型来组成一张牌,有空可以再用另一种形式走一遍,比如用54个数字(0-53)来表示一副牌。
CardInfo.js
//花型
var CardSuit = cc.Enum ({ none: 0, spade: 1, //黑桃 heart: 2, //红心 club: 3, //梅花 diamond: 4,//方块 }); //数字 var CardNumber = cc.Enum ({ none: 0, num_3: 3, num_4: 4, num_5: 5, num_6: 6, num_7: 7, num_8: 8, num_9: 9, num_10: 10, num_J: 11, num_Q: 12, num_K: 13, num_A: 14, num_2: 15, littleJoker: 16, bigJoker: 17, }); var CardInfo = cc.Class ({ extends: cc.Component, properties: { //数字 number: { default: CardNumber.none, type: CardNumber }, //花型 suit: { default: CardSuit.none, type: CardSuit }, }, statics: { CardNumber: CardNumber, CardSuit: CardSuit }, //主要用于打印时,能清晰看到现在是哪张牌 desc() { var desc = ""; if (this.number == CardNumber.littleJoker) { return "小王"; } if (this.number == CardNumber.bigJoker) { return "大王"; } switch(this.suit) { case CardSuit.heart: desc = "红桃"; break; case CardSuit.spade: desc = "黑桃"; break; case CardSuit.club: desc = "梅花"; break; case CardSuit.diamond: desc = "方块"; break; } switch(this.number) { case CardNumber.num_3: desc += "3"; break; case CardNumber.num_4: desc += "4"; break; case CardNumber.num_5: desc += "5"; break; case CardNumber.num_6: desc += "6"; break;