Tuesday, 15 March 2011

user interface - Displaying image buttons to replicate app icons - Corona SDK -



user interface - Displaying image buttons to replicate app icons - Corona SDK -

i need display images mimic layout of ios app icons on various "home" pages. have code written display various images; however, cannot figure out how homecoming value corresponds each individual image on click event.

here's code far:

plates = { "fat-burning-foods.jpg", "fresh_food.jpg", "fat-burning-foods.jpg", "star.png", "fat-burning-foods.jpg", "star.png", "fat-burning-foods.jpg", "fresh_food.jpg", "fat-burning-foods.jpg", "star.png", "fat-burning-foods.jpg", "fresh_food.jpg", "fat-burning-foods.jpg", "star.png" } -- plateid have corosponding indexes plates array. used query plate info plateid = {1,2,3,4} plateidref = {} index = 1 platesish = {1,2,3,4,5,6,7,8} local anx = 20 local = 120 i=1, #plates local buffery = 20 if index == 4 buffery = 110 anx = 20 elseif index > 4 buffery = 110 end if index == 7 buffery = 200 anx = 20 elseif index > 7 buffery = 200 if index == 10 buffery = 290 anx = 20 elseif index > 10 buffery = 290 end end local dummyvar = math.random() dummyvar = display.newimagerect(plates[index],80, 80) scenegroup:insert(dummyvar) dummyvar.x = anx + 30 dummyvar.y = + buffery table.insert(plateidref, index) function dummyvar:touch( event ) if event.phase == "began" local alert = native.showalert( "corona", event.target, { "ok", "learn more" } ) --print( "you touched "..dummyvar) homecoming true end end dummyvar:addeventlistener( "touch", dummyvar ) anx = anx + 110 index = index + 1 end

any ideas?

ok, illustration see how works:

local plates = {} local function platetouch( self, event ) local phase = event.phase if phase == "ended" print( "you touched ".. self.id) end homecoming true end i=1, 3 plates[i] = display.newimagerect("test.png",80, 80) plates[i].id = "plate " .. plates[i].x = 90 * plates[i].y = 90 plates[i].touch = platetouch plates[i]:addeventlistener( "touch", plates[i] ) end

when create each plate can define id property know button pressed, can add together other properties need.

you can see api docs touch event , see illustration table listeners.

other approach object oriented solution, define class create new plates, maybe first need understand example.

button user-interface lua corona

No comments:

Post a Comment