# Dynamically created sprites

**URL:** <https://forum.defold.com/t/dynamically-created-sprites/2590>\
**Category:** Questions\
**Created:** [August 10, 2016, 1:20pm UTC](https://forum.defold.com/t/dynamically-created-sprites/2590 "2016-08-10T13:20:01Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![benjames171](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/benjames171/32/34759_2.png) [@benjames171](https://forum.defold.com/u/benjames171)\
**Post date:** [August 10, 2016, 1:20pm UTC](https://forum.defold.com/t/dynamically-created-sprites/2590/1 "2016-08-10T13:20:01Z")

</div>

I’d like to dynamically create a mini-map for my game. Is there any way to create a sprite on-the-fly so to speak? I only want something simple as in setting the pixels for the walls and solid scenery and transparent for everything else.

---

<div class="post-metadata">

**Author:** ![sicher](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/sicher/32/8_2.png) [@sicher](https://forum.defold.com/u/sicher)\
**Post date:** [August 10, 2016, 1:30pm UTC](https://forum.defold.com/t/dynamically-created-sprites/2590/2 "2016-08-10T13:30:23Z")

</div>

You can’t do that with sprites, but GUI nodes can be used. See [API reference (GUI)](http://www.defold.com/ref/gui/#gui.set_texture_data:texture-width-height-type-buffer)

---

<div class="post-metadata">

**Author:** ![benjames171](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/benjames171/32/34759_2.png) [@benjames171](https://forum.defold.com/u/benjames171)\
**Post date:** [August 10, 2016, 1:40pm UTC](https://forum.defold.com/t/dynamically-created-sprites/2590/3 "2016-08-10T13:40:29Z")

</div>

That looks like just what I need - thanks!

---

<div class="post-metadata">

**Author:** ![sven](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/sven/32/1086_2.png) [@sven](https://forum.defold.com/u/sven)\
**Post date:** [August 10, 2016, 1:41pm UTC](https://forum.defold.com/t/dynamically-created-sprites/2590/4 "2016-08-10T13:41:18Z")

</div>

You could also have a look at this thread:

> [@Texture sampling in procedural GUI textures? (SOLVED)](https://forum.defold.com/t/texture-sampling-in-procedural-gui-textures-solved/1973):
>
> I’m trying to create some procedural textures for a minimap system, and noticing that the upscaled 10x10 checkerboard texture shown in the screenshot is being rendered with linear filtering. As is visible, rendering is set to nearest in game.project which is reflected in the game sprites but not in the procedural texture. GUI textures such as the item and status icons render with ‘nearest’ sampling as well. Is there a way to set the sampling of textures created with gui.new\_texture()? [image]

---

<div class="post-metadata">

**Author:** ![Ragnar\_Svensson](https://forum-defold.b-cdn.net/letter_avatar_proxy/v4/letter/r/b5ac83/32.png) [@Ragnar\_Svensson](https://forum.defold.com/u/Ragnar_Svensson)\
**Post date:** [August 11, 2016, 8:54am UTC](https://forum.defold.com/t/dynamically-created-sprites/2590/5 "2016-08-11T08:54:59Z")

</div>

I think @Lukas_Palmer did something similar in the labyrinth game.

---

<div class="post-metadata">

**Author:** ![Lukas\_Palmer](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/lukas_palmer/32/722_2.png) [@Lukas\_Palmer](https://forum.defold.com/u/Lukas_Palmer)\
**Post date:** [August 11, 2016, 12:29pm UTC](https://forum.defold.com/t/dynamically-created-sprites/2590/6 "2016-08-11T12:29:58Z")

</div>

Yup! Just be careful when you make the texture string- since you have to append strings for each bit of pixel data a ton of times, the complexity of making the texture can grow quickly. If you’re making a higher resolution texture, I’d recommend using some sort of string builder to keep the game’s performance smooth.

---

<div class="post-metadata">

**Author:** ![britzl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/britzl/32/23_2.png) [@britzl](https://forum.defold.com/u/britzl)\
**Post date:** [August 11, 2016, 7:55pm UTC](https://forum.defold.com/t/dynamically-created-sprites/2590/7 "2016-08-11T19:55:08Z")

</div>

String concatenation (using ..) can become quite expensive. For a large amount of strings it might be better to do `table.concat(strings, "")` instead. And perhaps also do it over several frames.
