Only been doing this a few months.
I am trying to display 8 different objects to create a room, all using the same png file.
I tried displaying normally:
(local platform2
platform2 = display.newImageRect( “platform.png”, 700, 20)
platform2.x = display.contentHeight - 100
platform2.y = display.contentHeight - 10
physics.addBody( platform2, “static”)
and it worked fine for all 8.
but I am trying to condense this, as doing that for each one seems to long.
So I tried the following and it crashes every time I try to save.
Thus it will not display anything.
It can take the first 2 or 3 platforms but than it crashes
I am probably doing this the hard way.
Thank you for any assistance.
local platform = {}
local objectCount = 8
– Platform hovering on the right
for i = 1, objectCount do
platform[i] = display.newImageRect(“platform.png”, 100, 20)
platform[1].x = 330
platform[1].y = 160
--Platform hovering on the left
for i = 2, objectCount do
platform[i] = display.newImageRect(“platform.png”, 100, 20)
platform[2].x = 140
platform[2].y = 160
--Platform on the top(Ceiling)
for i = 3, objectCount do
platform[i] = display.newImageRect(“platform.png”, 600, 20)
platform[3].x = 250
platform[3].y = 0
--Right Wall
for i = 4, objectCount do
platform[i] = display.newImageRect(“platform.png”, 320, 20)
platform[4].x = 520
platform[4].y = 160
platform[4].rotation = 90
--Left Wall
for i = 5, objectCount do
platform[i] = display.newImageRect(“platform.png”, 100, 20)
platform[5].x = -40
platform[5].y = 50
--Tilted platform on the left
for i = 6, objectCount do
platform[i] = display.newImageRect(“platform.png”, 200, 20)
platform[6].x = 30
platform[6].y = 250
platform[6].rotation = 35
--Tilted platform on the right
for i = 7, objectCount do
platform[i] = display.newImageRect(“platform.png”, 200, 20)
platform[7].x = 450
platform[7].y = 250
platform[7].rotation = -35
--Platform hovering on the bottom(Floor)
for i = 8, objectCount do
platform[i] = display.newImageRect(“platform.png”, 700, 20)
platform[8].x = -100
platform[8].y = -10
physics.addBody(platform[1], “static”)
physics.addBody(platform[2], “static”)
physics.addBody(platform[3], “static”)
physics.addBody(platform[4], “static”)
physics.addBody(platform[5], “static”)
physics.addBody(platform[6], “static”)
physics.addBody(platform[7], “static”)
physics.addBody(platform[8], “static”)
end
end
end
end
end
end
end
end