坑爹啊,cocos2dx对象实例化的问题。
本帖最后由 u010232872 于 2013-11-05 16:50:07 编辑 事情是这样的。游戏的主场景
绘制主角
hero = new GameObjHero();
hero->setScale(0.5);
hero->setPosition(ccp(100,160));
addChild(hero,1);
GameObjHero::GameObjHero(void)
{
}
GameObjHero::~GameObjHero(void)
{
}
void GameObjHero::onEnter()
{
CCNode::onEnter();
this->setContentSize(CCSizeMake(85,90));
CCDirector* pDirector = CCDirector::sharedDirector();
pDirector->getTouchDispatcher()->addTargetedDelegate(this, 0, true);
CCSprite * obj = CCSprite::create("s_hurt.png");
hurt = obj->getTexture();
obj = CCSprite::create("s_jump.png");
jump = obj->getTexture();
mainsprite = CCSprite::create("s_1.png");
//动画
CCAnimation * animation = CCAnimation::create();
animation->addSpriteFrameWithFileName("s_1.png");
animation->addSpriteFrameWithFileName("s_2.png");
animation->addSpriteFrameWithFileName("s_3.png");
animation->addSpriteFrameWithFileName("s_4.png");
animation->addSpriteFrameWithFileName("s_5.png");
animation->addSpriteFrameWithFileName("s_6.png");
animation->setDelayPerUnit(0.1f);
animation->setRestoreOriginalFrame(true);
//运行奔跑动画
mainsprite->runAction(CCRepeatForever::create(CCAnimate::create(animation)));
state = 0;
addChild(mainsprite);
}
arrayMakeObjectsPerformSelector(m_pChildren, onEnter, CCNode*);