public:
...
virtual void update(float dt);
...
private:
float ry;
cocos2d::Sprite * s;
- 然后将init函数的实现改为:
// on "init" you need to initialize your instance
bool HelloWorld::init()
{
//////////////////////////////
// 1. super init first
if ( !Layer::init() )
{
return false;
}
ry = 0;
Size visibleSize = Director::getInstance()->getVisibleSize();
s = Sprite::create("HelloWorld.png");
s->setAnchorPoint(Vec2(0,0.5f));
s->setPosition(visibleSize.width / 2,visibleSize.height / 2);
addChild(s);
scheduleUpdate();
return true;
}
实现update函数:
void HelloWorld::update(float dt){
//s->setPositionZ(s->getPositionZ() + 1);
ry++;
s->setRotation3D(Vec3(0,ry,0));
}
运行,完成!