使用日程表功能更新精灵位置
update sprite position with schedule function
在我的游戏中,我有一个动画精灵。我在游戏中添加了box2d来增加重力。现在我想使用日程表功能来更新精灵的位置。我用objective-C实现了它,但我希望它是一个多平台游戏,所以现在我正在C++中尝试它。
在我的init中,我有以下行:
this->schedule(cocos2d::SEL_SCHEDULE(View::tick(1.0f)));
方法勾选:
void View::tick(float dt) {
world->Step(dt, 10, 10);
for(b2Body *b = world->GetBodyList(); b; b=b->GetNext()) {
if(b->GetUserData() != NULL) {
}
}
}
我在init中的行中收到以下错误:"无法从类型'void'转换为成员指针类型'coco2d::sel_schedule'(又名void coco2d:::CCobject::*)(float)
我不知道现在该怎么办。我试着在谷歌上搜索,但每个人都使用objective-c或schedule_selector(显然已经不起作用了)
提前感谢
您可能不应该使用schedule函数来更新单个sprite。
在您的场景类中,覆盖虚拟方法进行更新(…):
virtual void update(float dt)
{
CCLOG("This was called.");
// Do updates for everything in the scene you need to call on a tick.
}
此外,覆盖onEnter()和onExitTransitionDidStart()。在第一个步骤中,调用scheduleUpdate来设置场景,以便在刻度上自动调用。在第二个步骤中,调用unscheduledUpdate(在场景退出时)以停止更新。
void IntroScene::onEnter()
{
CCScene::onEnter();
scheduleUpdate();
}
void IntroScene::onExitTransitionDidStart()
{
CCScene::onExitTransitionDidStart();
unscheduleUpdate();
}
这样做可以让您明确控制何时更新。。。在更新周期中只有一个函数被调用。
但是,如果你真的想这么做:
像这样声明您的自定义更新程序:
void IntroScene::myUpdate(float dt)
{
CCLOG("Also called");
}
安排如下:
schedule(schedule_selector(IntroScene::myUpdate), 1.0f);
这样安排:
unschedule(schedule_selector(IntroScene::myUpdate));
**注意**据我所知,您只能"调度"从CCNode派生的对象。
这有帮助吗?
相关文章:
- 将值指定给向量(2D)的向量中的某个位置
- 使用Unreal C++获取VR耳机的世界位置/方向
- 写入位置0x0000000C时发生访问冲突
- 如何将两个不同矢量的同一位置的两个元素组合在一起
- 在不同位置渲染相同精灵的数组
- 在鼠标位置移动精灵
- 更新函数之间精灵的位置
- 如何获得精灵的实际位置并将其打印在C 和SFML中
- 如何根据鼠标位置旋转精灵
- 将聚焦的精灵逐渐移动到目标位置(C++和SFML)
- 使用日程表功能更新精灵位置
- 未在指定位置绘制的精灵
- C++ SFML 精灵位置在功能中时不会更新
- 精灵旋转偏移不会停留在它所属的位置。(SDL)
- C++SFML 1.6精灵位置与鼠标
- 更新精灵位置的奇怪行为
- 在不改变精灵位置的情况下缩放资产
- cocos2dx精灵设置位置错误
- DirectX精灵在缩放时呈现在不同的位置
- 如何使用精灵解析器获得错误位置