Help using mouse input!

The Partridge Family were neither partridges nor a family. Discuss.
Post Reply
Carlows
Posts: 10
Joined: June 1st, 2013, 12:31 pm

Help using mouse input!

Post by Carlows » June 1st, 2013, 12:45 pm

Basically, what i want is to draw a line (a 10px line :mrgreen: ), but i only want the line to move depending the mouse movement, i mean, the line cant change its lenght, it only moves depending where the mouse is.

I know this is really stupid but, i can't figure how to do it :(

My native lenguage is Spanish, so, apologies :shock:

User avatar
viruskiller
Posts: 399
Joined: June 14th, 2012, 5:07 pm

Re: Help using mouse input!

Post by viruskiller » June 1st, 2013, 11:55 pm

well that;s quite easy to do:P

you can use the draw line function that chili teached us.

second u need to make it so it moves with the cursor.

first get 2 global variables
int x;
int y;

initialize these to x400 y300 ;

then in compose frame have x = mouse coordinates; and y= mouse coordinates;

then in the draw frame function put a draw line call with the x and y and color of your choice, also if u want the line centerd on the cursor then have an offset into the direction of the line, like if is a horizontal line of 10 pixel in length have it start at x-5 and end at x+4.

if u haven't watched the lesson where chili implements mouse support then u have to wait till then:)

Carlows
Posts: 10
Joined: June 1st, 2013, 12:31 pm

Re: Help using mouse input!

Post by Carlows » June 2nd, 2013, 1:25 am

What lesson is that? I'm already at lesson 18.

Carlows
Posts: 10
Joined: June 1st, 2013, 12:31 pm

Re: Help using mouse input!

Post by Carlows » June 2nd, 2013, 1:45 am

lets see, if i do that you tell me, i will draw a line between a point X or Y, to the mouse position, isn't it? but i don't want to draw the line to the exactly mouse position, i only want to draw a 10 pixels between the starting point, to anywhere the mouse is

User avatar
viruskiller
Posts: 399
Joined: June 14th, 2012, 5:07 pm

Re: Help using mouse input!

Post by viruskiller » June 3rd, 2013, 12:53 am

ah then i missunderstood what u want to do:p, i tought u want to have something like a 10 pixel line cursor.
if u just want to draw a 10 pixel line from a point in the direction of the mouse u need a new draw line function.
u can use the old draw line function and do a check with the code from circle draw function to see when the pixel drawn is more than 10 pixels away from the origin, when it goes beyond 10 pixels just finish the drawing.

User avatar
viruskiller
Posts: 399
Joined: June 14th, 2012, 5:07 pm

Re: Help using mouse input!

Post by viruskiller » June 3rd, 2013, 12:54 am

and check the sticky on the forum to see when the mouse gets implemented.

Carlows
Posts: 10
Joined: June 1st, 2013, 12:31 pm

Re: Help using mouse input!

Post by Carlows » June 3rd, 2013, 10:17 pm

well.. im killing my mind with this, i put a count that breaks the drawing when the 10 pixel are drawn, the problem is, there are some parts where the for loops towards the center and not from the center, im trying to fix it, but always at some point the cycle starts at the wrong side...

Carlows
Posts: 10
Joined: June 1st, 2013, 12:31 pm

Re: Help using mouse input!

Post by Carlows » June 3rd, 2013, 10:24 pm

otherwise, what i want to do is something like the game that chilli is playing at lesson 22, the rectangle always follow the mouse direction, does anybody knows how to implement that? isn't there the source code of that game? :-(

User avatar
viruskiller
Posts: 399
Joined: June 14th, 2012, 5:07 pm

Re: Help using mouse input!

Post by viruskiller » June 4th, 2013, 2:06 am

don't think so, the problem u have lies inside the draw line function:P
thing is is coded in such a way that if the line goes up and to the left it actually starts from the end towards the center to reuse the code used for when the line goes down and to the right.
you would have to study the draw line function and code it so it always draws from center out.
to do that u would need some reverse math, like going from 0 to - something and doing x-- and so on.

Carlows
Posts: 10
Joined: June 1st, 2013, 12:31 pm

Re: Help using mouse input!

Post by Carlows » June 4th, 2013, 3:14 am

yeap, I finally did it, but the resulting code was way to long.. Anyway, I'm happy with that for now, thanks a lot :)

Post Reply