Quantcast
Channel: Cocos Forums - Latest topics
Viewing all articles
Browse latest Browse all 17076

String array error

$
0
0

@perinho wrote:

Hey guys, sorry for this topic, but I'm trying to create a system to randomly select an image to generate a sprite, but I can't figure out how to do that here is my code:

Color::Color( )
{
string spriteC[2] = {"a.png","b.png"};
visibleSize = Director::getInstance( )->getVisibleSize( );
origin = Director::getInstance( )->getVisibleOrigin( );
}
void Color::SpawnColor(cocos2d::Layer *layer)
{
int cor = rand()%(2-0)+0;
auto colorObstacle = Sprite::create(spriteC[cor]);
auto colorObstacleBody = PhysicsBody::createBox(colorObstacle->getContentSize());
colorObstacleBody->setDynamic(true);
colorObstacle->setPhysicsBody(colorObstacleBody);
colorObstacle->setPosition(origin.x+visibleSize.width,origin.y+visibleSize.height);
layer->addChild(colorObstacle,0);
}

But it's not working, what would I do to make this work? Thanks in advance

Posts: 5

Participants: 3

Read full topic


Viewing all articles
Browse latest Browse all 17076

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>