Separating events from framerate, and font issues.

0 favourites
  • 12 posts
From the Asset Store
Minimal Sprite Font with Stroke for Pixel Art games.
  • Hi there,

    I have an issue with a few things that are all related.

    I'm making an Incremental/Idle game to learn C2 along the way.

    The income is tied to tick rate, which is affected by framerate. It seems that deltatime is a better option, but there's not many tutorials and I'm still confused about where to put it.

    Currently income from one unit works like this:I think to use deltatime it needs to be something like ((Buy1Value*Buy1Stock)/60)/(dt*60), that works but is still effected by framerate.

    The /60 can be removed, it's just to update the income quickly.

    I've heard I can use Every x Seconds but that seemed to be affected by framerate too.

    Using a font and updating text every tick is lagging the game (and income).

    I'm trying to use a webfont but it isn't loading on people's browsers, only people who have the font locally.

    I've heard I should swap over to a sprite font, I've added one but not sure how to actually use it without replacing loads of text objects, will be a lot of work unless there's an easier way.

    Last thing is a small bug, I'm using Scroll To when user presses a button, when it changes the view, the mouse no longer created particles on click. Not a big thing but it's confusing me.

    Any help appreciated.

    Download of file:

    If you download the project file, my example picture of the income is in the Buy1 event group (which is building 1 within the game).

  • If you'd like people to be able to help, it's not a good idea to have third party plugins..

    yours has:



    Both not used by many users and as such the capx can't be opened by them..

  • I've updated the download link to remove them. I just deleted the events/spritefont+ object, so I'm not 100% sure if that worked.

  • For the time:

    dt is the time between the last frame and the current one. It's used in cases where this makes sense:

    rate * time = amount

    For example say a car is going 100 pixels per second then the distance it moves in a frame is

    100*dt = distance

    In the same way if your rate of earning money is (Buy1Value*Buy1Stock) and you can find the amount you earn per tick with:


    Now if you want to update the money with a "every x seconds" then "x" is the time you multiply by instead of dt.

    Every 1.0 seconds

    add (Buy1Value*Buy1Stock)*1.0 to money

    Both are framerate independent, and you should get the same amount added per second either way.

    For the text:

    If you want to switch over to spritefonts, which are faster at rendering, you'll have to manually change everything over. You can keep the normal text objects instead and make it a bit faster if you set "webgl" to off, but that may not be an option if you want to use effects.

    And lastly the mouse "bug":

    Mouse.x and mouse.y use the mouse position on the first layer. I haven't opened your capx but I'd assume the first one is the hud which doesn't scroll. You can use the Mouse.x("layer") expression instead to get the mouse on the layer that scrolls instead.

  • Ah R0J0hound, thanks, the mouse thing was correct, was drawing them to a hud layer.

    Just fixing the time now, ty.


    That works, but when I go in debug mode and lower the frame rate, it seems affected by frame rate and I have no idea why,

    This is the same, works but affected by frame rate still.

  • In what way is it affected by the framerate? Is the result lower than you expect?

  • For some reason debug mode lags for me, but it makes testing this easier.

    Normal preview is 60fps, adds +1 money per second.

    Debug preview is around 20fps, adds +1 money every 3 seconds roughly.

    Is the dt command supposed to be in a tick event? or separate.

  • "dt" is framerate independent. In a simple example this should give a value around 1 no matter the framerate:

    global number t=0
    every tick

    add dt to t

    time=1.0 seconds

    text: text=t[/code:c0mzc8r0]

    No idea why you're getting a framerate dependent result. I don't have cvs plugin installed and you use it everywhere so it's essential to your capx. Maybe I'll install it later but I'm lazy.

  • Pretty sure this version has no plugins:

    I use the csv for an array for cleaning up large numbers, but that version above should show the total money, if you buy 1 of the first building you will see it increases differently depending on frame rate.

    And thanks for stuff earlier, helped a lot.

  • If the framerate dips below 10 fps then dt is capped at 0.1 so time passed won't be accurate. Usually you design your game to run much faster than 10fps so that isn't really an issue.

    If you really must have it be correct with a framerate below 10 then you could use the wallclocktime expression.

    Basically add this to the top of your event sheet, and then use mdt in place of dt everywhere else.

    global number mdt=0

    global number prevTime=0

    every tick:

    set mdt to wallclocktime-prevTime

    set prevTime to wallclockTime

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Thanks R0j0, helpful as always. All my issues are fixed.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)