How do i use Object:new function?

Sorry for the newb lime questions.

 

I would like to add a new physics object to my level.  Is object:new the correct function to use?

 

Would someone be able to give me a simple example of this function in action?  Specifically, I am not sure what to provide as XML data.  Is this data i reference from the Tile set?

 

Here’s what the documentation says:

 

Object:new  (data, map, objectLayer) Create a new instance of an Object object. Parameters

  • data: The XML data.
  • map: The current Map object.
  • objectLayer: The ObjectLayer the the Object resides on.
    Return value: The newly created object instance.

A brief message from Graham led me to the solution i needed.  Here’s what he wrote about Object:new and that I shouldn’t use it:

“In answer to your question though, that function and the ones similar to it are more designed for internal use. Objects can be created in Tiled and then Lime just uses that function to create the Lua table for it.”

Using Object:new was not the correct approach.  I found my solution using Map:addOject(displayObject).  This function allowed me to create and add a new object to the Tiled map and fixed my collision issues and position issues for my newly spawned objects.

For example:

                        local spawnegg = function()

                            egg = display.newImage (“egg.png”)

                            map:addObject(egg)

                            egg.x = destructable.x

                            egg.y = destructable.y

                            

                            physics.addBody(egg, “dynamic”, {density = 1, friction = 0, bounce = 0, radius = 16})

                        end

                        

                        timer.performWithDelay(100, spawnegg, 3)

Without adding to the map I was having collision issues and camera problems.

Map:addObject(displayObject) documentation:

Map:addObject  (displayObject) Adds a displayObject to the world. Parameters

  • displayObject: The displayObject to add.
    Return value: The added displayObject.

A brief message from Graham led me to the solution i needed.  Here’s what he wrote about Object:new and that I shouldn’t use it:

“In answer to your question though, that function and the ones similar to it are more designed for internal use. Objects can be created in Tiled and then Lime just uses that function to create the Lua table for it.”

Using Object:new was not the correct approach.  I found my solution using Map:addOject(displayObject).  This function allowed me to create and add a new object to the Tiled map and fixed my collision issues and position issues for my newly spawned objects.

For example:

                        local spawnegg = function()

                            egg = display.newImage (“egg.png”)

                            map:addObject(egg)

                            egg.x = destructable.x

                            egg.y = destructable.y

                            

                            physics.addBody(egg, “dynamic”, {density = 1, friction = 0, bounce = 0, radius = 16})

                        end

                        

                        timer.performWithDelay(100, spawnegg, 3)

Without adding to the map I was having collision issues and camera problems.

Map:addObject(displayObject) documentation:

Map:addObject  (displayObject) Adds a displayObject to the world. Parameters

  • displayObject: The displayObject to add.
    Return value: The added displayObject.