ok i try and implement the code on the link you provided + yours and i am getting an error when it calls hascollided:
[C]: in function ‘hasCollided’
…nsel rios\documents\corona projects\ejemplo\game.lua:187: in function
<…nruntime error> …nsel rios\documents\corona projects\ejemplo\game.lua:187: attempt to
call global ‘hasCollided’ (a nil value)
stack traceback:
[C]: in function ‘hasCollided’
…nsel rios\documents\corona projects\ejemplo\game.lua:187: in function
<…nruntime error> …nsel rios\documents\corona projects\ejemplo\game.lua:187: attempt to
call global ‘hasCollided’ (a nil value)
stack traceback:
[C]: in function ‘hasCollided’
…nsel rios\documents\corona projects\ejemplo\game.lua:187: in function
<…n>
here is the code for my drag event:
[lua]local function drag ( event )
local t = event.target
local phase = event.phase
if “began” == phase then
local parent = t.parent
parent:insert( t )
display.getCurrentStage():setFocus( t, event.id )
t.isFocus = true
t.x0 = event.x - t.x
t.y0 = event.y - t.y
if click < 2 then
click = click + 1
elseif click == 2 then
click = 1
end
if click == 1 then
oracion:insert(t)
elseif click == 2 then
if Fase == 1 then
Parte1:insert(t)
elseif Fase == 2 then
Parte2:insert(t)
elseif Fase == 3 then
Parte3:insert(t)
end
end
local function hasCollided(t, boton1)
if t == nil then
return false
end
if boton1 == nil then
return false
end
local left = t.contentBounds.xMin <= boton1.contentBounds.xMin and t.contentBounds.xMax >= boton1.contentBounds.xMin
local right = t.contentBounds.xMin >= boton1.contentBounds.xMin and t.contentBounds.xMin <= boton1.contentBounds.xMax
local up = t.contentBounds.yMin <= boton1.contentBounds.yMin and t.contentBounds.yMax >= boton1.contentBounds.yMin
local down = t.contentBounds.yMin >= boton1.contentBounds.yMin and t.contentBounds.yMin <= boton1.contentBounds.yMax
return (left or right) and (up or down)
end
elseif t.isFocus then
if “moved” == phase then
if hasCollided(t, boton1) then
t.x = boton1.x
t.y = boton1.y
else
t.x = event.x - t.x0
t.y = event.y - t.y0
end
elseif “ended” == phase or “cancelled” == phase then
display.getCurrentStage():setFocus( t, nil )
t.isFocus = false
end
return true
end
end
YoQuiero:addEventListener(“touch”, drag )
NoQuiero:addEventListener(“touch”, drag )
comer:addEventListener(“touch”, drag )
tomar:addEventListener(“touch”, drag )
egg:addEventListener(“touch”, drag )
pancake:addEventListener(“touch”, drag )
leche:addEventListener(“touch”, drag )
cereal:addEventListener(“touch”, drag )
pan:addEventListener(“touch”, drag )
egg:addEventListener(“touch”, drag )[/lua]
since i am unfamiliar in the used of the tables, i am assigning one by one the event listener. I assigned the event to the pics that i want to move, and if the collide with a static image below, they snap in with the static image.
any help on why this is failing??
[import]uid: 123133 topic_id: 22616 reply_id: 91263[/import] </…n></…nruntime></…nruntime>