Image not added to scene group

Is there a difference between display.newImageRect and for example widget.newButton when adding to scene groups?

background = display.newImageRect(sceneGroup, "images/backgrounds/image.jpg", display.actualContentWidth, display.actualContentHeight)

Not sure whether it’s necessary but I also have sceneGroup:insert(background). Without that line it doesn’t make any difference either. But when exiting the scene this image is not removed. Whereas this object:

 menu\_btn = widget.newButton({ id = "menu", x = btnPos, y = buttonY, onRelease = function(event) end, width = btnWdth, height = btnHt, defaultFile = "images/game/menu.png", overFile = "images/game/menuoff.png", }) sceneGroup:insert(menu\_btn)

gets added to the scene group and gets hidden no problem when exiting the scene. They’re both added at the same scene:function and only added once. I can make them invisible of course or whatever but I’m just not sure why these objects are different.

There should be no difference between display.newImageRect and widget.newButton with regards to being inserted into a group.  So both of these calls should work in exactly the same way as each other.

sceneGroup:insert(background) sceneGroup:insert(menu\_btn)

Is it possible you have created an additional group called sceneGroup by mistake, and the background is being inserted into that?

Hmm so it should be working? No there is only one sceneGroup, I double checked that. It’s weird that ALL my widgets, display text etc get added no problem but all imageRects don’t get added properly.

So I do need to use sceneGroup:insert as well then? I have used it but I’m just wondering since newImageRect the first variable is the scene group so I don’t know what that is for if it still needs to be inserted into the scene group again.

The only difference I can see is that the images have this group variable when created. Should I be adding them to a smaller group instead rather than sceneGroup and then adding them into the main sceneGroup with insert?

No, you don’t need to use it again, having it as the first argument in the newImageRect function does exactly the same thing as calling insert(). I was just trying to show that imageRects can be passed into groups.  

You might need to post more of your code, as something must be wrong somewhere. 

Ok thanks for the clarification. I’ll have a further look at it.

Widgets are libraries built upon our display.* objects. But in many cases, the widget is itself not a display object.  We added convenience methods like :insert() to make them behave like display objects, so you can add widgets easily to groups. But there are generally not ways to use widget constructors to automatically add them to groups. All of our display.* API’s should take an optional group as the first parameter for those who want to use that method to add them to groups.

Rob

There should be no difference between display.newImageRect and widget.newButton with regards to being inserted into a group.  So both of these calls should work in exactly the same way as each other.

sceneGroup:insert(background) sceneGroup:insert(menu\_btn)

Is it possible you have created an additional group called sceneGroup by mistake, and the background is being inserted into that?

Hmm so it should be working? No there is only one sceneGroup, I double checked that. It’s weird that ALL my widgets, display text etc get added no problem but all imageRects don’t get added properly.

So I do need to use sceneGroup:insert as well then? I have used it but I’m just wondering since newImageRect the first variable is the scene group so I don’t know what that is for if it still needs to be inserted into the scene group again.

The only difference I can see is that the images have this group variable when created. Should I be adding them to a smaller group instead rather than sceneGroup and then adding them into the main sceneGroup with insert?

No, you don’t need to use it again, having it as the first argument in the newImageRect function does exactly the same thing as calling insert(). I was just trying to show that imageRects can be passed into groups.  

You might need to post more of your code, as something must be wrong somewhere. 

Ok thanks for the clarification. I’ll have a further look at it.

Widgets are libraries built upon our display.* objects. But in many cases, the widget is itself not a display object.  We added convenience methods like :insert() to make them behave like display objects, so you can add widgets easily to groups. But there are generally not ways to use widget constructors to automatically add them to groups. All of our display.* API’s should take an optional group as the first parameter for those who want to use that method to add them to groups.

Rob