首页 技术 正文
技术 2022年11月12日
0 收藏 302 点赞 2,628 浏览 3407 个字

[cpp] view
plain
copy

  1. #include "HelloWorldScene.h"
  2. #include "SimpleAudioEngine.h"
  3. using namespace cocos2d;
  4. using namespace CocosDenshion;
  5. CCScene* HelloWorld::scene()
  6. {
  7. CCScene *scene = CCScene::create();
  8. HelloWorld *layer = HelloWorld::create();
  9. scene->addChild(layer);
  10. return scene;
  11. }
  12. bool HelloWorld::init()
  13. {
  14. if ( !CCLayer::init() )
  15. {
  16. return false;
  17. }
  18. size = CCDirector::sharedDirector()->getWinSize();
  19. //加一背景
  20. CCLayerColor* background = CCLayerColor::create(ccc4(255, 180, 255, 255), size.width, size.height);
  21. this->addChild(background);
  22. actionIsDone = true;//标示动作是否完毕
  23. createPoker(); //创建扑克
  24. return true;
  25. }
  26. //创建扑克
  27. void HelloWorld::createPoker()
  28. {
  29. //扑克牌正面
  30. CCSprite* pokerFront = CCSprite::create("poker_front.png");
  31. pokerFront->setVisible(false);
  32. pokerFront->setPosition(ccp(size.width/2, size.height/2));
  33. this->addChild(pokerFront,1,123);
  34. //扑克牌反面
  35. CCSprite* pokerBack = CCSprite::create("poker_back.png");
  36. pokerBack->setPosition(pokerFront->getPosition());
  37. this->addChild(pokerBack,1,321);
  38. }
  39. //翻牌动作
  40. void HelloWorld::startOrbitAction()
  41. {
  42. //扑克牌正面
  43. CCSprite* pokerFront = (CCSprite*)this->getChildByTag(123);
  44. //扑克牌反面
  45. CCSprite* pokerBack = (CCSprite*)this->getChildByTag(321);
  46. float orbitTime = 1;
  47. if (pokerFront->isVisible() == false && actionIsDone == true) {
  48. actionIsDone = false;
  49. //第一个參数是旋转的时间,第二个參数是起始半径,第三个參数半径差。第四个參数是起始Z角。
  50. 第五个參数是旋转Z角差。第六个參数是起始X角。最后一个參数旋转X角差,
  51. //顺时钟翻转

            CCOrbitCamera* orbitFront = CCOrbitCamera::create(orbitTime, 1, 0, 270, 90, 0, 0);

  52. CCSequence* sequenceFront = CCSequence::createWithTwoActions(CCShow::create(), orbitFront);
  53. CCTargetedAction* targetFront = CCTargetedAction::create(pokerFront, sequenceFront);
  54. CCOrbitCamera* orbitBack = CCOrbitCamera::create(orbitTime, 1, 0, 0, 90, 0, 0);
  55. pokerBack->runAction(CCSequence::create(orbitBack, CCHide::create(), targetFront, CCCallFunc::create(this, callfunc_selector(HelloWorld::actionIsDownFunc)),NULL));
  56. }else if(pokerFront->isVisible() == true && actionIsDone == true){
  57. actionIsDone = false;
  58. //逆时钟翻转

            CCOrbitCamera* orbitFront = CCOrbitCamera::create(orbitTime, 1, 0, 270, 90, 180, 0);

  59. CCSequence* sequenceFront = CCSequence::createWithTwoActions(CCShow::create(), orbitFront);
  60. CCTargetedAction* targetFront = CCTargetedAction::create(pokerBack, sequenceFront);
  61. CCOrbitCamera* orbitBack = CCOrbitCamera::create(orbitTime, 1, 0, 0, 90, 0, 0);
  62. pokerFront->runAction(CCSequence::create(orbitBack, CCHide::create(), targetFront, CCCallFunc::create(this, callfunc_selector(HelloWorld::actionIsDownFunc)),NULL));
  63. }
  64. }
  65. void HelloWorld::actionIsDownFunc()
  66. {
  67. actionIsDone = true;
  68. }
  69. bool HelloWorld::ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent)
  70. {
  71. //翻牌动作
  72. startOrbitAction();
  73. return true;
  74. }
  75. void HelloWorld::ccTouchMoved(CCTouch *pTouch, CCEvent *pEvent){}
  76. void HelloWorld::ccTouchEnded(CCTouch *pTouch, CCEvent *pEvent){}
  77. void HelloWorld::onEnter()
  78. {
  79. CCDirector::sharedDirector()->getTouchDispatcher()->addTargetedDelegate(this, 0, false);
  80. CCLayer::onEnter();
  81. }
  82. void HelloWorld::onExit()
  83. {
  84. CCDirector::sharedDirector()->getTouchDispatcher()->removeDelegate(this);
  85. CCLayer::onExit();
  86. }
  87. HelloWorld::~HelloWorld(){}

两张扑克牌资源:

               

watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvc29uZ19odWlfeGlhbmc=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center” alt=”” style=”border:none; max-width:100%”> 
        

watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvc29uZ19odWlfeGlhbmc=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center” alt=”” style=”border:none; max-width:100%; font-family:SimSun; color:rgb(51,102,255); font-size:18px”>

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,896
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,423
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,241
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,055
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,684
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,723