Anyone have any ideas on this? [import]uid: 40786 topic_id: 11959 reply_id: 311959[/import]
you can do a spritesheet animation with the leaf swinging in a loop.
you can use the physics engine to make the sprite fall [import]uid: 13632 topic_id: 11959 reply_id: 43600[/import]
spritesheet animation?
use the sine function, man!
val.object.x = val.object.x + math.sin(val.w) \* 3
val.w = val.w + 0.05
[import]uid: 70635 topic_id: 11959 reply_id: 43606[/import]
how do I need to apply this formula?
[import]uid: 40786 topic_id: 11959 reply_id: 43609[/import]
but actually it would be better to do this if you want to use the physics engine:
(you will have to tweak the physics parameters to get the best result)
[lua]local physics = require( “physics” )
physics.start()
physics.setScale ( 30 )
physics.setGravity (0, 1)
local leaf = display.newImageRect( “leaf.png”, 40, 10 )
leaf.x, leaf.y = 140, 140
physics.addBody( leaf, { density=0.2, friction=0.9, bounce=0.2} )
local w = 0
local function loop()
local force = math.cos(w) * 2
leaf:applyForce( force, 0, leaf.x, leaf.y )
w = w + 0.1
end
timer.performWithDelay ( 20, loop, 300 )
[import]uid: 13632 topic_id: 11959 reply_id: 43622[/import]
you need to put the sine calculations into somekind of loop.
you could do something like this:
[lua]local leaf = display.newImageRect( “leaf.png”, 40, 10 )
leaf.x, leaf.y = 140, 140
local w = 0
local function loop()
leaf.y = leaf.y + 1
leaf.x = leaf.x + math.sin(w) * 5
w = w + 0.1
end
timer.performWithDelay ( 10, loop, 300 )
[/lua]
[import]uid: 13632 topic_id: 11959 reply_id: 43620[/import]
thanks all finally i got it…!! [import]uid: 40786 topic_id: 11959 reply_id: 43624[/import]
is there a way to do it using joints like distance or pivot joints? [import]uid: 40786 topic_id: 11959 reply_id: 43645[/import]
no I wouldn’t do that. as the name joint indicates they are used to attach physics bodies to each other.
If you want a more realistic simulation you could add some kind of random force to the loop…
[import]uid: 13632 topic_id: 11959 reply_id: 43654[/import]