lua - Use loop to create objects with different offsets -


here loop create 4 objects:

for i=1,4     local obj = display.newrect(scenegroup, 40, 60)     obj.y = (obj.height + 80) * end 

this code create 4 objects starting point of 60(obj.height) gap of 80 between each 1 of them.

what want change starting point keep same gap(80) between them, meaning want start point 250 instead of 60. tried different approaches couldn't manage right.

from corona documentation display.newrect()

overview

creates rectangle object. local origin @ center of rectangle , anchor point initialized local origin.

syntax

display.newrect( [parent,] x, y, width, height ) 

try

local x, y = display.contentwidth * 0.5, 250-- decide put first rectangle  local obj = {} -- reference futher use   i=1, 4     obj[i] = display.newrect(x, y, 40, 60)     y = y + obj[i].height + 80 end 

Comments

Popular posts from this blog

sql server - Cannot query correctly (MSSQL - PHP - JSON) -

php - trouble displaying mysqli database results in correct order -

C++ Linked List -