update sprite with schedule function

update sprite with schedule function
0.0 0



In my game I have an animated sprite. I added box2d to my game to add gravity. now I want to update my sprite’s position using the schedule function. I got it working with objective-C, but I want it to be a multiplatform game so now I’m trying it in c++.

In my init I have the following line:


and the method tick:

void View::tick(float dt) { world->Step(dt, 10, 10); for(b2Body *b = world->GetBodyList(); b; b=b->GetNext()) { if(b->GetUserData() != NULL) { } } }

I get the following error on the line in my init: "cannot cast from type ‘void’ to member pointer type ‘coco2d::sel_schedule’ (aka void coco2d::CCobject::*)(float)

I have no idea what to do now. I tried to google, but everyone either uses objective - c or schedule_selector (which apparently doesn’t work anymore)

Thanks in advance


When you write View::tick(1.0f) the compiler think that it is call of tick method with parameter 1.0f, and the tick returns void - so it’s difficult to cast void to method pointer.

You should use schedule like this:

schedule(SEL_SCHEDULE selector, float interval, unsigned int repeat, float delay)

so your code turns into:

this->schedule(cocos2d::SEL_SCHEDULE(&View::tick), 1.0f, kCCRepeatForever, 0);


Thanks very much. I don’t have access to a mac atm, but I’ll try this tomorrow.

A question though: My tick method needs a float parameter. If I use this->schedule(cocos2d::SEL_SCHEDULE(&View::tick), 1.0f, kCCRepeatForever, 0); , what value will the parameter be? Will it take the value of the interval parameter and be 1.0f?


Hi, I just tried it and got a different error: Reference to non-static member function must be called?