0
\$\begingroup\$

I'm making a multiplayer game which involves drawing lines. It's based this game: http://curvefever.com/sites/default/files/resize/remote/ef86488088c618df13b34f8b87aafd4e-1107x808.jpg. The game is setup so each "worm" has an own bitmap. All these bitmaps then get drawn in another single bitmap for best performance. Now i'm trying to implement online multiplayer into the game. However I've had some doing struggle implementing online multiplayer. The thing is that I will need to reverse the state of the draw lines in case a packet from the server comes late to the client. The biggest problem is that the drawing needs to be done very fast since the game updates every 20th millisecond. However I figured out and tried some different approaches to this:

-Save the state of the whole context and then redraw it. This is probably the slowest method.

-Only save a part of the context (100x100) in a another bitmap hidden by looping through each pixel, then looping through each pixel from that bitmap to the main bitmap that is shown on the screen.

-Save each point of the drawn path in a some kind of path reference, then when reverting the context, draw this path with the background color (0,0,0,1).

-Saving the position in the bitmap of each pixel that gets drawn in a separate array and then setting that pixel alpha to 0 (in the drawn bitmap) when I need to undo.

The last approach or 2nd one should be the fastest of them all. Are my approaches that I've listed above correct or is there some method that I'm missing that I should use? I've been prototyping my approaches in code above but they have been rendered to slow or they haven't worked.

\$\endgroup\$
  • \$\begingroup\$ The first method is the most common one in usual games where the scene consists of tiles and sprites, but what you have here is not a very usual game. \$\endgroup\$ – Philipp Jan 7 '15 at 8:26
  • \$\begingroup\$ What kind of "canvas" are you talking about? There are lots of different platforms and graphic APIs which use something called a "canvas" but not all have the same performance characteristics and features. \$\endgroup\$ – Philipp Jan 7 '15 at 8:27
  • \$\begingroup\$ yeah I agree. But when I say canvas I the visible bitmap that is shown in the screen. The code is written in Core Graphics which is an api for objective-C. But, It could be ported to openGl if needed even though I prefer Core Graphics. \$\endgroup\$ – Fredrik Jan 7 '15 at 8:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.