Quantcast
Channel: Cocos Forums - Latest topics
Viewing all articles
Browse latest Browse all 17070

Chipmunk lag with cocos-js v3.6

$
0
0

@ofreyre wrote:

Hi,

I´m developing a very simple game like flappy bird, but with two characters. One on top another. The user applies impulse to the bottom character. Of couse, if the bottom character collides with the top one, chipmunk will do it's work.

I'm not using physics sprites for characters, but sprites associated with bodies by code.
I move the bottom character by code, bottomsprite.x+=speed*deltatime, each frame on update funtion.
Then I set its body x position to sprite.x, but leave its body y to chypmunk's control: body.setPos(bottomsprite.x, bottombody.getPos().y).
I do the same for the top character so it stays just ontop of the bottom character:
body.setPos(bottomsprite.x, topbody.getPos().y).

In this way I control x coordinate, of both characters, enssuring they are always at the same x, and leave y coordinates to chipmunk so gravity can act on them.

Both sprites move smoothly, but sometimes (I thinks when both characters collide), there is a bit of lag.

I don't know if this lag is because I'm setting x coordinates of the bodies, and this can cause numeric inconsistencies in chipmunk, or if is there something else that I'm doing wrong.

My chipmunk step code is:

acumulator+=delta;
while(acumulator>fixedStep){
acumulator -= fixedStep;
space.step(fixedStep);
}

where fixedStep = 1/60

I have tested it on web, ios and android, and the framerate is never bellow 59, most of the time 60. The worst performance is on Android.

Thanks for your help.

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 17070


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>