so I have created an object called “box” and I want to have multiple boxes at different locations. Is this easy enough or will I need to copy and paste the code dor my box and move the location? [import]uid: 59735 topic_id: 16522 reply_id: 316522[/import]
Well, you can do this…
then you can put everything in your “EnterFrame” and any other property to your box…
and I just used a Cirlce…
[code]
function makebox()
local box= display.newCircle(240,200,25)
function snowfall:enterFrame(event)
(what ever you want it to do)
end
Runtime:addEventListener(“enterFrame”,snowfall)
end
for 0,10 do
makebox()
end
[import]uid: 95032 topic_id: 16522 reply_id: 61712[/import]
that works, but I want to be able to specify all of the locations. So for example I want 5 boxes all in different locations. Is this possible or should I create new actors? [import]uid: 59735 topic_id: 16522 reply_id: 61725[/import]
There’s various ways you can do this, which are all a matter of personal preference really, but the bottom line is:
You’ll need to create a separate display object for each box.
You’ll need to modify the x/y values for each one of those display objects.
If the boxes are evenly spaced, then you could probably get away with storing the display objects in a table and using a for-loop to position them. Otherwise, if you have specific locations you want to place each box, here’s probably the fastest way to do so:
local boxes = {} -- create a tablefor i=1,5 do boxes[i] = display.newImage( "box-" .. i .. ".png" )endboxes[1].x, boxes[1].y = 100, 200boxes[2].x, boxes[2].y = ...boxes[3].x, boxes[3].y = ...boxes[4].x, boxes[4].y = ...boxes[5].x, boxes[5].y = ...[/code]Obviously, you'd replace the "..." with x, y values depending on where you want those specific boxes to be placed. [import]uid: 52430 topic_id: 16522 reply_id: 61732[/import]
I don’t mean to takeover this thread but I’m at the same point. I am creating a bunch of objects and want to insert them dynamically into a table. The caveat in my case is that I would prefer a dictionary index on the table and not a numeric one.
I’ve seen the blog post on tables but it didn’t quite get me there.
Any help is appreciated.
I should add that what I’m doing “looks” acceptable:
…create a bunch of objects named square and assign :
local squareName = "square"..squareCount
square.squareID = squareName
spawnTableSquares[squareName] = square
print(#spawnTableSquares)
I’ve also tried:
spawnTableSquares.squareName = square
and…
spawnTableSquares = { squareName = square }
and my table length still shows 0 so something else is going on. [import]uid: 42417 topic_id: 16522 reply_id: 61791[/import]