Again, here I go with the items box. Here is the link to my two previous ‘items box’ threads:
Items bar lock view
[ display.getCurrentStage():setFocus( self )
iCr()
g._startX = event.x - g.x
g._startY = event.y - g.y
if onPress then
result = onPress( event )
end
elseif event.phase == “moved” then
iCr()
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” then
display.getCurrentStage():setFocus( nil )
gX=g.x
gY=g.y
if onRelease then
self.y=gY
self.x=gX
result = onRelease( event )
end
end
– stop touch from falling through to objects underneath
return true
end
function setDragItemsBox( 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 = dragMeItemsBox
listener=item:addEventListener( “touch”, item )
else
item:removeEventListener ( “touch”, item )
dragBounds = nil
end
end
end
public.setDragItemsBox=setDragItemsBox
return public
[/code]
Now, if you drag the screen to either side, and then deactivate the dragMe function, you can’t drag it any more. So far so good. But, if the drag ability is deactivated, and you try to move a tile, the tile jumps to the beginning x of the scroll group. How would I get it to not jump to that point?
binc [import]uid: 147322 topic_id: 27824 reply_id: 327824[/import] ](http://developer.anscamobile.com/forum/2012/06/16/items-bar-again>Items%20bar%20again
Here%20is%20my%20dragIt%20itemsBox%20function:
%5Bcode%5D
local%20public=%7B%7D
%20%20%20%20%20%20%20
%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20local%20function%20dragMeItemsBox(self,%20event)
%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20local%20g=event.target
%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20local%20onPress%20=%20self._onPress
%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20local%20onDrag%20=%20self._onDrag
%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20local%20onRelease%20=%20self._onRelease
%09%09%09%09local%20iCro=false
%09%09%09%09function%20iCr()
%09%09%09%09%09if%20event.y<119%20then
%09%09%09%09%09%09g._startX%20=%20event.x%20-%20g.x
%09%09%09%09%09%09g._startY%20=%20event.y%20-%20g.y
%09%09%09%09%09end
%09%09%09%09end
%09%09%09%09
%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20if%20event.phase%20==%20)