CLIENT PERFORMANCE, API.worldToScreen lag

  • Used version: Stable and Open Beta

    Explanation of the bug:

    When you use API.worldToScreen to draw for example drawText, drawRectangle or dxDrawTexture.

    The position on screen for the points given by worldtoscreen start to lag and overall jump around.

    This problem is worse when you are driving a car at high speed.


    Steps to reproduce the bug:

    use API.worldToScreen with API.drawText


    Can you reproduce this bug (and how often):

    Always


    Additional information:

    example code,

    Code
    1. API.onUpdate.connect(function() {
    2. var pos = API.getEntityPosition(API.getLocalPlayer())
    3. var point = API.worldToScreen(pos)
    4. API.drawText("player", point.X, point.Y, 0.5, 255, 255, 255, 255, 0, 0, false, true, 0);
    5. })

    Screenshots:

  • onUpdate is not capable to draw textures smoothly per frame.

    There will be an event called every frame, made for stuff like smoothly drawing textures / huds in a future version.
    This is on hold until then.

  • onUpdate is not capable to draw textures smoothly per frame.

    There will be an event called every frame, made for stuff like smoothly drawing textures / huds in a future version.
    This is on hold until then.


    I think there is no problem with onUpdate, it must be worldtoscreen if you use SetDrawOrigin it works perfectly fine. it updates

    smoothly. albeits it starts to lag if you are drawing many texts. probably due to native performance.

    Code
    1. API.onUpdate.connect(function() {
    2. var pos = API.getEntityPosition(API.getLocalPlayer())
    3. //var point = API.worldToScreen(pos)
    4. API.callNative("SET_DRAW_ORIGIN", pos.X, pos.Y, pos.Z, 0);
    5. API.drawText("player", 0, 0, 0.5, 255, 255, 255, 255, 0, 0, false, true, 0);
    6. API.callNative("CLEAR_DRAW_ORIGIN");
    7. })
  • For recurring Text to be drawn I strongly recommend using addTextElement instead.

    It's running outside the ClientScript and does not impact perfomance that much.


    It's not recommended to do anything in onUpdate that takes longer than 100ms.