sprites and .jpgs as random images

Hey, im not home and can not try it, but a thought affects me:

I have to randomize 2 images.

Even if the App Start it should display 2 images randomly.

certainly i will mut the pool of images in a table like this:

local pool  = {“1”, “2”, “3”, etc.}

and call it by:

local randImage display.newImage(“Images/”…pool…".jpg")

now, this code just display .jpg files.

But what is, if file 3 is a sprite? how can i define the sprite values and get it in to the randomize?

Can i outsource the spriteinformation and call them by calling the lua file?

If yes, how? is there any documentation or tutorial?

thanks a lot and a nice day :slight_smile:

With sprites you setup sequences.  In this case, you would have a sequence of one image.  You give each sequence a name in your case they could be named “1”, “2”, “3”, etc. and then when you’re ready you would do:

obj:setSequence(tostring(pool))

obj:play()

Rob

ah ok, that mean i put the sprite sequence into “pool”. verry interesting, thanks.

Sorry for all the noobquestions, but how can i handel more Sprites and images?

the model with 3 images is just an example.

With the obj.play() i start the spriteanimation, sure, but if there are more, lets say 20 jpgs and 20 sprites in just two positions to randomize, i can not start all the sprite animations in the same time, the game will be unstabile.

I’m not sure I fully understand your question, but what you can do is have a sequence that is just one frame that doesn’t repeat and then another sequence that is the full animation.  You draw out your non-animating ones just playing the sequence of one frame and then on tap or whatever you chose, then you can play the full animation.

Rob

Hmm what’s about if I put all the sprites into a function sprite call (obj/self)

Ant put the functioncall several times in the pool.
I would change the numbers of pool into local image display.newImage (“images/number.jpg”)

And call the pool by

Local Rand …pool
Rand.x = …

And at the end an if:

If sprite=true then
Self.play ()

Could this work?
If jes, how can I call the if on the right way?

With sprites you setup sequences.  In this case, you would have a sequence of one image.  You give each sequence a name in your case they could be named “1”, “2”, “3”, etc. and then when you’re ready you would do:

obj:setSequence(tostring(pool))

obj:play()

Rob

ah ok, that mean i put the sprite sequence into “pool”. verry interesting, thanks.

Sorry for all the noobquestions, but how can i handel more Sprites and images?

the model with 3 images is just an example.

With the obj.play() i start the spriteanimation, sure, but if there are more, lets say 20 jpgs and 20 sprites in just two positions to randomize, i can not start all the sprite animations in the same time, the game will be unstabile.

I’m not sure I fully understand your question, but what you can do is have a sequence that is just one frame that doesn’t repeat and then another sequence that is the full animation.  You draw out your non-animating ones just playing the sequence of one frame and then on tap or whatever you chose, then you can play the full animation.

Rob

Hmm what’s about if I put all the sprites into a function sprite call (obj/self)

Ant put the functioncall several times in the pool.
I would change the numbers of pool into local image display.newImage (“images/number.jpg”)

And call the pool by

Local Rand …pool
Rand.x = …

And at the end an if:

If sprite=true then
Self.play ()

Could this work?
If jes, how can I call the if on the right way?