Hey, it’s me with the items bar again! This time, what I want to do is completely different. Here it is:
By the way: If you have seen my ‘items bar lock view’ forum topic, you’ll know what my items bar is. If you haven’t visited that topic, do so now.
-
What I want to do:
I want to use my external library dragIt (created from movieclip.lua) to make a drag function that only drags if the touch is not in the items bar. -
My dragIt code: (modified for items bar dilemma)
module(..., package.seeall)
local function dragMe(self, event)
local g=event.target
local onPress = self.\_onPress
local onDrag = self.\_onDrag
local onRelease = self.\_onRelease
local iCrossedOver=false
function decideIfCrossed()
if event.y\<119 then
iCrossedOver=true
end
end
decideIfCrossed()
if event.phase == "began" and (not iCrossedOver) then
decideIfCrossed()
display.getCurrentStage():setFocus( self )
g.\_startX = event.x - g.x
g.\_startY = event.y - g.y
if onPress then
result = onPress( event )
end
elseif event.phase == "moved" and (not iCrossedOver) then
decideIfCrossed()
if transpose == true then
if limitX ~= true then
g.x = g.\_startX - (event.yStart - event.y)
end
if limitY ~= true then
g.y = g.\_startY + (event.xStart - event.x)
end
else
if limitX ~= true then
g.x = event.x - g.\_startX
if (dragBounds) then
if (g.x \< dragLeft) then g.x = dragLeft end
if (g.x \> dragLeft + dragWidth) then g.x = dragLeft + dragWidth end
end
end
if limitY ~= true then
g.y = event.y - g.\_startY
if (dragBounds) then
if (g.y \< dragTop) then g.y = dragTop end
if (g.y \> dragTop + dragHeight) then g.y = dragTop + dragHeight end
end
end
end
if onDrag then
result = onDrag( event )
end
elseif event.phase == "ended" and (not iCrossedOver) then
decideIfCrossed()
display.getCurrentStage():setFocus( nil )
gX=g.x
gY=g.y
if onRelease then
self.y=gY
self.x=gX
result = onRelease( event )
end
end
return true
end
function setDrag( item, params )
if ( params ) then
if params.drag == true then
limitX = (params.limitX == true)
limitY = (params.limitY == true)
transpose = (params.transpose == true)
dragBounds = nil
if ( params.onPress and ( type(params.onPress) == "function" ) ) then
item.\_onPress = params.onPress
end
if ( params.onDrag and ( type(params.onDrag) == "function" ) ) then
item.\_onDrag = params.onDrag
end
if ( params.onRelease and ( type(params.onRelease) == "function" ) ) then
item.\_onRelease = params.onRelease
end
if ( params.bounds and ( type(params.bounds) == "table" ) ) then
dragBounds = params.bounds
dragLeft = dragBounds[1]
dragTop = dragBounds[2]
dragWidth = dragBounds[3]
dragHeight = dragBounds[4]
end
item.touch = dragMe
item:addEventListener( "touch", item )
else
dragBounds = nil
end
end
end
-
What my problem is:
I tried setting it to only move if the touch is under 119 (my items bar size), but if you put your finger (or pointer) over 119 after starting it in 119 or moving into 119, it makes a horribly jerky movement. I guess because it’s trying to line the main screen up with your touch. -
What is happening:
I can identify the problem. It is checking if iCrossedOver every time you move the touch. So event if you started or moved into 119, it is resetting it once you move out. I need a way to if you began or moved into 119, it to instantly cancel the movement. How would I do that?
binc
[import]uid: 147322 topic_id: 27580 reply_id: 327580[/import]

[import]uid: 52491 topic_id: 27580 reply_id: 112621[/import]