is there a way to provide "snapping" of draggable elements during game play?

xyloFUNxyloFUN Member Posts: 1,593
edited November -1 in Working with GS (Mac)
Hi,
i am wondering if I could "help" a user drag an object to the right place by snapping it to the correct location if released close enough?
If this is possible, could someone please brake down the process so that a simple person like me can understand it?

thank you ;)

Comments

  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    Hi xylo, there's an excellent template by firemaplegames called dragging/snapping to a gird, which sounds like what you want. There's a couple of rather complex algorithms used in it though; well done if you understand them!

    http://gamesalad.com/forums/topic.php?id=1894#post-10370

    :-)

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • ChunkypixelsChunkypixels Member Posts: 1,114
    Probably the easiest method would be to place transparent actors centred on the place you want the item to snap to.

    If the item your dragging touches inside the transparent actor, upon release, you change the moving actors X,Y positions to the X,Y co-ordinates at the centre of the transparent actor... thus snapping it to the new location.

    Theres probably more mathematical ways of doing it, but the system explained above should work.
  • xyloFUNxyloFUN Member Posts: 1,593
    Chunkypixels said:
    Probably the easiest method would be to place transparent actors centred on the place you want the item to snap to.

    If the item your dragging touches inside the transparent actor, upon release, you change the moving actors X,Y positions to the X,Y co-ordinates at the centre of the transparent actor... thus snapping it to the new location.

    Theres probably more mathematical ways of doing it, but the system explained above should work.

    thanks for that! And thanks gyroscope for the link, I will try to open it if Safari can handly it (crashes on most GS related links)

    OK, back to Chunkypixels ....

    yes, I like that because that is exactly what I need ... now could you/would you/please do explain how to swap coordinates? I am old and want to figure that out while i still breath :)
  • MotherHooseMotherHoose Member Posts: 2,456
    @xyloFun.... this was my project yesterday... had 25 drag-able actors that I wanted to snap to the x,y of 25 (5 instances of each of 5 actors in a grid) if the user put them there!

    two game.Attributes: (both real type)
    whereX
    whereY
    (I also have a pickIndex to track which drag-able actor is active)

    in the prototype of the final placement actor in the grid.:
    [Rule] Any
    when Actor overlaps/collides with actor of the type
    (add/select all possibles from the list)
    ---change.Attribute game.whereX to self.Position.X
    ---change.Attribute game.whereY to self.Position.Y
    (then drag instances of that actor to the screen)

    on the individual drag-able actors:
    [Rule]
    when touch is pressed
    ---change.Attribute game.pickIndex To: the appropriate #

    [Rule]
    when game.pickIndex = #
    --[Rule]
    when touch is inside
    --constrain attributes for drag
    --[Rule]
    when touch is released
    ---[Rule]
    when actor overlaps/collides with actor with type
    ---changeAttribute self.Position.X to game.whereX
    ---changeAttribute self.Position.Y to game.whereY
    ---Timer after 0.1 second change the whereX and whereY to 0
    ---Timer after 0.2 second change pickIndex to 0

    (had this working in 8.9 without the timers... but 0.9 is so fast you need them to allow for change events)

    Sounds complicated... but once I had one working right... I just dragged behaviors to myBehaviors... and back into editor as needed and only had to change pickIndex # and collide type.

    MH
Sign In or Register to comment.