cocos2dx 《忍着飞镖射幽灵》小结

  源码教程请移步: http://blog.csdn.net/iamlazybone/article/details/19612941

    感谢懒骨头提供了这么多的Demo教程,对于初学者的我而言,帮助真的十分大。

    注:本节仅仅记录博主自身学习《忍着飞镖射幽灵》的心得体会。


【游戏截图】

wKioL1QKb7-CH_68AADFADrI5xE085.jpg




【学习心得】


1、遍历CCArray

1
2
3
4
5
6
//
     CCARRAY_FOREACH(CCArray, object) 
     {
         //......
     }
//


2、更改背景颜色

    使用颜色布景层CCLayerColor。

1
2
3
4
5
//
     //1.继承CCLayerColor
     //2.然后在init里,将 if(!CCLayer::init()) 替换为
     if ( !CCLayerColor::initWithColor( ccc4(255,255,255,255) ) )
//


3、碰撞检测

    使用boundingBox()、intersectsRect()两个函数,进行矩形碰撞检测。

1
2
3
4
5
6
7
8
//
     //获得图片矩阵 boundingBox()
     CCRect rect_bullet = bullet->boundingBox();
     CCRect rect_enemy  = enemy->boundingBox();
 
     //碰撞检测intersectsRect()
     rect_enemy.intersectsRect(rect_bullet);
//


4、获得触摸点坐标

1
2
3
4
//
     CCTouch* touch
     CCPoint location = touch->getLocation();
//


5、帧动画

    直接使用图片资源创建Animation/Animate动画。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
//
     CCAnimation* animation = CCAnimation::create();
 
     for  ( int  i = 9; i <= 23; i += 2) {
         char  str[50];
         sprintf (str,  "hero/20005_%2d.png" , i);
         animation->addSpriteFrameWithFileName(str);
     }
     
     animation->setDelayPerUnit(1.0f / 16.0f);  //每帧间隔,单位秒
     animation->setRestoreOriginalFrame( true );  //是否还原为原始帧
 
     CCFiniteTimeAction* ac = CCAnimate::create(animation);
     CCCallFunc* finished = CCCallFunc::create( this , callfunc_selector(GameOver::actionDone));
     CCFiniteTimeAction* act = CCSequence::create(ac, finished, NULL);
     sp->runAction(act);
//



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值