I have a class player.cpp contains a create method
Player* Player::create(const std::string& filename)
{
Player *player = new (std::nothrow) Player();
if (player && player->createWithSpriteFrameName(filename))
{
player->autorelease();
//default state
player->setState(&PlayerState::idling);
return player;
}
CC_SAFE_DELETE(player);
return nullptr;
}
and in the HelloWorld.cpp in the init function I have this
auto spritePlayerFrame = SpriteFrameCache::getInstance();
spritePlayerFrame->addSpriteFramesWithFile("WarriorSprite.plist");
auto spriteImage = SpriteBatchNode::create("WarriorSprite.png");
this->addChild(spriteImage);
Vector<SpriteFrame*> arrayOfFrames(8);
for (int i = 1; i <= 8; i++)
{
String * fileName = String::createWithFormat("Walk (%d).png",i);
SpriteFrame * frame = spritePlayerFrame->spriteFrameByName(fileName->getCString());
arrayOfFrames.pushBack(frame);
}
CCAnimation* animation = CCAnimation::createWithSpriteFrames(arrayOfFrames,0.1);
_player = Player::create("Walk (1).png");
_player->setPosition(Vec2(visibleSize.width / 2, visibleSize.height / 2));
_player->setScale(0.09);
auto * action = RepeatForever::create(Animate::create(animation));
_player->runAction(action);
but when I add the player to this scene it returns a black sprite with animation, what is the reason ?