Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 How to drag an object?
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
canmovie




PostPosted: Sat Oct 23, 2010 10:59 pm   Post subject: How to drag an object?

I'm making a lever for a slots project, so when you pull the lever to the bottom, the slots start turning, but I don't know how I can make turing act depending on the downward movement of the mouse. This is how I want it to work: You hold down the mouse button on the circle, you drag it down, and the slots start to turn. I tried to assign a variable to the y value of the circle, but I have no idea how to update it so it is the same y value as the mouse. Help please!
Sponsor
Sponsor
Sponsor
sponsor
SNIPERDUDE




PostPosted: Sat Oct 23, 2010 11:17 pm   Post subject: RE:How to drag an object?

Turing:
Mouse.Where (mouse_x, mouse_y, Mouse_button)

You need all three variables to run that command, but the ones you want to use are mouse_y, and mouse_b. mouse_b will check if the mouse button is being pressed down (an integer value, 0 = released, 1 = pressed).

Hope that helps.
canmovie




PostPosted: Sat Oct 23, 2010 11:22 pm   Post subject: Re: How to drag an object?

Ok.... Doesn't really help... I know where the mouse is, I just don't know where or how to integrate the mousewhere command. I want to be able to drag the lever down.
SNIPERDUDE




PostPosted: Sun Oct 24, 2010 6:45 pm   Post subject: RE:How to drag an object?

Think of the logics step by step. Write it on a sheet of paper if that helps (not an uncommon practice at all).

First you want to check if the mouse is within the parameters of where the lever is and if the mouse button is pressed down. Then a good idea might be to figure out at that initial click the distance between the mouse y location and the center of the handle y location. Record that number, and animate it so the lever handle follows the mouse y location (keeping that initial recorded distance so it looks smooth) until the handle reaches a certain point. Then check to see if the handle is at the bottom and the mouse is released.

Just brainstorming through the logic in my head here, I may have missed something, but this should give you an idea as to how it may happen step by step.
DanShadow




PostPosted: Mon Oct 25, 2010 1:44 pm   Post subject: RE:How to drag an object?

Thats pretty much it.
- Do a check to determine if left mouse click is down
- If it is down, set a variable to tell your program "the user is using the lever"
- While said variable is set, animate the lever based on the y-position of the users mouse relative to the top/bottom/left/right sides of the lever
- When the user releases the left mouse click button, disable the variable, and determine what position the lever is in (closer to the top, or closer to the bottom)
- If it is within your desired distance to the bottom of the lever (aka, the lever is down), active your lottery scripts
Dan




PostPosted: Mon Oct 25, 2010 3:04 pm   Post subject: Re: How to drag an object?

As I was board, so I thought i would make you a simple example:

Turing:

View.Set ("offscreenonly")

var x, y, b : int
var box_x, box_y : int := 10
var box_width, box_height : int := 50
var moving : boolean := false

var start_x, start_y : int := -1
var offset_x, offset_y : int

loop
    cls
    Draw.FillBox (box_x, box_y, box_x + box_width, box_y + box_height, 1)
    Mouse.Where (x, y, b)

    if b not= 0 and not moving then
        if x > box_x and x < box_x + box_width and y > box_y and y < box_y + box_height then   
            moving := true
            offset_x := x - box_x
            offset_y := y - box_y
        end if
    elsif b = 0 and moving then
        moving := false
    end if

    if moving then
        box_x := x - offset_x
        box_y := y - offset_y
    end if

    if start_x not= box_x or start_y not= box_y then
        View.Update()
    end if
end loop


This example shows how to use Mouse.Where to move a box around the screen. Obvesly you can't just copy and past this into your program as you want to do somthing diffrent, but it does contain the same logic you will need. The only diffrence is you want to limit where the box can be draged.
Computer Science Canada Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more!
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 6 Posts ]
Jump to:   


Style:  
Search: