The code above has hands moving across the screen and a print statement telling me when they have passed a hit spot. I also have a touch event that plays a animation when clicked. What I want to accomplish is a timing event. I only want the animation to happen when you have clicked on the screen when the hands are inside the hit spot… Not sure how to go about this, so any help will be much appreciated… Thanks
[lua]-- LOAD PARTICLE LIB
local loqsprite = require(‘loq_sprite’)
local physics = require (“physics”)
local director = require(“director”)
physics.start()
physics.setGravity(0,0)
local rand = math.random
local moveSpeed = 4000
local screenW = display.contentWidth
local screenH = display.contentHeight
local BG = display.newImageRect(“background.png”, 1024, 768)
BG.x = screenW/2; BG.y = screenH/2
local girl = display.newImageRect(“girl.png”, 512, 785)
girl.x = 508; girl.y = 563
local hands = display.newImageRect(“hands.png”, 200, 127)
hands.x =0
hands.y = 700
physics.addBody (hands, {radius = sensorRect, isSensor = true})
hands.myName = “hands”
function moveLeft()
transition.to(hands, {time=moveSpeed, x = 10, y = hands.y, onComplete = moveRight})
end
function moveRight()
transition.to(hands, {time=moveSpeed, x = 1024, y = hands.y, onComplete = moveLeft})
end
local wfactory = loqsprite.newFactory(‘water’)
local water = wfactory:newSpriteGroup()
water.x = 508; water.y = 450
water.alpha = 0
local hitSpot = display.newImageRect(“hitSpot.png”, 240, 180)
hitSpot.x = 510; hitSpot.y = 675
hitSpot.alpha = .5
physics.addBody (hitSpot, {radius = sensorRect, isSensor = true})
hitSpot.myName = “hitSpot”
local screenTouch = function( _e )
if _e.phase == “ended” then
water:play(“water splash”)
water.alpha = 1
elseif _e.phase == “began” then
print(“begin touch”)
end
end
function hitSpot:collision(_e)
if _e.other.myName == “hands” then
print(“hands Passed”)
end
end
hitSpot:addEventListener(“collision”, hitSpot)
Runtime:addEventListener (“touch”, screenTouch)
moveRight()[/lua] [import]uid: 51459 topic_id: 14163 reply_id: 314163[/import]
[import]uid: 52491 topic_id: 14163 reply_id: 52277[/import]