chris1986m Posted March 4, 2015 Share Posted March 4, 2015 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 comment Share on other sites More sharing options...
valueerror Posted March 4, 2015 Share Posted March 4, 2015 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 comment Share on other sites More sharing options...
CtlAltDel Posted March 4, 2015 Share Posted March 4, 2015 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 comment Share on other sites More sharing options...
valueerror Posted March 4, 2015 Share Posted March 4, 2015 since the physics and the rendering are not coupled anymore in phaser 2.2.2 my game would still run at the configured 50fps physics frames per second.. in one point you are right though.. my meter-meter would run twice as fast i'm definitely going to fix that Link to comment Share on other sites More sharing options...
chris1986m Posted March 4, 2015 Author Share Posted March 4, 2015 Thanks for your replies. I think too, that Twen and interval more critical is than an Update in the game Loop. I'll try to reduce the Code to get a better Performance. Link to comment Share on other sites More sharing options...
valueerror Posted March 5, 2015 Share Posted March 5, 2015 if you really have performance problems i highly doubt that these come from your distance counter... but just in case.. someone told me to use "bitmap fonts" for text because normal text (i can't imagine why) is slow compared to bitmap fonts !?! Link to comment Share on other sites More sharing options...
chris1986m Posted March 5, 2015 Author Share Posted March 5, 2015 This is a Great hint. After development and before compiling to cocoonjs, i'll change fonts to bitmap. Thanks Link to comment Share on other sites More sharing options...
ZoomBox Posted March 5, 2015 Share Posted March 5, 2015 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 comment Share on other sites More sharing options...
valueerror Posted March 5, 2015 Share Posted March 5, 2015 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 comment Share on other sites More sharing options...
ZoomBox Posted March 5, 2015 Share Posted March 5, 2015 Yep I agree. I was using Cordova/Phonegap for my project so no "canvas+" optimization (and constraints). Link to comment Share on other sites More sharing options...
Recommended Posts