Ask here your questions to get help using GDevelop.
By komencanto
#45093 I want to draw a square on the screen where I clicked. I'm using Primitive Drawing tool for that. But I can draw only one square. When I clicked in the other place the previous square just disappears. So, how to make it stay on the screen?
Here is my event sheet:
drawing.png
drawing.png (10.18 KiB) Viewed 3123 times
User avatar
By Lizard-13
#45114 The problem is: GD replaces the old variable "x" and "y" values with the new ones, so you have only two values to draw, and one instruction to draw; The drawers don't remember old draws, you have to add a draw action every frame for every draw :|

Ok, I think I can help you, check this out:
Simple multi-rectangle draw
(22.38 KiB) Downloaded 194 times

De/activate the first and second event to check both of them work: The first one add a new variable to a struct with each click (each variable of the struct stands for a rectangle), then one DrawerObject draw a rectangle for each variable in the struct. The second add a new DrawerObject with each click and save some values on it (object variable), then each DrawerObject draw its rectangle in function of its own variables :ugeek:

Excuse me if the first option (with struct variables) is a bit complex (you know I like the complex things) :twisted:
The second option with multiple drawer objects is a bit easier ;)
By komencanto
#45122 Yes, complicated... but it works. :)
And thanks for example of using structure variables! Couldn't figure it out on my own.
I just curious about if these methods would be too demanding on the computer memory. As I understood you need to keep in a memory coordinates of Every created object on the screen. And color... and other possible attributes....
In another post you recommended to use a panel sprite for drawing. Will it be less memory consuming? Still you'll end up with a bunch of panel sprites which could slow down the program, I think.
The goal is just to draw with mouse/keys simple shapes/scribble on the screen or make a pixel art drawing. Maybe GD is not suitable for this kind of stuff. The python's turtle is perfect for this. The Scratch's drawing tool is less capable but still usable too. In the CC's example you can draw on the canvas, resize it and save the resulting picture.
User avatar
By Lizard-13
#45162 First of all, check this, it's possible:
Basic Draw System
(7.24 KiB) Downloaded 146 times


In another post you recommended to use a panel sprite for drawing. Will it be less memory consuming? Still you'll end up with a bunch of panel sprites which could slow down the program, I think.

Yeah, I recommended panel sprites because you wanted control over it (drag-and-drop basically)... but "opening my mind" ( :lol: ) now I could even think in drag-and-drop over struct variables *1
About the memory consuming: The order could be: Structure (bad performance) --> Multiple Drawers --> Panels/Sprites *2

The goal is just to draw with mouse/keys simple shapes/scribble on the screen or make a pixel art drawing.

Yes, multiple draws should work ;)
If you need to move the shapes (basic control), structures could work.
If you need to rotate them (high control), you'll need sprites.

*1- To check if the mouse is over a rectangle (the four points in the struct variable) you can test StartX<MouseX<EndX and StartY<MouseY<EndY , then you can modify the struct rectangle's points in function of the mouse's movement.
*2- I don't know how much information the DrawerObject keeps, but probably the structure I used in the example, with extra variables as FillColor, BorderColor, Opacity, etc would take less memory. But changing every frame the properties of the only DrawerObject to work with each structure variable will lost performance. Then Panel Sprites and Sprites (again probably) keeps a lot more information than a Drawer, so you better option (if you don't need high control) is with multiple drawers, then you could need structures/sprites/panel sprites if you need nice thinks like basic control, automatisms, and so on.