i re-modified the drop function when the Mouse is Up so it will check the position of the dropped sprite if it is in the area of the region the sprite will be disappear if not the nothing happen.
here is the code:
function CLL:DragonMouseUpN(event)
if self.isFocus then
if( (self:getY()>(800))
and (self:getY()<(1000))
and (self:getX()<(900))
and (self:getX()<(1000))) then
self.nood:setVisible(false)
self.isFocus = false --unmark
event:stopPropagation()
else
self.isFocus = false --unmark
event:stopPropagation()
end
end
end
Comments
The x and y coordinate seem too large, what is your device settings?
Ultimate Games on Appstore
Ultimate Games on Google Play
But I sill get the same error"attempt to index field 'nood' (a nil value)"
Sorry for bad english
self.noodles=Bitmap.new(Texture.new("pics/nood.png"))
self.nood=Bitmap.new(Texture.new("pics/nood.png"))
application:setOrientation(Application.LANDSCAPE_LEFT)
------ADD images-------------------------------------------------
--bg
local bg = Bitmap.new(Texture.new("pics/bg.png"))
self:addChild(bg)
localScore = 0
counter=1
--pot
pot=Bitmap.new(Texture.new("pics/pot.png"))
pot:setAnchorPoint(0.5,0.5)
pot:setPosition(980,900)
print(pot:getHeight())
self:addChild(pot)
--fire
fire = FireB.new()
fire:setPosition(600,1100)
self:addChild(fire)
--steam
steam=SteamB.new()
steam:setPosition(660,350)
self:addChild(steam)
--[[splash
splash=Bitmap.new(Texture.new("pics/splash.png"))
splash:setAnchorPoint(0.5,0.5)
splash:setPosition(0.64,0.28)
self:addChild(splash)]]--
self.oil=Bitmap.new(Texture.new("pics/oil_bottle.png"))
self.oil:setAnchorPoint(0.5,0.5)
self.oil:setPosition(1600,400)
self:addChild(self.oil)
--noodles
self.noodles=Bitmap.new(Texture.new("pics/noodles.png"))
self.noodles:setAnchorPoint(0.5,0.5)
self.noodles:setRotation(120)
self.noodles:setPosition(200,400)
self:addChild(self.noodles)
--------------------------Images end----------------------
--------------------------Fade Ingredent------------------
self:FadeIng()
-------------------------Enf Fade Ingredient--------------
--------------------------Event Listener------------------
--noodles
self.noodles:addEventListener(Event.MOUSE_DOWN, self.DragonMouseDown, self.noodles)
self.noodles:addEventListener(Event.MOUSE_MOVE, self.DragonMouseMove, self.noodles)
self.noodles:addEventListener(Event.MOUSE_UP, self.DragonMouseUpN, self.noodles)
--[[oil
self.oil:addEventListener(Event.MOUSE_DOWN, self.DragonMouseDown, self.oil)
self.oil:addEventListener(Event.MOUSE_MOVE, self.DragonMouseMove, self.oil)
self.oil:addEventListener(Event.MOUSE_UP, self.DragonMouseUp, self.oil)
--]]
--Fire
--self:addEventListener(Event.TIMER, self.onTimer,self)
-------------------------End Event Listener---------------
end
-------------------------Function----------------------------
------Drag functions
function Balaleetp3:DragonMouseDown(event)
if self:hitTestPoint(event.x, event.y) then
self.isFocus = true -- mark to chk whether it is selected or not
self.x0 = event.x--store initial position of touch
self.y0 = event.y
event:stopPropagation() --stop all the touch events or mouse event
end
end
function Balaleetp3:DragonMouseMove(event)
if self.isFocus then
local dx = event.x - self.x0--get the diff of initial pos and current touch pos
local dy = event.y - self.y0
self:setX(self:getX() + dx) -- add this diff to img's x and y pos
self:setY(self:getY() + dy)
self.x0 = event.x -- change the initial pos with new one
self.y0 = event.y
event:stopPropagation()
end
end
function Balaleetp3:DragonMouseUpN(event)
if self.isFocus then
if( (self:getY()>(610))
and (self:getY()<(1190))
and (self:getX()>(306))
and (self:getX()<(1654))) then
self.noodles:setVisible(false)
self.isFocus = false --unmark
event:stopPropagation()
else
self.isFocus = false --unmark
event:stopPropagation()
end
end
end
-------------Fade Function
function Balaleetp3:onTimer(timer)
fade = Fade.new(self)
stage:addChild(fade)
end
function Balaleetp3:FadeIng()
--counter = counter + 1
local IngNo= math.random(1,2)
--noodles
if (IngNo == 1) then
local Nodmovie = MovieClip.new{
{1,30, self.noodles, {alpha=0}},
{31, 60, self.noodles, {alpha = {0, 1, "easeOut"}}
}
}
Nodindex = self:getChildIndex(self.noodles)
self:addChildAt(Nodmovie,Nodindex)
Nodmovie:play()
IngID=1
elseif (IngNo == 2) then
--oil
Oilmovie = MovieClip.new{
{1,30, self.oil, {alpha=0}},
{31, 60, self.oil, {alpha = {0, 1, "easeOut"}}}
}
Oilindex = self:getChildIndex(self.oil)
self:addChildAt(Oilmovie,Oilindex)
Oilmovie:play()
IngID=2
end
end
self.noodles:addEventListener(Event.MOUSE_MOVE, self.DragonMouseMove, self.noodles)
self.noodles:addEventListener(Event.MOUSE_UP, self.DragonMouseUpN, self.noodles)
it should be
self:addEventListener(Event.MOUSE_DOWN, self.DragonMouseDown, self)
self:addEventListener(Event.MOUSE_MOVE, self.DragonMouseMove, self)
self:addEventListener(Event.MOUSE_UP, self.DragonMouseUpN, self)
because you are adding to self.noodles sprite and then trying to reach self.noodles.noodles
Thus you have to do: