displayGroup gets insane X value 2147483648 for no reason!

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:

 -- 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 print statement in the end outputs the weird value already - so the error is present right away after creation, not because of some weird code afterwards. Printing the Y value is correct.

As you can see I’m not doing anything that explains this weirdness, right? By the way, uncommenting the line that says ‘Grid.x=0’ makes the displayGroup jump off the screen immediately.

So… Apparently creating the displayGroup defaults to a X position of 2147483648. If this deviation was predictable I could compensate for this value, but alas, it is not.

Please fix this or help me out!!!

Thanks,
Thomas [import]uid: 70134 topic_id: 14789 reply_id: 314789[/import]

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. [import]uid: 7559 topic_id: 14789 reply_id: 54731[/import]

This does indeed fix the issue :

eg :

[code]
– 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)
[/code] [import]uid: 84637 topic_id: 14789 reply_id: 54733[/import]

Okay - weird but great and thanks for the fast reply! [import]uid: 70134 topic_id: 14789 reply_id: 54735[/import]

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. :slight_smile:

Maybe that little tidbit should be included in the API docs.

Jay
[import]uid: 9440 topic_id: 14789 reply_id: 54749[/import]

Yes, I updated the display.newGroup API page about this issue.
http://developer.anscamobile.com/content/displaynewgroup

Thanks,
Tom [import]uid: 7559 topic_id: 14789 reply_id: 54752[/import]