Hey all,
I am having trouble “spawning” an object based on a swipe. My end goal is that the player swipes (hard or slow) and it spawns a throwing object that hits a target and they both explode. I came over from UDK and Unity engines so it’s a bit of a challenge converting over (though I am loving CoronaSDK!!). I was trying to search through some code and there is soo much sample code out there! Unfortunately there is not much in the “swipe to throw” type games. So far, thanks to another Corona user, I have come up with this to get a image to spawn but it does not go anywhere and I was wondering if anyone can help me with this?
The main code I have been tweaking is the swipe right in the check direction functions
local beginX
local beginY
local endX
local endY
local xDistance
local yDistance
local bDoingTouch
local minSwipeDistance = 10
local totalSwipeDistanceLeft
local totalSwipeDistanceRight
local totalSwipeDistanceUp
local totalSwipeDistanceDown
function checkSwipeDirection()
if bDoingTouch == true then
xDistance = math.abs(endX - beginX) -- math.abs will return the absolute, or non-negative value, of a given value.
yDistance = math.abs(endY - beginY)
if xDistance \> yDistance then
if beginX \> endX then
totalSwipeDistanceLeft = beginX - endX
if totalSwipeDistanceLeft \> minSwipeDistance then
print("Swiped Left")
end
else
totalSwipeDistanceRight = endX - beginX
if totalSwipeDistanceRight \> minSwipeDistance then
print("Swiped Right")
local star = display.newImage("star.jpg")
physics.addBody(star, {density = 1, friction = 0, bounce = 0})
end
end
else
if beginY \> endY then
totalSwipeDistanceUp = beginY - endY
if totalSwipeDistanceUp \> minSwipeDistance then
print("Swiped Up")
end
else
totalSwipeDistanceDown = endY - beginY
if totalSwipeDistanceDown \> minSwipeDistance then
print("Swiped Down")
end
end
end
end
end
function swipe(event)
if event.phase == "began" then
bDoingTouch = true
beginX = event.x
beginY = event.y
end
if event.phase == "ended" then
endX = event.x
endY = event.y
checkSwipeDirection();
bDoingTouch = false
end
end
Runtime:addEventListener("touch", swipe)
Thanks! [import]uid: 183158 topic_id: 32914 reply_id: 332914[/import]