Dear Cocos2d-x forum
I am pretty new to iOS development but am good in c++ ONLY
I wanted to create a sprite from a class but every time i try to run the simulator, it crashes!
Here is my syntax code that i want to get fixed!
void Game::initializeGame()
{
if (Utils::s().width > 1024) {
}
else { CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("GEMS.plist");
}
gems = CCArray::create();
gems->retain();
for (int i = 1; i <= 3; i++) {
Gem *gem = (Gem *) Gem::create();
gem->setPosition(ccp(300 * i , 667)); (EXC_BAD code=2 adress=0x0)
gems->addObject(gem);
this->addChild(gem, 1);
}
And here is the header file from the Gem.h
---------------------------------------------------------------//
// Mole.h
// moleit-x
//
//
// Copyright © 2012 MyCompanyName. All rights reserved.
//
#ifndef moleit_x_Mole_h
#define moleit_x_Mole_h
#include “cocos2d.h”
using namespace cocos2d;
class Gem : public cocos2d::CCSprite
{
private:
public:
float upTime;
bool isIn, didMiss;
// Here’s a difference. Method ‘init’ in cocos2d-x returns bool, instead of returning ‘id’ in cocos2d-iphone
virtual bool init();
void stop();
void reset();
void start();
void wasTapped();
void startAndFall();
bool getIsUp();
void stopEarly();
void startLoopAnimation();
CCSprite* gem;
// implement the “static node()” method manually
CREATE_FUNC(Gem);
};
#endif // HELLOWORLD_SCENE_H
And finally the definition of init
#define TAG_REPEAT_ANIM 6
bool Gem::init()
{
if ( !Gem::init() )
{
return false;
}
this->setDisplayFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("greenNOTHDgemstone.png"));
return true;
}
JUST ASK ME IF U HAVE SOME QUESTIONS
u guys can save my life!