首页 > 代码库 > 哇!板球 源码分析三
哇!板球 源码分析三
守门员出场
守门员出场,每个守门员是从屏幕的右侧中间的位置随机方向向左侧移动
FielderSprite* fielderSprite1 = FielderSprite::create("pic/fielder.png"); //守门员精灵初始位置为右侧中间位置 fielderSprite1->setPosition(ccp(GOALKEEPER_X, GOALKEEPER_Y)); fielderSprite1->setAnchorPoint(ccp(0.5, 0.5));//默认锚点为0.5,0.5 //将fielder精灵添加到布景中 this->addChild(fielderSprite1, GAME_LEVEL_WYF);
动作序列中的6个动作,终点都在最左侧
CCActionInterval* at1=CCMoveBy::create(3.5,CCPointMake(-800,-170)); CCActionInterval* at2=CCMoveBy::create(4,CCPointMake(-800,-100)); CCActionInterval* at3=CCMoveBy::create(2.5,CCPointMake(-800,-30)); CCActionInterval* at4=CCMoveBy::create(4.5,CCPointMake(-800,40)); CCActionInterval* at5=CCMoveBy::create(5,CCPointMake(-800,110)); CCActionInterval* at6=CCMoveBy::create(3,CCPointMake(-800,180));
随机移动的6条线路
int r = rand()%6; switch(r) { case 0: fielderSprite1->runAction(at1); fielderSprite1->ccat=at1; fielderSprite1->mark=1;break; case 1: fielderSprite1->runAction(at2); fielderSprite1->ccat=at2; fielderSprite1->mark=2;break; case 2: fielderSprite1->runAction(at3); fielderSprite1->ccat=at3; fielderSprite1->mark=3;break; case 3: fielderSprite1->runAction(at4); fielderSprite1->ccat=at4; fielderSprite1->mark=4;break; case 4: fielderSprite1->runAction(at5); fielderSprite1->ccat=at5; fielderSprite1->mark=5;break; case 5: fielderSprite1->runAction(at6); fielderSprite1->ccat=at6; fielderSprite1->mark=6;break; }
将定时器在一次创建的守门员都添加到array中,用于后面检测是否与球碰撞了
array->addObject(fielderSprite1);
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。