cocos2dx实现简单卡牌翻转效果

cocos2dx实现简单卡牌翻转效果,第1张

概述将两张图片放入图层,将其中一个图片x的比例设置为0,即隐藏起来。 分别给两个图片绑定点击监听事件,事件触发后执行缩放动作。将自身x比例设置为0,完成后将另一张图片x比例设置为1。 详见代码注释。 bool HelloWorld::init(){ ////////////////////////////// // 1. super init first if ( !Lay

将两张图片放入图层,将其中一个图片x的比例设置为0,即隐藏起来。
分别给两个图片绑定点击监听事件,事件触发后执行缩放动作。将自身x比例设置为0,完成后将另一张图片x比例设置为1。
详见代码注释。

bool HelloWorld::init(){    //////////////////////////////    // 1. super init first    if ( !Layer::init() )    {        return false;    }    auto visibleSize = Director::getInstance()->getVisibleSize();    Vec2 origin = Director::getInstance()->getVisibleOrigin();    //使用两张图片分别创建精灵    auto logo1 = Sprite::create("up.jpg");    auto logo2 = Sprite::create("down.jpg");    //设置居中    logo1->setposition(visibleSize/2);    logo2->setposition(visibleSize/2);    //将第二张图片x轴缩放至隐藏    logo2->setScale(0,1);    //加入图层    addChild(logo1);    addChild(logo2);    //创建监听器    auto touchListener1 = EventListenertouchOneByOne::create();    //设置点击事件    touchListener1->ontouchBegan = [logo1,logo2](touch* touch,Event* event){    //判断点击位置是否在精灵显示范围内        if(event->getCurrentTarget()->getBoundingBox().containsPoint( touch->getLocation())) { //执行缩放动作 auto move1 = Scaleto::create(1,0,1); auto move2 = Scaleto::create(1,1,1); logo1->runAction(move1);            logo2->runAction(move2);        }        return false;    };    //同上    auto touchListener2 = EventListenertouchOneByOne::create();    touchListener2->ontouchBegan = [logo1,Event* event){        if(event->getCurrentTarget()->getBoundingBox().containsPoint( touch->getLocation())) { auto move1 = Scaleto::create(1,1); logo2->runAction(move1);            logo1->runAction(move2);        }        return false;    };    //分别将两个监听器与两个精灵绑定    Director::getInstance()->getEventdispatcher()->addEventListenerWithSceneGraPHPriority(touchListener1,logo1);    Director::getInstance()->getEventdispatcher()->addEventListenerWithSceneGraPHPriority(touchListener2,logo2);    return true;}
总结

以上是内存溢出为你收集整理的cocos2dx实现简单卡牌翻转效果全部内容,希望文章能够帮你解决cocos2dx实现简单卡牌翻转效果所遇到的程序开发问题。

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

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

原文地址:https://54852.com/web/1080993.html

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

发表评论

登录后才能评论

评论列表(0条)

    保存