Jump to content

Best performance for game score and distance


Recommended Posts

Hi guys,

 

do you know what's the best solution for a well performed game with automatically  increasing game score and distance like other endless scroller?

 

I've two different ways tested. In reality, the code looks something different. I do not know memorize everything. The important part is the function calling. In update game loop or with different timer parallel...

 

1.

- Update distance every time in game loop (update()). 60 times, every second, the player moves a few px. This is a value between 0.3 and > 2, depending on the game speed.

- Update score every time in game loop (update()). 60 times, every second, the score increase. This value starts with 0, depending on distance and a multiplier.

 

2.

- Update distance every time in game loop (update()). 60 times, every second, the player moves a few px. This is a value between 0.3 and > 2, depending on the game speed.

- Save all in a distanceTotal variable

- Built a interval timer (create()) with 500ms to check score and make data tween (600ms) for a nice counter animation. Update score depends on distanceTotal-oldDistance, to tween the correct new score value.

 

I think number 2 is faster than the other, but i'm not sure. We dont have a score checking and updating 60 times per second. But a second parallel running timer 2 times per second and a tween for the count animation. There could be a problem with the total game score.... i update the score every 500ms, but what when game ends between the interval?

In number 1 i dont need a tween, because the update is so fast.

 

Are there better solutions or is this the correct way?

 

I would be very happy for some hints.

 

Regards,

Chris

Link to post
Share on other sites

interesting.. i haven't give much thought into it..  for now i just do this on every update (60 times a second)

distance += 0.1;leveltext.text = 'meters: '+Math.floor(distance);

do you think this is not good for performance?  

i mean..  the text gets rendered on every frame anyway so the one thing that probably uses cpu power would be leveltext.text and Math.floor  (i could implement an IF statement before the text update and only update on an even number but calling Math.floor is probably as expensive and leads to the same result.)

 

i believe that a tween is much more expensive than that, also a interval timer...  but it definitely sounds like it would look better :)

 

Link to post
Share on other sites

If you want an accurate distance not based on your update speed I suggest not doing a static += 0.1 every frame, but move your character a distance based on the time elapsed etc. Your game would otherwise be blazing fast on 120 fps for some people that have monitors with that refresh rate :)

Link to post
Share on other sites

I often use html text for those kind of things.

 

It's quite boring to have 2 "ways" of thinking in my code (since I have Phaser objects and HTML ones) but it has no performance issues.

And I'm used to only update score (and continuous things like that) every 10 or 20 frames only.

 

It's more pleasant to the eye and I suppose it's less ressources consuming.

Link to post
Share on other sites

well ... especially if you consider working with cocoonjs you need to know that cocoonjs is not able to use bitmap fonts without a custom xml parser..  also canvas+ delivers only  the canvas element..  so everything DOM related will not work afaik.

also styling the canvas with shadows for example will lead to a huge performance problem so i dare to say your 2 way approach will probably lead to some problems on mobile.. not definitely but it could :)

 

updating the text is not the problem IMHO.. i think it's a very cheap function..  the text is still going to be rendered 60 times a second.. it doesn't matter how it looks like (if there is a "1" or a "2" or an "A" does't matter at all)

 

if you consider using cocoonjs with webview you lose the huge performance boost canvas+ offers - if so i recommend having a look at intel crosswalk too..  it doesn't require any hacks and has no problem with bitmapfont, buttons, anchors, webgl, etc.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...