Physics body shape

How to use the physics body shape that I edit in the level director for enemy object when enemy spawn ?

----------------------------- -- Level Director - Example 1 ------------------------------ display.setStatusBar( display.HiddenStatusBar ) local physics = require ("physics") physics.start() local LD = require ("lib.LD\_LoaderG2") local myLevel = {} -- this creates all the display objects for the level -- myLevel will contain all the display groups so you can access all the elements of the level myLevel = LD:loadLevel("Level01") local function spawnEnemy() local enemy = display.newRect(0,0,20,30) enemy.x = math.random(10,300) enemy.y = math.random(10,400) end timer.performWithDelay(1000,spawnEnemy,0)

Hi,

If I understand you correctly you want to spawn an asset created from within level director that already has physic bodies applied?

This is simple to do and the ‘AssetTest’ example that comes with LD shows you this in action.

An asset called ‘dog’ was added in LD and the following code spawns an instance of that asset on layer ‘fg’ and starts the ‘walk’ animation sequence.

--spawn dog and animate it local objProps =  { name = "dog",  x = 250, y = 300, assetName = "dog", } local dog = myLevel:createObject("fg", objProps).view dog:setSequence("walk") dog:play()

In the ‘AssetTest’ example the dog doesn’t actually have physics applied but that doesn’t matter, if it did then your new instance will automatically inherit the physics applied to your asset.

Does this help?

Hi,

If I understand you correctly you want to spawn an asset created from within level director that already has physic bodies applied?

This is simple to do and the ‘AssetTest’ example that comes with LD shows you this in action.

An asset called ‘dog’ was added in LD and the following code spawns an instance of that asset on layer ‘fg’ and starts the ‘walk’ animation sequence.

--spawn dog and animate it local objProps =  { name = "dog",  x = 250, y = 300, assetName = "dog", } local dog = myLevel:createObject("fg", objProps).view dog:setSequence("walk") dog:play()

In the ‘AssetTest’ example the dog doesn’t actually have physics applied but that doesn’t matter, if it did then your new instance will automatically inherit the physics applied to your asset.

Does this help?