dragIt [CODE]

I made a ‘transposition’ of movieclip.lua’s drag function into a new library. My simple little editing now allows you to add local dragIt=require "dragIt" at the top of your code and use the movieclip function setDrag. It works exactly the same as the movieclip function, only now, instead of saying animation:setDrag{drag, bounds}, now you can add drag to anything (not just a a movieclip animation) by calling, dragIt:setDrag(myObject, {drag, bounds}. Here is the edited version of movieclip’s drag function to put in another library:

PLEASE NOTE:
I did not write this. Credit goes where credit is due. This is by Ansca. I only made some slight changes to set it to be able to drag anything.

 local function dragMe(self, event)  
 local g=event.target  
 local onPress = self.\_onPress  
 local onDrag = self.\_onDrag  
 local onRelease = self.\_onRelease  
  
 if event.phase == "began" then  
 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" then  
  
 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 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  
 item:removeEventListener( "touch", item )  
 dragBounds = nil  
  
 end  
 end  
 end  

binc [import]uid: 147322 topic_id: 27488 reply_id: 327488[/import]

ERROR: In the above post, I said you could use dragIt:setDrag. That is not correct. The function is, dragIt.setDrag. It is a dot instead of a colon. [import]uid: 147322 topic_id: 27488 reply_id: 111999[/import]

Can’t you edit your own post? [import]uid: 116842 topic_id: 27488 reply_id: 112003[/import]

I didn’t see that I could. Where can you do that? I know you could edit it in the other website, but I didn’t see that option in this one. I know you can with replies, but I don’t know about main topics. [import]uid: 147322 topic_id: 27488 reply_id: 112006[/import]

Ah, no, i don’t know haha. I didn’t start any topic yet. [import]uid: 116842 topic_id: 27488 reply_id: 112007[/import]

It looks like “edit” option is hidden at the moment. (I tracked down my old post, and I don’t see the “edit” anymore.) Let’s hope it’ll get fixed soon. (Note: To clarify, I can edit all of my “reply” post, but not the original/new topic I’ve started – before the transition to the new website, I was able to edit my topic.)

Naomi [import]uid: 67217 topic_id: 27488 reply_id: 112019[/import]

Haha. Everything in this post is about editing posts. [import]uid: 147322 topic_id: 27488 reply_id: 112074[/import]

Hey,

I couldn’t find the “edit” at first either. (I know the new forum is, uhm, “questionable”. Hopefully before long we’ll have a new one.)

I can see an edit bottom near the very bottom of the page under the “Save” and “Preview” buttons that show up under the box you type in to reply to the thread.

I know it isn’t intuitive but using that (if you can see it?) you should be able to modify your threads.

Peach :slight_smile: [import]uid: 52491 topic_id: 27488 reply_id: 112146[/import]