Please login or register.

Login with username, password and session length
Advanced search  

News:

This forum provides RSS feed. To query recent posts use this url. More...


Author Topic: Click and drag sprites  (Read 1596 times)

0 Members and 1 Guest are viewing this topic.

TheDerman

  • Regular poster
  • ***
  • Karma: 0
  • Offline Offline
  • Posts: 225
    • View Profile
Click and drag sprites
« on: August 25, 2007, 02:34:27 PM »

Hi all,

I'm trying to make ye olde favourite puzzle - the torn letter that must be put back together puzzle.  ;D ::rock

So, I want to be able to click a sprite on screen and while the mouse button is down, drag it around the screen. I didn't find any way to already do this so I did some script:

Code: [Select]
#include "scripts\base.inc"

var MoveTest = Scene.GetNode("move_test");
var IsLeftDown = false;

////////////////////////////////////////////////////////////////////////////////
on "LeftClick"
{
  IsLeftDown = true;

  while(true)
    {
     if (IsLeftDown==true)
      {
       MoveTest.X = Game.MouseX;
       MoveTest.Y = Game.MouseY;
       Sleep(50);
      }
    }
}

on "LeftRelease"
{
  IsLeftDown = false;
  MoveTest.X = MoveTest.X;
  MoveTest.Y = MoveTest.Y;
}


This works fine whilst the left button is down, but when it's released, the game crashes. So, obviously something is wrong. Something probably to do with the "leftrelease" part I think.

EDIT:

Sorted it out.  ::rock

Code: [Select]
#include "scripts\base.inc"

var MoveTest = Scene.GetNode("move_test");
var IsLeftDown = false;

////////////////////////////////////////////////////////////////////////////////
on "LeftClick"
{
  IsLeftDown = true;

  while(IsLeftDown==true)
    {
       MoveTest.X = Game.MouseX;
       MoveTest.Y = Game.MouseY;
       Sleep(50);
    }
}

on "LeftRelease"
{
  IsLeftDown = false;
  MoveTest.X = MoveTest.X;
  MoveTest.Y = MoveTest.Y;
}

« Last Edit: August 25, 2007, 02:50:05 PM by TheDerman »
Logged
 

Page created in 0.352 seconds with 18 queries.