Page 1 of 1

rendering.draw_sprite - example of usage?

Posted: Sun Apr 28, 2019 10:49 pm
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?

Re: rendering.draw_sprite - example of usage?

Posted: Mon Apr 29, 2019 7:15 am
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.

Re: rendering.draw_sprite - example of usage?

Posted: Mon Apr 29, 2019 9:33 am
by anothersillyaccount
Looks good. thanks for the clarification.