sorabh86 / quickb2

Automatically exported from code.google.com/p/quickb2
0 stars 0 forks source link

world.translateBy() slow #33

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
I'm creating online game where a 2D-cyclist is moving along a hand-drawn path 
(simplier version of canvasrider.com). I need to move whole world left/right so 
the cyclist remains centered. While moving world using world.translateBy() 
called from within qb2UpdateEvent.POST_UPDATE handler it's pretty damn slow 
(around 0-10fps). Is there some different way to move world with all of the 
objects inside it?

Thanks

Original issue reported on code.google.com by miroslav...@marmar.sk on 16 Aug 2011 at 2:00

GoogleCodeExporter commented 8 years ago
Translating a whole world will indeed be slow...there's now way to optimize 
that because you have to visit every single object in the game and do an 
operation on it.

A better way is to only move the bicyclist, and just move your "camera" to keep 
the cyclist centered.  The physics will be more accurate this way too.

By the way, move your cyclist by applyForce(), not by translating.

Original comment by doug...@gmail.com on 16 Aug 2011 at 4:39

GoogleCodeExporter commented 8 years ago
Thanks. The cyclist is qb2Group which containcs two qb2CircleShapes and I'm 
applying applyTorque() onto them. He's moving nicely but of course he always 
gets off the stage :) Please is there any tutorial/demo of camera movement? I 
saw the qb2DemoReel but it's unclear there :/ Thanks

Original comment by miroslav...@marmar.sk on 16 Aug 2011 at 4:46

GoogleCodeExporter commented 8 years ago
Ah, yea, applyTorque is a better idea :)

The car driving demo in qb2DemoReel follows the screen, but I understand that 
it's a little complicated.  I intend to make simpler demos, but haven't done so 
yet.

The basic idea is that whenever your cyclist moves forward, the 
DisplayObjectContainer containing your world should move backwards...something 
like this:

worldContainer.x = -cyclist.x + stageWidth/2;

Original comment by doug...@gmail.com on 17 Aug 2011 at 2:39

GoogleCodeExporter commented 8 years ago
Thank you! I've tried it and it works like a charm! ;)

Original comment by miroslav...@marmar.sk on 17 Aug 2011 at 7:33