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.
Label: corona android iphone ipad building error inmobi problem display screen View image tableView failed object physics touch button game lua config event listener |
Create and fill a grid in Lua/Corona
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | -- 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 |
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.
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
views:1874 update:2011/10/6 9:28:12
热门文章
GameCenter LeaderBoards and Achievements Enabled Through OpenFeint
send message and call to a person
Forum: Report Spam + PM
[INSTALL_PARSE_FAILED_NO_CERTIFICATES]
[SOLVED] Director ERROR: Failed to execute new( params ) function on 'screen1'
Too many (200) local variables
Corona SVG Level Builder released. Drag and drop physics level editor with Inkscape and SVG.
Small bug in Collectible Items example
Pivot Joints and apparent elasticity
Can't make removeSelf() delayed
send message and call to a person
Forum: Report Spam + PM
[INSTALL_PARSE_FAILED_NO_CERTIFICATES]
[SOLVED] Director ERROR: Failed to execute new( params ) function on 'screen1'
Too many (200) local variables
Corona SVG Level Builder released. Drag and drop physics level editor with Inkscape and SVG.
Small bug in Collectible Items example
Pivot Joints and apparent elasticity
Can't make removeSelf() delayed
相关文章
Updates to the Corona Daily Builds Summary Page
How long is the wait?
Player and Map scrolling at different rates
attempt to compare number with string
video capture
Dynamically generating display groups: why doesnt this work?
Big texture mess on Android after a resume
Lua PHP Post call
iPhone location-services
Buy button not showing up on Android Market
How long is the wait?
Player and Map scrolling at different rates
attempt to compare number with string
video capture
Dynamically generating display groups: why doesnt this work?
Big texture mess on Android after a resume
Lua PHP Post call
iPhone location-services
Buy button not showing up on Android Market
corona forums © 2003-2011