Sprite "Group" Simplification help

hello!
i need help figuring out a way to “Group” sprites together and apply the same properties to all of them. Copying and Pasting over and over is mighty inconvinient, and very ugly to look at:


i attempted to use arrays like this:

and then using the “list” variable instead of the others induvidually, but i get a lot of errors about sprite kinds.
Help please!

3 Likes

Use an array for colors and instead of multiple images use the image recolor function to easily recolor from the same image. Also use a for element block.

2 Likes

Can you send the game link? Also, the picture you posted is blurry, so I can’t see what’s going on

1 Like

Here is small demo of grouping sprites!

im still a noob to block coding, so im going to need a visual explanation if thats not too much trouble

Heres the project
The link will be updated every few hours (im actively working on it)

1 Like

theres many things you can optimise with functions and looping code

firstly, instead of a huge list changing each tile individually, you can just loop a section of code and change the x pos by 1 each time. Because the loop has no delay it all happens instantanously
(note that I add +1 because the index value starts at 0)

Something many beginners struggle with is using sprites effectively, I always see many different sprite variables being used when it could all be one variable.

To remove the huge list we can use a function. Functions are a way to loop a custom section of code. But the magic is that we can add parameters to adjust them.
For example:
Say we made a function to make a red apple. Without adding a parameter, the function can only make red apples. But if we wanted green apples as well, we could just add a parameter controlling colour so that we could reuse our function and make actually any colour we wanted.

back to the original code →
Here i have taken advantage of the fact that colours = numbers in code. By plugging into the index into our function, we get a different colour each cycle of the loop. Thus, 8 different sprites are made. Again we have to +1 since while our colours start at 1, our index starts at 0.

extra

also the only reason why i added this is because its fun to make random things deterministic (if you input the same seed the exact same outcome will happen!) This could be useful for stuff like remaking the same set of random outcomes and saving games

2 Likes