void FlyScene::createBullet( float dt )
{
if(bullets.size()>g_bulletNum){
//只创建规定数量的炸弹
return;
}
//printf("创建新的bullet
");
CCTexture2D *texture = CCTextureCache::sharedTextureCache()->addImage("bullet.png");
CCSprite *bullet = CCSprite::createWithTexture(texture);
this->addChild(bullet);
bullets.push_back(bullet);
CCSize winSize = CCDirector::sharedDirector()->getWinSize();
float x, y;
int speedX, speedY;
int randVal = rand();
int entrance = randVal % 4;
switch(entrance){
case 0:
//从上侧飞入
x = randVal % (int)winSize.width;
y = winSize.height - bullet->getContentSize().height/2;
speedX = randVal%3;
speedY = -(randVal%3 + 1);
break;
case 1:
//从下侧飞入
x = randVal % (int)winSize.width;
y = bullet->getContentSize().height/2;
speedX = randVal%3;
speedY = randVal%3 + 1;
break;
case 2:
//从左侧飞入
x = bullet->getContentSize().width/2;
y = randVal % (int)winSize.height;
speedX = randVal%3 + 1;
speedY = randVal%3;
break;
case 3:
//从右侧飞入
x = bullet->getContentSize().width/2;
y = randVal % (int)winSize.height;
speedX = -(randVal%3 + 1);
speedY = randVal%3;
break;
}
CCActionInterval *action = CCMoveBy::create(0.1f, ccp(speedX,speedY));
bullet->setPosition(ccp(x,y));
bullet->runAction(CCRepeatForever::create(action));
}
为什么 屏幕上没有子弹效果呢?