Hi guys!!, maybe a simple problem, but is breaking my head! haha.
I'm making appear images (blue square) when the background is touched, but I also have a green square that I can drag. The problem is that when I try to drag de green square, a blue square appear over the green square because I did a touch. How can I avoid to make appear the blue square over the green square when I touch the screen to drag the green square?.
the code is this:
local physics = require("physics")
local gameUI = require("gameUI")
local easingx = require("easingx")
local movieclip = require( "movieclip" )
local ui = require( "ui" )
--***VARS************
physics.start()
system.activate( "multitouch" )
physics = require("physics")
physics.setGravity(0,9.8)
local baseline = 290
_H = display.contentHeight
_W = display.contentWidth
mRand = math.random
--*************************
--************BACKGROUND************
local bkg = display.newImage( "background.jpg", true )
bkg.x = display.contentWidth/2
bkg.y = display.contentHeight/2
--*********************************
--********GREEN SQUARE*********************
local object2 = display.newRect(0, 0, 50, 50) --green
object2.x = _W / 2
object2.y = _H / 3
object2:setFillColor(0, 255, 0)
physics.addBody(object2, "kinematic", {density = 1.0, friction = 1, bounce = 0.2})
object2.myName = "object2"
--********************************************
--*****GREEN SQUARE DRAGGABLE***********
local function dragObject2 (event)
object2.x = event.x
object2.y = event.y
end
object2:addEventListener ("touch", dragObject2)
--********************************************
--********APPEAR BLUE SQUARE WHEN THE BACKGROUND IS TOUCHED*********
local function spawnDisk( event )
local phase = event.phase
if "began" == phase then
audio.play( popSound )
myLabel.isVisible = false
local disk = display.newRect(0, 0, 50, 50)
disk.x = event.x
disk.y = event.y
disk:setFillColor(0, 0, 255)
transition.to(disk, { time = 500, xScale = 1.0, yScale = 1.0, transition = easingx.easeOutElastic }) -- "pop" animation
physics.addBody(disk, "kinematic", {density = 1.0, friction = 1, bounce = 0.2})
disk.linearDamping = 0.4
disk.angularDamping = 0.6
end
end
bkg:addEventListener( "touch", spawnDisk ) -- touch the screen to create disks
--********************************************