1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. GTA Network forum is now in archive mode.

Sprite Loader

Discussion in 'Libraries/Wrappers/Web' started by Stuyk, May 5, 2017.

  1. Stuyk

    Stuyk Active Member Public Relations Developer

    Messages:
    81
    Likes Received:
    76
    Joined:
    Jan 12, 2017




    What does this do?
    Let's you easily add in animated sprites to play over your screen / on screen.
    This is technically a way to easily implement 2d animated elements into your game mode.

    How?
    Code:
           let sprite: Sprite = resource.sprite_loader.newSprite(); // Create a local variable to hold our Sprite instance.
            sprite.TicksPerFrame = 4; // How many ticks before we move to the next frame. (4 is default);
            sprite.Width = 576; // Width of Frame or Size
            sprite.Height = 576; // Height of Frame or Size
            sprite.XPos = 500; // Position on Screen X
            sprite.YPos = 500; // Position on Screen Y
            // This is where we add all of our clientside frames. You must also add these into your meta.xml
            sprite.AddFrame = "clientside/resources/images/effect/effect_00.png";
            sprite.AddFrame = "clientside/resources/images/effect/effect_01.png";
            sprite.AddFrame = "clientside/resources/images/effect/effect_02.png";
            sprite.AddFrame = "clientside/resources/images/effect/effect_03.png";
            sprite.AddFrame = "clientside/resources/images/effect/effect_04.png";
            sprite.AddFrame = "clientside/resources/images/effect/effect_05.png";
            sprite.AddFrame = "clientside/resources/images/effect/effect_06.png";
            sprite.AddFrame = "clientside/resources/images/effect/effect_07.png";
            sprite.AddFrame = "clientside/resources/images/effect/effect_08.png";
            sprite.AddFrame = "clientside/resources/images/effect/effect_09.png";
            sprite.AddFrame = "clientside/resources/images/effect/effect_10.png";
            sprite.AddFrame = "clientside/resources/images/effect/effect_11.png";
            sprite.AddFrame = "clientside/resources/images/effect/effect_12.png";
            sprite.AddFrame = "clientside/resources/images/effect/effect_13.png";
            sprite.LoopAmount = 1; // How many times would you like this to loop? (0 loops forever);
            sprite.ready(); // Lets our sprite manager know the sprite is ready to be drawn.
    
    Download
    Github
     
    Last edited: May 6, 2017
  2. MrPancakers

    MrPancakers Active Member

    Messages:
    90
    Likes Received:
    19
    Joined:
    Aug 2, 2016
    I'm not a pro but just observing, with all your sprite.AddFrames, the only thing changing is the image name (00 to 13), is there a way to just make it a for loop so you don't have to just add every single line? A for loop for example that loops through 14 times.

    If you can't do that then ignore this lol
     
  3. Stuyk

    Stuyk Active Member Public Relations Developer

    Messages:
    81
    Likes Received:
    76
    Joined:
    Jan 12, 2017
    You could probably create a loop yourself and do it. I mean...
    Code:
    for (var i = 0; i < frameCount; i++) {
         sprite.AddFrame(`myfilename_${i}.png`);
    }
    
     
  4. MrPancakers

    MrPancakers Active Member

    Messages:
    90
    Likes Received:
    19
    Joined:
    Aug 2, 2016
    Oh I know we could change it ourselves, it was just a suggestion to minimise lines in the code instead of copy/pasting the same line over and over. It's a neat script though!
     

Share This Page