Actions not running from scheduled method? (beginner, v 2.2)

Actions not running from scheduled method? (beginner, v 2.2)


Hi, I’m having some problems when trying to code a simple sprite creation and movement method: sometimes the bullets move along the screen as expected but most of the time they pop up for a instant (less than a second) then disappear without moving.

void HelloWorld::fireBullets(CCTime dt)
CCSprite* bullet = CCSprite::create(“bullet.png”);
bullet->setPosition(ccp(200, 300));

    //move sprite 800 pixels in 1.5 seconds
bullet->runAction(CCSequence::create(CCMoveBy::create(1.5f, ccp(800, 0)), NULL));

numBullets++;  //an integer counter

char text[256];
sprintf(text, "Num bullets %d", numBullets); 


That’s the method in its simplest form, with all possible external problems gone - it is scheduled to run every 1 second and when run the numBullets ticks with no problem.

    //line which calls method, part of the init method 
this->schedule(schedule_selector(HelloWorld::fireBullets), 1.0);

Strangely, for a test I put identical method code (without the CCTime dt) in a touchBegan method and it worked fine, one bullet everytime finger touched. So from that I think its a conflict between the schedule and the action, but I don’t have much experience to know what kind, and the tutorials I use don’t discuss schedules/actions in detail.

Thanks in advance for any help