Click on the blue word Follow Us!
Efforts of a number of public
Long good-looking people are concerned about the
In the game, sometimes in order to pass a way interesting, allowing users to get some kind of random items in some of the items in addition to the previously mentioned using Big Wheel lottery we get, there is a similar function can be achieved is to extract the card.
description
Pumping open interface card, to show the user all the back surface of the card, a random point until the user card, the card will open a movie player, and displaying information related to the card and the like is described.
UI construction
(1) Create a new Button component, brand image is set to a rear view of
(2) 5 parts of replication, lined up, and in turn were ordered as follows;
the effect is as follows:
Code
(1) to declare an array of storage card
the this . Cards = []; // Array Card
(2) facing the storage card array
for (let i = 0; i < 6; i++)
{
self.cards[i] = cc.find("card" + i, obj4);
}
(3)为卡片添加监听事件
findBtn("card" + i, obj4, function ()
{
self.turnCard(i);
})
(4)翻牌操作(翻牌动画)
///翻牌操作
turnCard(idx) {
var self = this;
var scale1 = cc.scaleTo(0.1, 0, 1);
var call1 = app.callFunc(function (adt) {
self.flipCard(idx);
}, [self.cards[idx]]);
var scale2 = cc.scaleTo(0.1, 1, 1)
self.cards[idx].stopAllActions();
self.cards[idx].runAction(cc.sequence(scale1, call1, scale2));
},
5翻牌后显示牌正面:这里为了替换牌正面纹理的方便,我们将它保存在Resources/image/card/目录下,并依次命名为1,2,3,4,5,将背面纹理图片命名为0.
//翻开某一张牌后显示牌正面相关信息
flipCardShow(idx) {
//--测试,根据需要赋值
let cardIdx=3;
self.updateCardTexture(this.cards[idx], cardIdx);//更换牌的纹理
//显示牌正面的其他信息
//TODO
},
修改纹理图片方法:
updateCardTexture(img, textureName) {
cc.loader.loadRes("image/card/" + textureName, cc.SpriteFrame, function (err, spriteFrame) {
if (!err) { img.getComponent(cc.Sprite).spriteFrame = spriteFrame; }
});
},
6.当关闭该翻牌面板时,需要将翻牌结果重置未未翻牌状态
//初始化牌
initCard() {
for (let i = 0; i < 6; i++) {
gm.GameData.updateCardTexture(this.cards[i], "0");
}
},
So far, the flop function is realized, the main purpose of writing this article is to share a flop animation, step (4).
effect
Note: gif above effects produced ps output frame animation, not the actual results. Actual results will look more coordinated a number.
If you want to learn ps, you can scan the next Fanger Wei code, look at our public number oh ~
Past Recommended
One. Bedtime glance, fast-paced world (three)
two. Finally, I riches! ! (two)
three. The college entrance examination, will go from here? (One)