Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Library for drag and drop for GIDEROS — Gideros Forum

Library for drag and drop for GIDEROS

psdiaspsdias Member
edited December 2012 in Game & application design
Hello!

Sorry for my bad English!
(I used an automatic translator, and then I tried to correct my text)


I am an inexperienced programmer in "mobile" applications and, until few days.
But, yesterday, I found GIDEROS.

I am creating a simple board game, where the user must touch in some pieces
and then position it on the board (like the "checkers" however more simple)

In CORONA SDK, I was using the "dmc_dragdrop" library, because it
facilitates the movement of the pieces a lot (drag and drop)

Here is two links on that library:
http://docs.davidmccuskey.com/display/docs/Quick+Guide+-+dmc_dragdrop
http://developer.coronalabs.com/code/dmc-lib-drag-and-drop

Is there some similar library, for GIDEROS ?

Thank you for the attention!
Paulo

Comments

  • hgvyas123hgvyas123 Guru
    edited December 2012
    as far as i know there is no library for drag and drop with gideros however drag and drop functionality is very easy see the below code
     
    local function onMouseDown(self, 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
     
    local function onMouseMove(self, 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
     
    local function onMouseUp(self, event)
    	if self.isFocus then
    		self.isFocus = false --unmark 
    		event:stopPropagation()
    	end
    end
     
    local img = Bitmap.new(Texture.new("img.png"))
    img:addEventListener(Event.MOUSE_DOWN, onMouseDown, img)
    img:addEventListener(Event.MOUSE_MOVE, onMouseMove, img)
    img:addEventListener(Event.MOUSE_UP, onMouseUp, img)
    :)
  • There is a drag drop sample in sample files that come with Gideros
  • Sorry for my bad English !
    (I used an automatic translator, and then I tried to correct my text)

    Thanks, everyone, for the answers!

    Actually, I need something a little more complex.

    I would like that, when I move a piece over the board, automatically the nearest square of that piece "attract" (like a magnet) the piece for him. Thus, the user don't need positioning the piece exactly inside the "house".

    In Corona SDK, with the "dmc_dragdrop" library that I mentioned above, I got it.

    Please watch the video below, with my program running. Notice that the board squares "attract" (pull) the triangular piece for him:

    http://www.mediafire.com/?lhlcw9g5i0w0ah8

    Thank you very much !
    Paulo



  • PS: In Brazil, we call each square of the board of "house" :)
  • you can use box2d magnet or just calculate if the piece is in region
  • @psdias yes that would be more complicated than simple dragging and I think I haven't see an example of something similar on this forum.
    And unfortunately you have chosen not the best time to ask for help, since it's a winter holiday, I think no one could really help you by creating a prototype or example for now.

    But if you are up to creating the functionality yourself, the idea would be that you store all center coordinates where you could drop your triangle in a table.
    And then on mouse up or touch end loop through the table and find the nearest point, which is basic comparing of x and y coordinates.
    When you have found the nearest point simply, tween your object to it and that's it ;)
  • @psdias,
    is the triangle an image? If it is then you need to calculate the square that has the maximum portion of the rectangular image (triangle in this example) to determine where it should go. Then when the touch is released, make it tween to the square. To work with squares and board, have a look at these articles,

    http://howto.oz-apps.com/2012/11/games-with-grids-tilemaps.html
    http://howto.oz-apps.com/2012/12/working-with-grids-part-ii.html
    twitter: @ozapps | http://www.oz-apps.com | http://howto.oz-apps.com | http://reviewme.oz-apps.com
    Author of Learn Lua for iOS Game Development from Apress ( http://www.apress.com/9781430246626 )
    Cool Vizify Profile at https://www.vizify.com/oz-apps
  • Hello!

    With your suggestions, I got it !

    Thanks for everybody!

    Paulo
Sign In or Register to comment.