Log in to reply

How do i draw sprites?

  • Was trying to load this in Function.Call(Hash.DRAW_SPRITE, "heisthud", "main_gradient", 0.5f, 0.5f, 0.5f, 0.5f, 0.0f, 255, 255, 255, 1);
    Nothing happens when loading it though, what do i do?

  • @M8T Let me know when you find out, not easy it seems. You will need to put it ontick AFAIK.

  • @JohnFromGWN I have put it on tick

  • @M8T try this


    using System;
    using System.Drawing;

    using GTA;
    using GTA.Math;
    using GTA.Native;

    namespace SimpleSpriteDrawTest
    public class cSimpleSpriteDrawTest : Script
    const string SpriteLibrary = "mySprites";
    const string SpriteName = "mySpriteTexture";

    >    public cSimpleSpriteDrawTest()
            Tick += onTick;
            Interval = 0;
        private void onTick(object sender, EventArgs e)
            // Exits from the loop if the game is loading
            if (Game.IsLoading) return;
        private void DrawSprite()
            // Centre of the screen
            float spriteX = .5f;
            float spriteY = .5f;
            // Get the texture resolution, textureRes.X = width, textureRes.Y = height
            Vector3 textureRes = Function.Call<Vector3>(Hash.GET_TEXTURE_RESOLUTION, SpriteLibrary, SpriteName);
            // Divide those values by the screen resolution to get the required scale values to draw it at normal size.
            // NOTE: The scale values are a percentage of the SCREEN size, not the SPRITE size... 1f = Draw the sprite the size of the screen
            float scaleX = textureRes.X / Game.ScreenResolution.Width;
            float scaleY = textureRes.Y / Game.ScreenResolution.Height;
            // Set the rotation to 0
            float rotation = 0f;
            // Set the colour to white
            Color col = Color.White;
            // Has the texture library loaded?
            if (Function.Call<bool>(Hash.HAS_STREAMED_TEXTURE_DICT_LOADED, SpriteLibrary))
                // If Yes, draw the sprite
                Function.Call(Hash.DRAW_SPRITE, SpriteLibrary, SpriteName, spriteX, spriteY, scaleX, scaleY, rotation, col.R, col.G, col.B, col.A);
                // If No, request it
                Function.Call(Hash.REQUEST_STREAMED_TEXTURE_DICT, SpriteLibrary, false);


  • @JohnFromGWN Thanks that spawned the texture but im having an issue, is there a way to change the transparency?

  • @M8T research the function. Can you edit the texture and does it even support transparency

  • @JohnFromGWN nvm i dont need the transparency any more. Anyways thanks!

  • @M8T I'm assuming a transparent png would work? For a dds file, you need to play with the alpha channel in image editor (Photoshop) I think. Never tried.

    Anyway, I tried the code myself and it does work. However I'm using SHVDN3, not DN2, so one function had to be changed.

    GTA.UI.Screen.Resolution.Width; insted of Game.ScreenResolution.Width;

    same for the height of course

    Just curious, if you are using a custom sprite, did you create a new YTD file as a library or did you add your sprite to an existing library?

  • @M8T If you ever do need transparency, i just tried it with a transparent png and let OpenIV convert it to dds. Worked fine.
    In passing, have you figured out how to use different fonts, I mean other than the the limited ones in the enum.
    I know there is a file called fontsmap.xml, going to see if I can add additional fonts.
    Monospace is interesting, it draws a rectangle on the screen instead of a period.

    alt text

Log in to reply

Looks like your connection to GTA5-Mods.com Forums was lost, please wait while we try to reconnect.