Objects not drawing after adding to a Display Group

Hello,

I have been following an EggBreaker example to add objects to a display group, but every time I call group:insert(object) the object simply disappears.

I tried adding true to the insert function, but that didn’t do anything.
Tried setting the position of the object before and after adding to the group as well. All the collisions still work with the object added to the display group.

Here is what I currently have (a short version):

local mainDisplayGroup = display.newGroup()
mainDisplayGroup.x = 0
mainDisplayGroup.y = 0

local ground = display.newImage(“Ground.png”, 0, 280)
mainDisplayGroup:insert(ground)

physics.addBody(ground, {1.0, 1.0, 0.1, filter = collisionFilter})
ground.bodyType = “static”

Thank you,

Dinar. [import]uid: 11971 topic_id: 5722 reply_id: 305722[/import]

Why are you setting an x/y for the mainDisplayGroup, then the same for the image? That may be the problem. Either remove the x/y for the group or for the image and see how it goes [import]uid: 30185 topic_id: 5722 reply_id: 19590[/import]

Fixed it :slight_smile:

You have to add all images to display groups.

If you add an image to a display group they will be drawn first, and if you have any images that weren’t added to any display group they will be drawn last or on top.

In my case I had a background image that was not in a display group so it was drawing on top of the ground.

That’s at least how I see it.

Thanks. [import]uid: 11971 topic_id: 5722 reply_id: 19593[/import]

I had explained a while back groups and how they affect the drawing order here:

https://developer.anscamobile.com/forum/2010/10/09/initializing-groups-layers#comment-7929 [import]uid: 5712 topic_id: 5722 reply_id: 19611[/import]