Prototyping 2D games with customizable shapes

Hi everyone,

I get that the Sprite component requires an Image (atlas) and a Default animation (defined as part of the atlas). I was thinking that would be nice to have some default shapes (triangle, circle, rectangle, etc) that we could pick as an alternative to creating an atlas. That would be used to rapidly prototype mechanics without relying on pre-existing art. So my question is: how can I create (either using code or the editor) game objects defining shape and color instead of depending on pre existing art?

I just started learning Defold, so maybe I’m missing some workflow knowledge.

Thanks in advance.

1 Like

We’ve discussed different ways to provide basic drawing primitives for prototyping. One option would be to ship an atlas containing some basic shapes in the builtins folder that comes with each project. This could be solid rectangles, squares, triangles and circles of various shapes. Or we could ship an atlas with some art from Kenney.nl (https://kenney.nl/).

Another alternative is that we provide a few variations of mesh components in builtins for the different shapes.

And a third option is some basic model components. This option is discussed in the following PR: https://github.com/defold/defold/pull/5138

The above alternatives are definitely things we’d like to discuss and work out with community members such as yourself to ensure that we provide meaningful prototype assets. I’d be happy to hear more input from the community on this!

2 Likes

I think that plus a color picker in the editor would be great!
Thanks for the quick reply! :smiley:

2 Likes

I was taking a look at the rendering API and noticed that there’s a draw_line function. Is there a reason to not include others such as: set_pixel, draw_rect, draw_triangle, draw_circle, etc?
Phaser, for example, has a Graphics class that allows to draw primitives and then generate a texture out of it (to improve performance). This can be useful to quickly draw things over a sprite for debugging or to programmatically generate grids.

I know that the community already produced some helpers

but it would be nice to have those features out of the box. I think the community solutions don’t produce textures to enhance performance (they redraw everything on each frame).

I was thinking about @britzl’s idea of adding a built-in atlas, which would be nice, but I suppose that wouldn’t allow us to define the size of each shape without scaling the assets, whereas drawing primitives would allow to define width and height without having to stretch art assets.

Again, please take my suggestions with a grain of salt since I just started to look at Defold, its features and workflows.

We’ve considered those functions as debug functions and haven’t really been happy with them. What we would want if anything is something more fleshed out and put in its own namespace, like the drawpixels extension. Perhaps a new component type? But then again, we could achieve something like this using the mesh component as well (like I suggested in my second option).

2 Likes

This doesn’t really answer the OP’s question, but I’ve been doing a lot of prototyping over the past 2 weeks and I have a dedicated folder of placeholder sprites that I pull from whenever I need them. I make them by opening an art program and filling the image with a flat colour.

Once they’re made I don’t have to make them again, and I find it pretty convenient. If you don’t want to make them yourself (or just want something prettier) then filling this folder with Kenney sprites or something similar also works.

1 Like

Good point, in this video for example the author used a quad.dae model in a model component.

I haven’t tried yet, is it possible to programmatically create a mesh + texture?

You should be able to find some information to get you started here: Mesh Component and here: https://defold.com/manuals/mesh/

2 Likes

I have a template project that I copy when starting a new project, which includes an atlas with some basic shape sprites. It’s not as convenient as a built-in default would be, but lacking that I think it’s the best option.

In case you don’t feel like fiddling with an image editor, here are the textures I use: cross, circle, square, triangle (warning: they’re not very consistent in size). textures.zip (50.6 KB)

It would be cool if the editor let you set per-project defaults for certain things. Like the default atlas & image for sprites. It could speed up workflow a lot (copy-paste can work, but not in every situation).

3 Likes