It looks like you're new here. If you want to get involved, click one of these buttons!
drop={} -- The dropboard dTile=gideros.class(Sprite)-- Create a new drop class dropgroup=dTile.new() -- I hav a class dTile.lua but did not include for this example dbt = dTile.new("gfx/bluetile.jpg") drt = dTile.new("gfx/redtile.jpg") dyt = dTile.new("gfx/yellowtile.jpg") dgt = dTile.new("gfx/greentile.jpg") dpt = dTile.new("gfx/player.jpg") for i=1,4 do drop[i] = {} -- create a new row for j=1,4 do drop[i][j] = dTile.new r=math.random(5)-- Get a random number then a color to use if r == 1 then drop[i][j] = drt drop[i][j].color =1 elseif r == 2 then drop[i][j] = dbt drop[i][j].color =2 elseif r == 3 then drop[i][j] = dyt drop[i][j].color =3 elseif r == 4 then drop[i][j] = dgt drop[i][j].color =4 elseif r == 5 then drop[i][j] = dpt drop[i][j].color =5 end drop[i][j]:setX(j * 48) drop[i][j]:setY(i * 24) drop[i][j].occ=1 -- Occupied or not h=drop[i][j]:getHeight() w=drop[i][j]:getWidth() x=drop[i][j]:getX() y=drop[i][j]:getY() color = drop[i][j].color dropgroup:addChild(drop[i][j]) -- I cant seem to grasp how to add these objects to the group print( i,j, "Color", color, "h=", h, "w=", w, "x=",x, "y=",y, "Occ=",occ, drop [i][j]) --#WISH Debugger end end ----and then add them all to stage stage:addchild(dropgroup) |
Comments
sorry but without dTile set we can't also test it. From the first look can't find anything wrong. Can you at least share what error do you get, or what is not working correctly?
what is returned when you call the dTile.new() ?? Hopefully that is a Bitmap object.
Secondly, you are trying to create 16 display objects from 4. you will need to create 16 objects. Otherwise the same object is just repositioned.
Another thing that baffles me is, the line
Author of Learn Lua for iOS Game Development from Apress ( http://www.apress.com/9781430246626 )
Cool Vizify Profile at https://www.vizify.com/oz-apps
it is just years of being with IT
Author of Learn Lua for iOS Game Development from Apress ( http://www.apress.com/9781430246626 )
Cool Vizify Profile at https://www.vizify.com/oz-apps
stack traceback:
I guess in a nutshell I am looking for the correct way to display say 64 sprites on a screen at the same time and be able to access variables for each sprite in a array. Each sprite in the 64 group would be assigned of of the 6 availbale bitmap images.
and here is the dTile object - nothing pretty
...
drop[i][j] = dTile.new("gfx/redtile.jpg")
..
iterate thru and you have a wonderfull array of objects.
Doog
Glad you got it working...
Just a few tips in case you want
If you want to simply move an object on one axis, then rather than setting the position using setPosition(), you can just use the setY() as
Author of Learn Lua for iOS Game Development from Apress ( http://www.apress.com/9781430246626 )
Cool Vizify Profile at https://www.vizify.com/oz-apps
I have a group of Sprite, and then I group:addchild(childsprites)
But when I do eventlistener, I get the group sprite properties, whats the right method to get the childsprite properties?
---------------------------------------
You probably add it to the whole group and not each individual child right?
best regards
Like this, I move the group around with an event on the group.
But if I dont move, just select, I want the individual sprite to respond.
Where I am getting stuck is passing through an event from the parent to the child.
I can put some sample code if it helps.
Typical, the minute I ask the question I find the answer.
I found that, event:stopPropagation() stops the events traveling up the tree, when I remove this, all the events trigger and I can solve my problem.
---------------------------------------