Hello everyone
I am developing a shooting game.
I want my spaceship shoots automatically.
To achieve this effect, I built an CCArray of 20 elements.
Each element is the bullet sprite.
In the update method, I get the next position in the array.
as follows:
void GameLoop::setUpShipLasers(){
int initWithCapacity = 20;
for(int i = 0; i < initWithCapacity; i++){
GameObject *bullet = new GameObject();
bullet->setSprite(CCSprite::createWithSpriteFrameName("laser_3.png"));
bullet->getSprite()->setVisible(false);
bullet->setLife(1);
bullet->setDamage(1);
bullet->createBody(b2dWorld,spriteShape,CCString::create("laser_3"),true);
bullet->setupExplosion(this,CCString::create("particleSystem/smallFire.plist"),0.3f);
spriteSheet->addChild(bullet->getSprite());
shipLasers->addObject((CCObject*)bullet);
}//fin for
}
void GameLoop::updateShootLaser(float dt){
float delayNumber;
if(!isDelayTime_fireAction){
delayNumber = 0.25f;
isDelayTime_fireAction = true;
CCDelayTime *delayTime = CCDelayTime::create(delayNumber);
this->runAction(CCSequence::create(
delayTime,
CCCallFuncN::create(this,callfuncN_selector(GameLoop::getNextLaser)),
NULL
));
}//fin !isDelayTime_fireAction
}
void GameLoop::getNextLaser(){
float x = heroShip->getSprite()->getPositionX();
float y = heroShip->getSprite()->getPositionY();
CCSize winSize = CCDirector::sharedDirector()->getWinSize();
CCLog("[getNextLaser]shipLasers->count:%d, Laser utilizado: %d",shipLasers->count(),(nextLaser+1));
GameObject *b = (GameObject*)shipLasers->objectAtIndex(nextLaser++);
if(nextLaser >= shipLasers->count())
nextLaser = 0;
b->getSprite()->setPosition(ccp(x-b->getSprite()->getContentSize().width,y-b->getSprite()->getContentSize().height/2));
b->getSprite()->setVisible(true);
b->getBody()->SetActive(true);
b->getSprite()->stopAllActions();
b->exeAction(CCMoveBy::create(0.75,ccp(winSize.width,0)));
//---------------
CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect("sound/laser_ship.mp3");
}
The result is: view image piloto_projecto.png
Enclosed in the circle is the sprite and enclosed in the rectangle just this body.
Can anyone tell me what to do or a clue?
Thanks for the support
piloto_projecto.png (61.0 KB)