Dynamic object width/height and how to make object moves through the path

Hey,

I have two problems:

  1. I want to make dynamic object shows on the screen ( something similar as birds in AssetTest example)

My object has got 8 frames.

local objProps = { name = "smok", x = 100, y = 100, assetName = "smok", width = 60, height = 52, } --objProps.x = 300 objProps.width = 60 objProps.height = 52 local obj = myLevel:createObject("animals", objProps).view obj.speed = math.random(1,4) obj:setSequence("smokFlying") obj:play()

But on the screen show image with different width/height than 60,52 . The size is getting from Assets window in Level Director.

Can I change the size in  lua code? (I need few different width/height properties for that kind of object)

  1. I don’t know how to start move object through the path. This is my properties. I set Follow path and auto start for my image (this is animation waht’s has 8 frames)

2pskock.png

I saw PottyBirt example and I put there my image and my bezier path and it works. Maybe I should set some  other option I don’t know.

Thanks

Hi,

To size the new instance of the asset you need to pass the x and y scale in objProps;

xScale = 2, yScale = 2,

This would double the size based on the original asset size.

It is not obvious why your object is not following the path, are you calling ‘myLevel:initLevel()’ after you load the level as this starts the paths?

x/ y Scale works thanks.

No I didn’t called initLevel() before (should I call it in: ‘function scene:create( event )’  right after ‘myLevel= LD:loadLevel(“Level01”)’ or in function scene:show( event )? I’m using Composer ). I added now but still the same

Calling it in the show event should be fine as the level would have been loaded by then.

If you can send me your project I’ll take a look.

I found the answer.

I had to call ’ myLevel:initLevel()’ in function scene:show( event ) but after removing previous scene’s view:

local prevScene = composer.getSceneName( “previous” )

if (prevScene) then

composer.removeScene( prevScene )

end

 myLevel:initLevel()

I have two scene in my project Menu and Level1. 

Excellent, glad you figured it out.

Thanks for your help and time.

Can you tell me how can I remove my dynamic object?

When I click to my object I want to pause the animation and remove whole object. Then I want to create new one with different objProps. My game will have a lot of this dynamic object so I want to remove those I don’t need anymore. 

local objProps = { name = "smok" .. counter, x = 100, y = 100, assetName = "smok", xScale = 0.25, yScale = 0.25, followPathProps = {path = pathAndDelay.path, direction = 1, rotate = false, rebound = true, repeats = -1, delay = pathAndDelay.delay, autoStart = true, xFlip = true, yFlip = false}, } counter = counter + 1 local obj = myLevel:createObject("animals", objProps).view obj.speed = math.random(1,4) obj:setSequence( 'animation\_01') obj:play() animalsTable[index] = obj ----------------------------------------- local objectClean = function( index) local obj = animalsTable[index] obj:pause() -- pause the animation --obj:delete() -- I want to romove it from the screen and from the memory end

My second question is about myLevel:initLevel() function. I’m making many new dynamic objects during the game. When player ‘tap’ into object this object will be remove and new one will be create. New object has got followPath so I need to start it moves through the path/ bezier .

But If I call myLevel:initLevel() every time after I created new object other objects restart their positions (they move on the start path/ bezier positions). I don’t want to change position every objects but only this new one (make it moves).

Is there some proper function to do that?

EDIT: about my first question. I found this myLevel:removeLayerObject(layerName,objectName)

To remove an object you can use this;

myLevel:removeLayerObject(layerName,objectName)

For more information see http://www.retrofitproductions.com/level-director/utility-library/

With regards to the path question try creating the object first then set it to follow a path;

local obj = myLevel:createLayerObject(...) obj:followPath('path1', followPathProps)

I tried

local objProps = { name = "cat" .. counter, x = 100, y = 100, assetName = "cat", xScale = 0.13, yScale = 0.13, followPathProps = {path = "path\_D1", direction = 1, rotate = false, rebound = true, repeats = -1, delay = 2, autoStart = true, xFlip = true, yFlip = false}, } local obj = myLevel:createObject("animals", objProps).view obj:followPath( "path\_D1", objProps.followPathProps)

But I have nil value at followPath

my mistake the path param needs to be the actual object e.g.

local path = myLevel:getLayerObject("PathLayer","path\_D1") obj:followPath( path, objProps.followPathProps)

I made new project only to check this followPath function

 local objProps = { name = "monster", x = 100, y = 100, assetName = "monster", xScale = 0.25, yScale = 0.25, followPathProps = {path = "path\_18", direction = 1, rotate = false, rebound = true, repeats = -1, delay = 1, autoStart = true, xFlip = true, yFlip = false}, } local obj = myLevel:createObject("animals", objProps).view obj.speed = math.random(1,4) obj:setSequence( "monsterFly") obj:play() local path = myLevel:getLayerObject("animals","path\_18").view obj:followPath( path, objProps.followPathProps)

but i still have nil value when I call followPath. I don’t know maybe I have not enough properties in  followPathProps or I miss some library. (I have 3 files in my lib direcory: bezier.lua, LD_HelperG2.lua, LD_LoaderG2.lua) 

I saw you wrote I should call 

local obj = myLevel:createLayerObject(…)

but I call 

local obj = myLevel:createObject(“animals”, objProps).view

(createObject not createLayerObject )

I can’t call  

local obj = myLevel:createLayerObject(“animals”, objProps).view

or

local obj = myLevel:createLayerObject(“animals”, objProps) because I have nil value

In LD_HelperG2.lua, LD_LoaderG2.lua I can find createObject function but I don’t see createLayerObject 

I don’t know is it important. 

Sorry I was getting ‘create’ and ‘get’ mixed up but you’re right it should be ‘createObject’ not ‘CreateLayerObject’

When you get your path object try removing .view as it doesn’t have to be a display object i.e. just a list of points.

If you’re still having problems then send me your project and I’ll take a look (support@retrofitproductions.com)

ok, I send you  email with my sample project.

Try this code;

 local obj = myLevel:createObject("animals", objProps) -- No .view obj.view.speed = math.random(1,4) obj.view:setSequence( "monsterFly") obj.view:play() local path = myLevel:getLayerObject("animals","path\_18") obj:followPath( path, objProps.followPathProps) 

You’ll notice that when obj is created I omitted .view because the function ‘followPath’ is at the object level not the display/view level.

I then just added .view when referencing properties for the actual display object.

Does this make sense?

Thanks. Works great now, 

Can you recommend me some IDE for lua and Corona? It’s hard a bit to write a code without good debugger: seeing values during playing the game etc. ?

Debugging is difficult in Lua/Corona but I use NotePad++ to write my code and simply use ‘print’ statements to display variable values.

Sublime is another good editor.

I see. I’m using print too but it would be much more easier when I could put some breakpoints and debug it step by step.

You could try Lua Glider (http://www.mydevelopersgames.com/Glider/) which gives you the ability to add breakpoints and debug.

I used it for a little while but as I become more familiar with Lua I found it quicker to use print statements in the end.

I’ll look at it. thanks