Hi!
I have a game where I create a displayGroup and set the y value to -96. The x value I don't set, so I would assume that to be zero.
Now, later on in my game when I set the X value to zero, the displayGroup falls off the stage completely. In fact, getting the X value of the displayGroup gives a superhigh number: 2147483648.
Not only that, but setting the value to a bit less doesn't work that well either, e.g. setting the number to 20 less doesn't show any difference in X position on screen. Setting it 300 less gives a differences of 128 pixels on screen, and more of these weird results - I know it's 128 pixels because it is exactly two of my 64 px tiles.
The only code this Grid sees is the following during creation:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | -- create grid holding all tiles Grid = display.newGroup() Grid:setReferencePoint(display.TopLeftReferencePoint) --Grid.x = 0 Grid.y = -384 transition.to(Grid, {time=500, delay=300, y=96, transition=easing.outQuad}) Grid.tileSheet = sprite.newSpriteSheet("Elements.png", 64, 64) Grid.tileSet = sprite.newSpriteSet(Grid.tileSheet, 1, 64) -- populate the grid with 30 tiles for y = 0, 5 do for x = 0, 4 do local Tile = sprite.newSprite(Grid.tileSet) Tile:setReferencePoint(display.TopLeftReferencePoint) Tile.x = x*64 Tile.y = y*64 Tile.currentFrame=Array[x+1+y*5] Grid:insert(Tile) end end print(Grid.x) |
The problem is you are trying to set properties of the empty display group. An empty group object has no real properties if it doesn't contain any objects. You should insert at least one object into the group before changing the reference or setting any of its properties.
This does indeed fix the issue :
eg :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | -- create grid holding all tiles Grid = display.newGroup() --Grid.x = 0 Grid.y = -384 transition.to(Grid, {time=500, delay=300, y=96, transition=easing.outQuad}) Grid.tileSheet = sprite.newSpriteSheet("Elements.png", 64, 64) Grid.tileSet = sprite.newSpriteSet(Grid.tileSheet, 1, 64) -- populate the grid with 30 tiles for y = 0, 5 do for x = 0, 4 do local Tile = sprite.newSprite(Grid.tileSet) Tile:setReferencePoint(display.TopLeftReferencePoint) Tile.x = x*64 Tile.y = y*64 Tile.currentFrame=Array[x+1+y*5] Grid:insert(Tile) end end --Set reference point after some objects are inserted into the group Grid:setReferencePoint(display.TopLeftReferencePoint) print(Grid.x) |
Okay - weird but great and thanks for the fast reply!
Nice to know! I've experienced similar weirdness with groups and made it work after beating on it (flailing about) but never knew why -- I must have accidentally done what was right. :)
Maybe that little tidbit should be included in the API docs.
Jay
Yes, I updated the display.newGroup API page about this issue.
http://developer.anscamobile.com/content/displaynewgroup
Thanks,
Tom