Mouse control

About advanced scenes, and the Thyme scripting language used in Algodoo.

Mouse control

Postby Nait » Sat Dec 19, 2009 9:17 am

If there is any detection of mouse "mousedown", like key "mouseleft"? :?:
Thanks beforehand! :!:
User avatar
Nait
 
Posts: 224
Joined: Fri Oct 30, 2009 1:56 am
Location: Eastern Russia, Vladivostok

Re: Mouse control

Postby KarateBrot » Sat Dec 19, 2009 3:18 pm

I already got an idea for a code. I'll post it when it's ready.
Image
User avatar
KarateBrot
 
Posts: 825
Joined: Mon Aug 31, 2009 7:32 pm
Location: Germany

Re: Mouse control

Postby Kilinich » Sat Dec 19, 2009 3:21 pm

What do you mean mouse down? Mouse key down or mouse movement?
Dream of Algodoo as game development engine...
User avatar
Kilinich
[Best bug reporter 2010]
 
Posts: 2098
Joined: Mon Aug 31, 2009 8:27 pm
Location: South Russia

Re: Mouse control

Postby KarateBrot » Sat Dec 19, 2009 4:54 pm

Oh, I didn't think of that. I thought you want to get the mouse movement.
If you want something that detects if a mouse button is pressed you can do that with mechanics in algodoo. For the movmement I made this:

Rating: rated 6.8
Filesize: 9.47 kB
Comments: 6
Ratings: 5
download


Code: Select all
Scene.my.p1 := [0, 0];

Scene.my.move := "";

Scene.my.mousemovement :=
{
    posdiff := app.mousepos - scene.my.p1;
    scene.my.p1 = app.mousepos;
    move := "";
    (posdiff(0) ^ 2 + posdiff(1) ^ 2) ^ 0.5 > 0.01 ? {
        a := math.acos(posdiff(0) / (posdiff(0) ^ 2 + posdiff(1) ^ 2) ^ 0.5);
        posdiff(1) < 0 ? {a = 2 * math.pi - a} : {};
        math.or(a <= math.pi / 4, a > 7 * math.pi / 4) ? {scene.my.move = "right"} : {a <= 3 * math.pi / 4 ? {scene.my.move = "up"} : {a <= 5 * math.pi / 4 ? {scene.my.move = "left"} : {a <= 7 * math.pi / 4 ? {scene.my.move = "down"} : {}}}}
    } : {scene.my.move}
}
Image
User avatar
KarateBrot
 
Posts: 825
Joined: Mon Aug 31, 2009 7:32 pm
Location: Germany

Re: Mouse control

Postby Nait » Sun Dec 20, 2009 6:28 am

I mean mouse click, I ask becouse I know that in Visual Basic it can identify if button is pressed or if it goes back after click.
User avatar
Nait
 
Posts: 224
Joined: Fri Oct 30, 2009 1:56 am
Location: Eastern Russia, Vladivostok

Re: Mouse control

Postby KarateBrot » Sun Dec 20, 2009 10:25 am

Something like this?

Rating: rated 6.1
Filesize: 11.86 kB
Comments: 0
Ratings: 3
download


If you want to check how it works look at the left hand side. There's an invisible collision checker.

Code: Select all
Scene.my.presstime := -1;
Scene.my.mouseleft := {(sim.time - scene.my.presstime) < 0.05 ? {true} : {false}};
Scene.my.presstime2 := -1;
Scene.my.mouseright := {(sim.time - scene.my.presstime2) < 0.05 ? {true} : {false}}
Image
User avatar
KarateBrot
 
Posts: 825
Joined: Mon Aug 31, 2009 7:32 pm
Location: Germany


Return to Thyme scripting

Who is online

Users browsing this forum: No registered users and 1 guest

cron