Hi everyone ? My game use box2d physic with Cocos2d-x v3.10 . And it very lag when I play sound on jump action (when I remove the sound , the lag is less) . Help me pls , thank .
with sound :
gameplay_with_sound
without sound :
gameplay_without_sound
What is the format of your sound?
if it’s mp3 then change it to wav.
Is your sound play once in every jump?
Your video is not suitable for us, some code please! ;D
my sound format is wav ! Why my video is not suitable , you cant play it or it get some error when open ?
I don’t know which code have problems . Can we talk more detail on Skype or Facebook . Thank for help . (I have try to fix this bug for 5 days) I really need help . Thank again
Your video is OK. ;D
but post some code.
we can’t help you if we don’t have any code!
this is my update function :s . I load the tile map tilemap.zip (31.9 KB) to the game , and load each object when the char com close to it .
/*while (accumulator > kSecondsPerUpdate)
{
accumulator -= kSecondsPerUpdate;
world->Step(kSecondsPerUpdate, 8, 1);
worldstepped = true;
}
lastTickTime = currentTime;*/
I try fixed time step but things become worse. So I do the step normally
void GameScene::update(float dt)
{
//viewpoint
setViewPointCenter();
//load map
//object
if (!mapobjects.empty())
while (mapobjects.back()->pos.x - mapobjects.back()->size.width / 2 < mainchar->getPositionX() + visibleSize.width * 1.5f)
{
auto temp = mapobjects.back();
temp->deloyObject();
delete temp;
temp = NULL;
mapobjects.pop_back();
if (mapobjects.empty()) break;
}
//load new map - load map moi khi diem cuoi map cu cach char 1.5visiblesize.w
if (mainchar->getPositionX() > currentmap->getPositionX() + currentmap->getContentSize().width - visibleSize.width*1.5f)
{
loadNextMap();
}
//remove old map - xoa map cu khi char cach map cu visiblesize.w
if (mainchar->getPositionX() > currentmap->getPositionX() + visibleSize.width)
{
if (previousmap != nullptr)
{
previousmap->removeFromParent();
previousmap = nullptr;
}
//CCLOG("delete unuse map");
}
//physics step
accumulator += dt;
bool worldstepped = true;
world->Step(dt, 8, 1);
if (worldstepped)
{
for (b2Body *body = world->GetBodyList(); body != NULL; body = body->GetNext())
{
if (body->GetUserData())
{
Sprite *sprite = (Sprite *)body->GetUserData();
sprite->setPosition(Point(body->GetPosition().x * SCALE_RATIO, body->GetPosition().y * SCALE_RATIO));
sprite->setRotation(-1 * CC_RADIANS_TO_DEGREES(body->GetAngle()));
}
if (body->GetType() == b2_staticBody)
{
auto shape = (b2PolygonShape*)body->GetFixtureList()->GetShape();
auto shapesize = shape->m_vertices[0];
if (body->GetPosition().x * SCALE_RATIO - shapesize.x * SCALE_RATIO + visibleSize.width / 2 < mainchar->getPositionX())
{
bodyScheduledForRemoval.push_back(body);
}
}
else
{
if (body->GetPosition().x*SCALE_RATIO < mainchar->getPositionX() - visibleSize.width)
{
bodyScheduledForRemoval.push_back(body);
}
}
}
}
world->ClearForces();
deleteTrash();
//end game condition
}
thank for reply . I really need help . Thank again
hey guys !
pls help my problems pls . thank . I really need help . I think this is a big bug of cocos
and need to be fixed.
Do you use SimpleAudioEngine to play the sound effects?
If so, you could try to preload the sound effects by calling preloadEffect() if you do not already do that. It should help avoid lag.
I’ve already preload the sound ! still lag
I have followed this issue for a long time (from v 2.x)… Until today I have another companion… 
…
While waiting for the resolution…
void GameScene::update(float dt)
{
//TRY NOT USING "dt" IN ANYWHERE.. Using a constant number instead... (for ex: 1.0/60.0 )
//you will get the much better performance
}
You right . It make performance better . But on android , when the fps drop , the game will be slower
. I try to you fixxed time step but thing get worse . I don’t know where is the problems. Pls someone help me
Solved ! Fool me , not the cocos2d-x or box2d problems . I just move the setViewPoint center to behind the render stage , the problems solved.