【cocos2d-x IOS游戏开发-城市跑酷12】男一号上场,大家鼓掌!
来源:互联网 发布:苹果6的4g网络慢怎么办 编辑:程序博客网 时间:2024/04/30 02:43
尊重开发者的劳动成果,转载的时候请务必注明出处:http://blog.csdn.net/haomengzhu/article/details/17324797
<捕鱼达人>回顾
【cocos2d-x IOS游戏开发-捕鱼达人1】内容介绍
上节回顾
【cocos2d-x IOS游戏开发-城市跑酷11】设置菜单层及新的开始
创建一个主角:
//创建主角类_player = Player::create();_gameBatchNode->addChild(_player, kBackground);
Player * Player::create () {Player * player = new Player();if (player && player->initWithSpriteFrameName("player_1.png")) {player->autorelease();player->setSize();player->initPlayer();return player;}CC_SAFE_DELETE(player);return NULL;}
初始化主角:
//初始化主角void Player::initPlayer () {//设置锚点this->setAnchorPoint(ccp(0.5f, 1.0f));this->setPosition(ccp(_screenSize.width * 0.2f, _nextPosition.y));//_height = 228;//_width = 180;_height = 50;_width = 50; CCAnimation* animation;//创建一个空白的序列帧动画信息 animation = CCAnimation::create();//CCSpriteFrame对应的就是帧,将CCSpriteFrame添加到CCAnimation生成动画数据,//用CCAnimation生成CCAnimate(就是最终的动画动作),最后可以用CCSprite执行这个动作。 CCSpriteFrame * frame; int i;//共有3帧,这里用for循环将对应的序列图加入到动画中 for(i = 1; i <= 3; i++) { char szName[100] = {0}; sprintf(szName, "player_%i.png", i); frame = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(szName); animation->addSpriteFrame(frame); } //设置每两帧间时间间隔 animation->setDelayPerUnit(0.2f / 3.0f);//设置动画结束后是否保留动画帧信息 animation->setRestoreOriginalFrame(false);//设置循环播放次数 (-1:无限循环) animation->setLoops(-1);//由这个动画信息创建一个序列帧动画 _rideAnimation = CCAnimate::create(animation);//保存这个动画 _rideAnimation->retain(); //CCFiniteTimeAction是所有有限次执行类(或者也可以叫顺序执行类吧)的基类//CCSequence创建一个动作序列//CCEaseInOut创建对应匀速动画的变速动画,参数一为一个匀速动画。参数二为速度 CCFiniteTimeAction* easeSwing = CCSequence::create( CCEaseInOut::create(CCRotateTo::create(0.8f, -10), 2), CCEaseInOut::create(CCRotateTo::create(0.8f, 10), 2), NULL); _floatAnimation = CCRepeatForever::create( (CCActionInterval*) easeSwing ); _floatAnimation->retain(); this->runAction(_rideAnimation);}
主角状态更新:
void Player::update (float dt) {//加速度到最大,然后匀速if (_speed + ACCELERATION <= _maxSpeed) {_speed += ACCELERATION;} else {_speed = _maxSpeed;}_vector.x = _speed;//CCLog("play state:%d",_state);//主角状态switch (_state) {//在移动case kPlayerMoving:_vector.y -= GRAVITY;if (_hasFloated) _hasFloated = false;break;//在下降case kPlayerFalling:if (_floating ) {_vector.y -= FLOATNG_GRAVITY;_vector.x *= FLOATING_FRICTION;} else {_vector.y -= GRAVITY;_vector.x *= AIR_FRICTION;_floatingTimer = 0;}break;//死亡case kPlayerDying:_vector.y -= GRAVITY;_vector.x = -_speed;this->setPositionX(this->getPositionX() + _vector.x);break;}if (_jumping) {_state = kPlayerFalling;_vector.y += PLAYER_JUMP * 0.25f;if (_vector.y > PLAYER_JUMP ) _jumping = false;}if (_vector.y < -TERMINAL_VELOCITY) _vector.y = -TERMINAL_VELOCITY;_nextPosition.y = this->getPositionY() + _vector.y;if (_vector.x * _vector.x < 0.01) _vector.x = 0;if (_vector.y * _vector.y < 0.01) _vector.y = 0;if (_floating) {_floatingTimer += dt;if (_floatingTimer > _floatingTimerMax) {_floatingTimer = 0;this->setFloating(false);}}}
2 1
- 【cocos2d-x IOS游戏开发-城市跑酷12】男一号上场,大家鼓掌!
- 【cocos2d-x IOS游戏开发-城市跑酷1】跑酷游戏介绍
- 【cocos2d-x IOS游戏开发-城市跑酷9】没有各种坑还叫游戏吗
- 【cocos2d-x IOS游戏开发-城市跑酷13】游戏玩法:友情提示:how to play?
- 【cocos2d-x IOS游戏开发-城市跑酷19】游戏效果图及资源引用页
- 【cocos2d-x IOS游戏开发-城市跑酷3】读取资源,设置背景层
- 【cocos2d-x IOS游戏开发-城市跑酷2】python create_project
- 【cocos2d-x IOS游戏开发-城市跑酷4】设置“道具”:云、路灯、竞技团队
- 【cocos2d-x IOS游戏开发-城市跑酷5】导演说:动起来,动起来!
- 【cocos2d-x IOS游戏开发-城市跑酷6】添加街区元素:墙、屋顶、烟囱
- 【cocos2d-x IOS游戏开发-城市跑酷7】设计烟囱与烟的效果
- 【cocos2d-x IOS游戏开发-城市跑酷8】实现街区房子的摆放
- 【cocos2d-x IOS游戏开发-城市跑酷11】设置菜单层及新的开始
- 【cocos2d-x IOS游戏开发-城市跑酷15】完善积分板【CCLabelBMFont】
- 【cocos2d-x IOS游戏开发-城市跑酷18】统计结果,主角复活Try Again!!
- 【cocos2d-x IOS游戏开发-城市跑酷10】完善繁荣的城市街区及地形图类
- 【cocos2d-x IOS游戏开发-城市跑酷14】重写触屏[Touch]事件处理机制,响应玩家操作
- 【cocos2d-x IOS游戏开发-城市跑酷16】碰撞检测:撞墙 or 从房子上掉下来
- MFC操作EXCEL封装类
- 血与泪的经验:服务器ARP的欺骗攻击与防范
- 大家好。初来乍到,很喜欢这个地方。
- virtual 关键字 继承的使用
- 表空间学习笔记(一)
- 【cocos2d-x IOS游戏开发-城市跑酷12】男一号上场,大家鼓掌!
- UriMacher
- ipconfig源码
- sitemesh网页布局和修饰的框架
- windows下用netsh工具设置笔记本wifi热点
- C++多重继承
- python发送http请求
- C# ListView用法详解
- 使用Ambari快速部署Hadoop大数据环境