How to create many sprites similar to each other, and declare them incrementally (sprite1, sprite2, sprite3...)?

Hello, is it possible to automate the creation of sprites in such a way that you can name them as “[name] + [number]”? For example, in this game we want to create sprites that represent notes in a Dance Dance Revolution style game. However, we don’t want to hard code hundreds of sprites each with the names incrementing “note1”, “note2”, “note3”, etc. Is there any way to achieve this?

We have tried declaring and calling notes in the format,
var note + x = createSprite(100,100); and other similar formats like,
var “note” + “1” = createSprite(100,100); but these only result in an error.
Assuming that we get declaring the sprites working, how would we go about calling a specific sprite to change it’s animation?

Here is the game, though not much of it is in working order yet so there is little to see

@taggerung - I don’t know of any programming language that allows what you are trying. I’m not a GameLab expert but an array of sprites might be what you are looking for. I also see groups which may be useful.

1 Like

I would also look at groups, although I don’t have a ton of experience with them. If you search the forum, you will find other posts where people explain how they have used them.

Best luck,


1 Like

@gjschmidt @mwood Thank you for your suggestions! We have found a workaround that involves creating sprites in a group – noteGroup1.add(createSprite(x, y) and calling them using noteGroup1.get(0).

1 Like

Assuming i is an integer defined in for-loops.
Method 1:


Method 2:

var tempsprite = createSprite(100, 100)
eval("note"+i+" = tempsprite")

However none of these methods are conventional. In a more realistic sense, you would either create a group or an array (groups are just arrays with extra features used in manipulating sprites).
Using groups:

var g = createGroup()
for (var i = 0; i<10; i++) {
    var s = createSprite(100, 100)

Using arrays:

var a = [];
for (var i = 0; i<10; i++) {
    var s = createSprite(100, 100)
    g[i] = s