1. Hey Guest, is it this your first time on the forums?

    Visit the Beginner's Box

    Introduce yourself, read some of the ins and outs of the community, access to useful links and information.

    Dismiss Notice

[Solved] Sprite's onRender v.s. onTick

Discussion in 'Modding Help' started by Vermilicious, Mar 9, 2016.

  1. Vermilicious

    Vermilicious Ballista Bolt Thrower

    Messages:
    232
    Quick question this time :o)

    So far I understand that GUI-calls needs to made in onRender, and Geti once wrote in another forum thread, in a code example, that onRender might be called "more often that we'd like". How does onRender actually relate to onTick? It's been said that the game runs at a fixed 30 ticks, or "frames" as I've so far thought about it. Should I stop thinking that way because onRender may be called more often than that, like 60 or whatever frame rate the graphics card may produce?
     
  2. Verrazano

    Verrazano Flat Chested Haggy Old Souless Witchy Witch Witch THD Team Global Moderator Forum Moderator Tester
    1. Practitioners of War Extreme Revolution - POWER

    Messages:
    477
    You may have missread what he said. The reverse is more true. onTick can happen multiple times a frame, where onRender will only happen once a frame after all the necessary onTick calls happen. This is because of how the time step system works, it uses an accumulator, and when the accumulator greater than the time per a frame it can do a number of ticks (equal to the accum/frametime), but the partial dt remains in the accumulator.

    It's best not to consider how fast something is happening in real time, but rather in number of ticks for this reason. For example a computer that is very slow (like really really really slow) would have many ticks before it renders a frame since the dt between frames is large.

    http://gafferongames.com/game-physics/fix-your-timestep/
     
    Last edited: Mar 9, 2016
  3. Geti

    Geti Please avoid PMing me (poke a mod instead) THD Team Administrator Global Moderator

    Messages:
    3,730
    Uh there's also the potential (more likely, actually) for it to be running onRender quite a lot (like 100s of times a second) if someone is using uncapped framerate, or a steady 60fps (or whatever your monitor updates at) with vsync and uncapped frames.
    You should definitely do NO "UPDATE" LOGIC WHATSOEVER in onrender, just rendering logic.
     
    Vermilicious likes this.