I looked at the examples and I looked at numerous topics here in forum and I still don’t really get it.
I start with a sprite with animation 0-65 and a variable value n, representing the amount of sprites to create.
Additionally there is a variable vx.n (so there are n variable vx, one for every sprite, for first sprite: vx.1=0), containing values from 0-65.
What is the most elegant way to create the sprite n and set it’s animation to the value of the vx.n?
Is there a way to include the n in the name of the created sprites?
How do I work with the unique ID of the sprites to - for example, change the animation of the 712th sprite from 0 to 7?
I think the easiest way to distinguish between objects is to set them a variable “id” (or any appropriate name) after creation.
There is also the “For each object” event that can be used to loop on all objects (and then use inside the event a condition testing the “id” variable to do specific work according to the object).
I’m still thinking about the use of voxels in GD, and at the moment I’d like to create a simple voxel painter.
I had a look at the tilemapobject and it -used in several layers- seemed to be a very pleasant solution.
The only thing that bothers me about it is, that I would need to be able to use variables when creating it.
I’d need to create the tilemap object with a width of x and a height of y at layer z.
So far, I don’t know how to achieve that, so I thought recreating it to fit my needs might be possible.
That’s why I’m thinking about the sprites and their animations.
To have an idea of the model:
xSize=17,ySize=21,zSize=17
Using for each object in this case would require 6069 steps.
What I’d rather be able to do is to have my MasterSprite and to create - let’s call it “gridsprite.1” until “gridsprite.n” from it.
By that I think I could access my 712th GridSprite with gridsprite.712 - if all that is possible somehow?
In your case, you could attribute to objects variables called “x”, “y”, “z” and use them to access to an object (using a condition testing for variables).
(Or only use an “id” variable that go from 0 to n if you prefer).
There is no way to change objects “names”. Names are things that are just used to identify objects in events, but they do not exist for real in the engine. (In fact, they are used, but we could imagine that one day the names could be replaced by number identifiers or anything else internally). They are just like classes in object oriented programming.
Thank you very much for the suggestion - sounds like a good idea.
So I’d
create object Mastersprite
set Mastersprite.ID
set Mastersprite.X
set Mastersprite.Y
set Mastersprite.Z
set Mastersprite.Animationnumber
set animation of Mastersprite to Mastersprite.Animationnumber (wouldn’t that change the animation of all sprites???)
at creation
And when editing? How do I access my 712th Sprite to change it’s animation?
(I don’t feel very clever at the moment - hope I’m not too annoying…)
Can I create objects, that are not in the object list, by code?
Like creating a tilemap object with variable width and height within the code?
How can I create the variable zSize number of layers I need?
… little later…
To try and make it more simple for me I created in Objecteditor a sprite named GridSprite, that has animation 0 and 1.
“do =1 to variable counter
Then triggering once, repeating 4 times I
-create object GridSprite at tempX, tempY
-do=Variable(counter) to variable GridSprite.ID
-add 40 to tempX
-add 1 to counter”
That gives me 4 GridSprites in a row, all have animation set to 0
With
“For each object GridSprite, repeat:
Variable GridSprite.ID=2 do =1 to the number of current animation of GridSprite”
none of the sprites’ animations are changed.
With
“For each object GridSprite, repeat:
Variable GridSprite.ID>2 do =1 to the number of current animation of GridSprite”
all sprites’ animations are visibly changed to 1.
Seems my problem is still, that I don’t understand how to change only the 2nd sprites’ animation, without touching the 3 others.
Did you understand the way GDevelop pick objects? It’s the base of the software, you really need to understand it:
See the basic example on this page : wiki.compilgames.net/doku.php/en … s_concepts
No, because you created a Mastersprite object, so after creating an object, this object is added to the object “picked” in memory by GDevelop, and actions are applied only to it.
Like this:
Conditions : Variable id of mastersprite is =712
Actions : Do something with mastersprite
For the rest, please post events of your screenshot instead, it will be easier to debug your events
That should be the simplyfied code, where I’d like to learn how to change for example the 2nd sprites animation only.
Uhm - there doesn’t appear any code.
Seems I don’t even know how to ask a question.
The problem is in this part:
With
“For each object GridSprite, repeat:
Variable GridSprite.ID=2 do =1 to the number of current animation of GridSprite”
none of the sprites’ animations are changed.
With
“For each object GridSprite, repeat:
Variable GridSprite.ID>2 do =1 to the number of current animation of GridSprite”
all sprites’ animations are visibly changed to 1.
Using a variable named GridSprite.ID means that you’re using the scene variable “GridSprite.ID”, not an object variable.
You should use the conditions/actions in “All objects > Variables” to edit/test object’s variables.