Quantcast
Channel: cocos2d-x - Cocos Forums
Viewing all articles
Browse latest Browse all 2748

Schedule Problem

$
0
0

@Refetizm wrote:

Hi everyone,

I’m making an endless runner game. For the game to progress endless, objects are spawned off the game screen and begin to move. I used as “schedule” to get spawn times regular, but as the picture shows, the distance between the objects is different because the spawn times change somehow. What am I missing?

Note: The width of the objects is equal.

Definitions.h :
#define BUILDING_SPAWN_SPEED 0.65f

HelloWorld.h :
void generateBuildings(float dt = 0.f);

HelloWorld.cpp

schedule(schedule_selector(HelloWorld::generateBuildings), BUILDING_SPAWN_SPEED);
scheduleUpdate();
return true;
}

void HelloWorld::generateBuildings(float dt)
{
auto visibleSize = Director::getInstance()->getVisibleSize();
Vec2 origin = Director::getInstance()->getVisibleOrigin();
auto buildingSprite = BuildingPool::getBuildings()->getSprite(BUILDING_ID_TAG);
buildingSprite->setAnchorPoint(Vec2(0.5, 0.0));
buildingSprite->setPosition(Vec2(visibleSize.width + origin.x + buildingSprite->getContentSize().width / 2, 0));
this->addChild(buildingSprite, 3);
}

Posts: 4

Participants: 3

Read full topic


Viewing all articles
Browse latest Browse all 2748

Latest Images

Trending Articles



Latest Images