Hello everyone I am trying to setup a grid of 12x9 for iPhone and 17x13 for iPad in the same code and fill it up randomly with a specific number of type of items (2,3,4 or more types) and also allow user to choose how many types to display on screen prior to filling. Could anyone give me a hand with the code this is my first in Lua & Corona for me, any help is appreciated. [import]uid: 43696 topic_id: 7595 reply_id: 307595[/import]
thanks jmp909 this was very helpful, either line 25 or 26 should be “itemsDown”. The images do appear on screen but go over the edges
is there a way to design this and the whole app so that depending on the iDevice it’s running on it creates the right size grid and number of items, images dimensions are 65x65 pixels. [import]uid: 43696 topic_id: 7595 reply_id: 27181[/import]
[lua]-- cache our math function
local rnd=math.random
– somewhere to add our items too
local board = display.newGroup()
local itemsAcross
local itemsDown
– 4 item types here
local images =
{
“red.png”,
“blue.png”,
“green.png”,
“yellow.png”
}
– this is the known width/height of our image for instance
local itemWidth=32
local itemHeight=32
– size of grid
– you might check for iPhone/iPad here to change this
itemsAcross = 12
itemsDown = 9
– start at row 1 and work down
for y=1, itemsDown, 1 do
– start at column 1 and work across
for x = 1, itemsAcross, 1 do
– pick a random number between 1 and number of images
local r = rnd(1,#images)
– add image “r” from the array
local img = display.newImage(images[r])
– plot the image on the grid
img.x = (x-1) * itemWidth
img.y = (y-1) * itemHeight
– add it to our group
board:insert(img)
end
end[/lua] [import]uid: 6645 topic_id: 7595 reply_id: 27010[/import]
yes that’s why i made variables that you can change in an if statement that checks the system info
http://developer.anscamobile.com/reference/index/systemgetinfo
[import]uid: 6645 topic_id: 7595 reply_id: 27205[/import]