Good way to do animations with Cocos2D?

I am making a small iphone game and I would get some tips. Imagine:

Two background sprites move quite quickly from right to left and move up and down using an accelerometer.

I think I can’t use the animations here because the background movement is recounted in every frame. Therefore, I use a schedule with an interval of 0.025 and move the sprites on each hour with:

sprite.position = ccp(x, y);

So here is my problem: the result of laggy, with only these two sprites.

I tried both declaring sprites in the header and getting them using CCNodes and tags. This is exactly the same.

So, if someone can give me a hint that this is the best way to do this, that would be so nice. Interestingly, it’s not a problem that sprites move very fast, but I'm not sure.

Anyway, thanks for your time.

J.

+3
source share
2 answers

0.025 40 /, . . , , , , . , , . ( : 40 25 . - , ? - 20 . 10-20 .)

, . :

const int kDesiredModelFramerate = 50; // fps
const double kDesiredFrameTime = 1.0/kDesiredModelFramerate;

double now = CFAbsoluteTimeGetCurrent();
double delta = now - lastFrameTime;
double correction = delta/kDesiredFrameTime;
[object setX:object.x + step*correction];

, . 40 , , "", 50 20 . correction 0.04/0.02 = 2, 2, . , , - , .

<voice class="Simon Peyton Jones"> ? </voice>

, . . Cocos2D , . .

+3

Cocos2D "", time_elapsed, . , , DOUBLE, double-to-float.

"tick" CCLayer Cocos2D.

-(void) tick: (ccTime) dt
{
  static float time_elapsed = 0.0;
  time_elapsed += dt;

  ...

  float velocity = 5.0f * cosf(time_elapsed * 2 * M_PI) ;
  jPrism->SetMotorSpeed( velocity );
}
+1

Source: https://habr.com/ru/post/1737932/


All Articles