Please login or register.

Login with username, password and session length
Advanced search  

News:

Forum rules - please read before posting, it can save you a lot of time.

Author Topic: Need help with LeftRelease, please  (Read 2696 times)

0 Members and 1 Guest are viewing this topic.

warmblood

  • Supporter
  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Female
  • Posts: 18
    • View Profile
Need help with LeftRelease, please
« on: July 12, 2008, 04:17:33 AM »


I have a scene in an educational matching game where I drag and drop entities. (The approach I took was the same as TheDerman's Click and drag sprites topic here: http://forum.dead-code.org/index.php?topic=2269.0 -- the corrected code, of course.) It is slightly different in that If the entity is dropped close enough to the target location, it snaps into place. If it is too far away, it goes back to the original location.

Everything works beautifully EXCEPT sometimes (quite often) the LeftRelease event doesn't seem to trigger, and I'm left with the entity "stuck" to the mouse.  Sometimes I can get it unstuck if I click really fast, or if I go and pick up another entity (since they all use the same LeftButtonIsDown flag.) Sometimes after that the formerly stuck entity will correctly drag and position to the target location, but other times it just lies there, broken.

Has anyone else run into this problem? Any ideas on how I might try to resolve this? I'm not looking for code, just some ideas to try. Thanks!

Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5679
    • View Profile
    • Dead:Code Site
Re: Need help with LeftRelease, please
« Reply #1 on: July 12, 2008, 07:09:05 AM »

The important thing to remember is that the entity only receives the release event if the mouse pointer is above the entity, which may not me the case during the dragging (the entity position is not updated as frequently as the mouse pointer position).
In Five magical amulets I overcame this problem by always moving the *center* of the entity to the mouse pointer when starting the dragging. Other solution is to handle the LeftRelease directly in game.script and route it to your dragged entity.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

warmblood

  • Supporter
  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Female
  • Posts: 18
    • View Profile
Re: Need help with LeftRelease, please
« Reply #2 on: July 13, 2008, 12:58:43 AM »

Brilliant!

Thanks so much, Mnemonic.  This was just the info I needed.  I went with the second option, because the entity that I'm dragging is fairly small (a text label) -- which explains why it kept losing the mouse focus.  Now it works great!

If anyone wants to know what I did, here is a summary:

1) Used two global variables: LeftButtonIsDown and DragEntityName (which were initialized in scene_init.script to false and null respectively)
to keep track of when the left button was clicked on a draggable entity, and the name of the entity that is being dragged.
2) Made the following changes to the script for my draggable entity to set the DragEntityName variable and to change the LeftRelease event handler into a method I call DragLeftRelease(). (this code fragment won't work as is -- just the changes are shown!)
Code: [Select]

on "LeftClick"
{
    LeftButtonIsDown=true; 
    DragEntityName=this.Name;
    //...
    // Other code here to make the entity follow the mouse...
    //...
}

// This method used to be the on "LeftRelease" event handler.
method DragLeftRelease ()
{
     LeftButtonIsDown=false; 
     DragEntityName=null;
    //...
    // logic to handle the entity positioning when player releases left mouse button
    // ...

}

3) Added an on "LeftRelease event handler to game.script that contains the following code, which can be used by any scene that has draggable entities:

Code: [Select]
on "LeftRelease"
{
    if (LeftButtonIsDown && DragEntityName!=null) {
        var theDraggedEntity=Scene.GetNode(DragEntityName);
        if (theDraggedEntity!=null) theDraggedEntity.DragLeftRelease();
    }
}



Logged

Prote1n

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 45
    • View Profile
Re: Need help with LeftRelease, please
« Reply #3 on: April 19, 2010, 10:48:18 AM »

I also use this method but even it's more reliable, it is not 100% secure. I also succeed sometimes to loose the 'LeftRealase" event even when it's managed in game.script .... let's say it works at 95%
Logged
 

Page created in 0.995 seconds with 23 queries.