Sprite Array

Not sure if I’m doing this right? Trying to create an array of sprites. But when I do all of the sprites in the array are displayed on the screen at once. Calling a specific index doesn’t do anything.

1 Like

Sprites appear on the screen when they are created, as creating them adds them to the game engine. In this case, you’re creating three sprites, and storing references to them in an array; if you added set {sprite list get value at 1} position to x {0} y {0} it will move the apple to the top left corner, and if you add move {sprite list get value at 2} with buttons you will be able to move the lemon around the screen with the buttons.

The array of sprites of kind food returns an array with all the existing sprites of kind food – in this case the array will be empty, because at the time you are calling it non have been created yet.

What are you trying to use this for / what’s the end goal? You might want to use an array of Images instead if you just want to be able to create three different types of food sprites.

1 Like

I have about 20 images that I want to access randomly

https://makecode.com/_9MXDJ7gxR1bH Maybe like this.

3 Likes

Thanks, I think I can make this work for what I want. AWESOME!

And small add on to @jedgarpark’s example, if you want random images, here’s one way to do it:

3 Likes