randomize images?

I need to know how to make random images? so my obstacles are different every time! please help!

Put all your images in a table, then just pull them out using a randomized index. For example:

local myPics = {"bat.png", "cat.png", "hat.png", "rat.png" } local idx = math.random(#myPics) local pic = display.newImage(myPics[idx])  

Every time that code is executed a random picture will show.

 Jay

thanks it works but how can I change the size of the images?

You can change the size of images with the width and height properties:

pic.width = 200 pic.height = 150

Not sure exactly what you’re trying to do.

 Jay

go download flappy bird. I’m trying to make the obstacles like in that game…

help

From the pics I’ve seen of that game it looks more like the horizontal/vertical coordinates of the objects are changed, not the size. Positioning an object up and down happens by changing the y property. Positioning an object side to side happens by changing the x property.

 Jay

so what code would you recommend I need help

It kind of sounds like you’re trying to bite off more than you can chew. If you’re a Corona newbie (I’m guessing you are) you might want to get some foundation before trying to make a complete game. Even if it is a simple one. :slight_smile:

There’s a free video crash course here: http://masteringcoronasdk.com/game-development-crash-course/

You might want to go through that first (only takes an hour or two) and see if that helps answer some of your questions. It does cover positioning objects on the screen as well as simple animation and sound effects.

 Jay

I know sprites I know sound effects I know a lot I just can’t grasp random images.

You really need to go back to basics. Without knowing about tables, positioning images on the screen, etc you’re not going to get far before hitting another road block. 

Once you know how lua works, and what APIs are available, everything else is just a question of applying logic to each problem.

I know about tables and I know about positioning images…

Do you know about enterFrame listeners, display groups, scrolling, conditional logic, touch listeners?

If you do, then you have all you need to write flappy bird. If not, you’ll need to read about those things. 

I know all of that I just don’t have the math.random part nailed

https://docs.coronalabs.com/api/library/math/random.html

Put all your images in a table, then just pull them out using a randomized index. For example:

local myPics = {"bat.png", "cat.png", "hat.png", "rat.png" } local idx = math.random(#myPics) local pic = display.newImage(myPics[idx])  

Every time that code is executed a random picture will show.

 Jay

thanks it works but how can I change the size of the images?

You can change the size of images with the width and height properties:

pic.width = 200 pic.height = 150

Not sure exactly what you’re trying to do.

 Jay

go download flappy bird. I’m trying to make the obstacles like in that game…

help