Thanks for replying ir8, but the balloon object is kinematic, so the gravity doesnt affect they. I was trying that. But it doesn´t works. The balloon is in one module and the fan in other. Here I post the code for both. Thanks again
[code]
– This is the balloon module
module(…, package.seeall)
thresholds = {}
state = {}
local function checkThreshold(obj1,obj2)
if(obj1 and obj2) then
if(obj1.y < obj2[1].boundary and obj1.y > obj2[2].boundary) then
if(obj1.multiplier == nil) then
end
–print(obj2[1].multiplier … “: thresh 1”)
obj1.multiplier = obj2[1].multiplier
elseif(obj1.y < obj2[2].boundary and obj1.y > obj2[3].boundary) then
if(obj1.multiplier == obj2[1].multiplier) then
obj1:flash()
end
obj1.multiplier = obj2[2].multiplier
–print(obj2[1].multiplier … “: thresh 2”)
elseif(obj1.y < obj2[3].boundary and obj1.y > -10) then
if(obj1.multiplier == obj2[2].multiplier) then
obj1:flash()
end
obj1.multiplier = obj2[3].multiplier
–print(obj2[1].multiplier … “: thresh 3”)
elseif(obj1.y < -10) then
if(obj1.timer) then
obj1:pop()
end
end
end
end
function newBalloon(velocity)
local balloon = display.newImageRect(“burbuja.png”, 100, 100)
balloon.x = _W/2; balloon.y = _H+20
balloon.type = “balloon”
balloon.hit = false
balloon.multiplier = nil
balloon.points = 1
balloon.tween = {start={}, finish= {}}
function balloon:flash()
local x5 = self.xScale
local y5 = self.yScale
local factor = 0.3
local function tweenBack()
transition.to(self, {time= 150, xScale = 1, yScale = 1})
end
self.tween.finish = tweenBack
self.tween.start = transition.to(self, {time= 100, xScale = x5 + factor, yScale = y5 + factor, onComplete = self.tween.finish})
end
function balloon:pop()
state:dispatchEvent({name=“change”, state=“pop”})
if(self.timer) then
timer.cancel(self.timer)
self.timer = nil
end
self.isVisible = false
if(self.tween.start) then
self.tween.start = nil
end
if(self.tween.finish) then
self.tween.finish = nil
end
self.tween = nil
self:removeSelf()
self = nil
collectgarbage(“collect”)
end
balloon.timer = timer.performWithDelay(20, function(e)
checkThreshold(balloon, thresholds)
end, -1)
physics.addBody(balloon, “kinematic”, {density= 0, bounce= 0, friction= 0, radius= 40})
balloon:setLinearVelocity(0, velocity * -1)
function balloon:touch(e)
if(e.phase == “began”) then
self.isVisible = false
end
end
balloon:addEventListener(“touch”, balloon)
return balloon
end
— HERE IS THE FAN.LUA MODULE, OR, WHAT I GOT FOR NOW
module(…, package.seeall)
function newVenti()
local venti = display.newImage(“fan.png”)
venti.x = 100; venti.y = 300
venti.type = “venti”
physics.addBody(venti, “kinematic”, {density=0.2, friction=0.2, bounce=0.5, radius= 20})
function venti:touch(event)
if event.phase == “began” then
if event.other.type == “balloon” then
balloon:setLinearVelocity(0, 10)
end
end
return true
end
venti:addEventListener(“touch”, venti)
return venti
end
[import]uid: 81363 topic_id: 19513 reply_id: 75354[/import]