≡
Products
▼
Support
▼
Company
▼
Forum
Ambiera Forum
Discussions, Help and Support.
Create a new account
,
Search
, or Login:
Create reply in
time counter
Posted by:
(you are not logged in)
Enter the missing letter in: "Intern?tional"
(you are not logged in)
Text:
[quote][b][/b] wrote: Hi, I don't think this solution will really work with lag. In fact, I don't also think that seconds are the real seconds here:) I believe, onAnimate function is executed on screen draw, which in normal case happens every ~17 ms. Check this part: [code]if(this.now > this.endTime) { this.count += 1; ccbSetCopperCubeVariable("time", this.count); this.endTime = this.now + this.CountRate_Ms; }[/code] So let's say we start at 0 ms for simplicity (even though it's actually int representation of the current local time): 1. On the first run this.now is 0 and the code is not executed 2. On the second run it's 17 and nothing happens still 3. On 60th run it's 1020 ms, and now it enters the if block. On the last line of it, we're adding another countRate value (which is 1000) and get 2020ms - so our second is shifted by 20 ms in the first loop. If expect a precise second to count - condition should be "this.now === this.endTime". If you lag, which means your framerate drops, or run 30 fps this shift will increase even more. From the other hand, if your application froze for 1000 ms this second will be lost from the counter because of this.now + this.countRate_ms. You can easily test this by alttabing from game and alttab back then. I guess, on the last line you should do this.endTime += this.CountRate_Ms; Or why not to use a built in timer, by just assigning the difference between game start and current time in seconds to some variable, like: [code]behavior_timer = function () { this.initTimeMs = null; }; behavior_timer.prototype.onAnimate = function (node, timeMs) { if (this.initTimeMs !== null) { this.initTimeMs = timeMs; return; } ccbSetCopperCubeVariable('timer', Math.floor((timeMs - this.initTimeMs) / 1000)); }[/code][/quote]
Possible Codes
Feature
Code
Link
[url] www.example.com [/url]
Bold
[b]bold text[/b]
Image
[img]http://www.example.com/image.jpg[/img]
Quote
[quote]quoted text[/quote]
Code
[code]source code[/code]
Emoticons
Copyright© Ambiera e.U. all rights reserved.
Privacy Policy | Terms and Conditions | Imprint | Contact