Objects and display groups questions

Hello, i have been playing around with object groups lately. Mainly to test character attachment points like a character with equipments/shirts/hair, etc.

Currently this is a sample of what i am doing:

local head = display.newImage( "head.png" )  
local body = display.newImage( "body.png" )  
local shirt = display.newImage( "shirt.png" )  
  
local character = display.newGroup()  
  
-- set head, body, shirt positions  
  
character:insert( head )  
character:insert( body )  
character:insert( shirt )  
  
-- Some codes  
  
-- character movement example  
local function charMove()  
 character.x = character.x + 1  
end  
  
-- a function is called when character is dead  
local function removeCharacter()  
 character:removeSelf()  
end  
  1. I was wondering if this is the correct way to do it. Is there a better way to handle a character (or objectS within object)?

  2. does removeSelf actually remove all images i inserted into character?

  3. If i implement this with storyboard, do i need insert all images (head,shirt, hair) separately into the scene’s group or just the character itself?

  4. Do i have to manually remove this object like widgets when working with storyboard?

Thanks for your time!

  • Jeff [import]uid: 74723 topic_id: 26045 reply_id: 326045[/import]
  1. your method is fine, but you can shorthand the insertion by specifying the group as the first parameter of the newImage tag.

[code]
local character = display.newGroup()

local head = display.newImage( character, “head.png” )
local body = display.newImage( character, “body.png” )
local shirt = display.newImage( character, “shirt.png” )
 [/code]
2) removing the display group “character” should recursively remove all images inside it. Of course you need to clean up listeners or other references to those items before you clear the group.

3-4) unfortunately I’m not a Storyboard user, but maybe somebody else can answer. I am just too attached to my ultra-reduced slim version of Director to make the switch to Storyboard. :slight_smile:

Brent Sorrentino [import]uid: 9747 topic_id: 26045 reply_id: 105445[/import]

If you add a group to a scene in storyboard, all the children of that group will be added, no need to do it manually.

If you’ve added a group to the scene and only contains images there is no need to remove manually the group or the children in storyboard, this is handled by the scenes. If you have any listener, transition or timer attached to that group or a children, then It could be a great idea to cancel it and remove it. [import]uid: 131209 topic_id: 26045 reply_id: 105451[/import]

@Ignis Design
Thanks, those are some helpful tips.

@breathe
Thanks too, i am always paranoid when it comes to cleaning things up and making sure theres no memory leak even with the memory tracker on. [import]uid: 74723 topic_id: 26045 reply_id: 105626[/import]