Page 1 of 1

Mouse control

PostPosted: Sat Dec 19, 2009 9:17 am
by Nait
If there is any detection of mouse "mousedown", like key "mouseleft"? :?:
Thanks beforehand! :!:

Re: Mouse control

PostPosted: Sat Dec 19, 2009 3:18 pm
by KarateBrot
I already got an idea for a code. I'll post it when it's ready.

Re: Mouse control

PostPosted: Sat Dec 19, 2009 3:21 pm
by Kilinich
What do you mean mouse down? Mouse key down or mouse movement?

Re: Mouse control

PostPosted: Sat Dec 19, 2009 4:54 pm
by KarateBrot
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}
}

Re: Mouse control

PostPosted: Sun Dec 20, 2009 6:28 am
by Nait
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.

Re: Mouse control

PostPosted: Sun Dec 20, 2009 10:25 am
by KarateBrot
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}}