rendering.draw_sprite - example of usage?

Place to post guides, observations, things related to modding that are not mods themselves.
anothersillyaccount
Manual Inserter
Manual Inserter
Posts: 2
Joined: Sun Mar 31, 2019 2:39 pm
Contact:

rendering.draw_sprite - example of usage?

Post by anothersillyaccount »

Hi

I'm exploring the rendering API so a simple example I chose was to draw a image near the player on the ground. I created a mod to hold the image because I needed a place to hold it. I tried using a scenario but it made no difference.

How do I draw a sprite?

This doesn't work:

Code: Select all

rendering.draw_sprite{sprite="file/__mypictures__/graphics/image1.png", 
  target = player.position,
  surface = player.surface,
  time_to_live = 60}
Do I need to create something like this: (eg in mypictures_0.0.1/data.lua)

Code: Select all

data:extend ( { 
    {
    type = "sprite",
    name = "image1",
    filename = "__mypictures__/graphics/image1.png",
    priority = "extra-high",
    flags = {"no-crop" },
    width = 213, height = 158
  },
This is what I was expecting to work based on having the entry in data.lua

Code: Select all

rendering.draw_sprite{sprite="file/image1", 
  target = player.position,
  surface = player.surface,
  time_to_live = 60}
I tried using a scenario for this but that made no difference.

From what I can tell I don't understand how SpritePath works but I'm sure there's something else. The wiki doesn't mention it other than in passing. lua-api does. But I can't figure it out from that description. Do I use "file/image1" for sprite? "file/image1.png"?

Or is this the wrong approach?
eduran
Filter Inserter
Filter Inserter
Posts: 344
Joined: Fri May 09, 2014 2:52 pm
Contact:

Re: rendering.draw_sprite - example of usage?

Post by eduran »

anothersillyaccount wrote: Sun Apr 28, 2019 10:49 pm Do I need to create something like this: (eg in mypictures_0.0.1/data.lua)
Yes, you do. Sprites have to be defined at the data stage.
anothersillyaccount wrote: Sun Apr 28, 2019 10:49 pm This is what I was expecting to work based on having the entry in data.lua

Code: Select all

rendering.draw_sprite{sprite="file/image1", 
  target = player.position,
  surface = player.surface,
  time_to_live = 60}
sprite="image1" should work, that is the "name" property you gave to the sprite. No file/ prefix needed.
anothersillyaccount
Manual Inserter
Manual Inserter
Posts: 2
Joined: Sun Mar 31, 2019 2:39 pm
Contact:

Re: rendering.draw_sprite - example of usage?

Post by anothersillyaccount »

Looks good. thanks for the clarification.
Post Reply

Return to “Modding discussion”