Help using mouse input!
Help using mouse input!
Basically, what i want is to draw a line (a 10px line ), 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
I know this is really stupid but, i can't figure how to do it
My native lenguage is Spanish, so, apologies
- viruskiller
- Posts: 399
- Joined: June 14th, 2012, 5:07 pm
Re: Help using mouse input!
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:)
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:)
Re: Help using mouse input!
What lesson is that? I'm already at lesson 18.
Re: Help using mouse input!
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
- viruskiller
- Posts: 399
- Joined: June 14th, 2012, 5:07 pm
Re: Help using mouse input!
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.
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.
- viruskiller
- Posts: 399
- Joined: June 14th, 2012, 5:07 pm
Re: Help using mouse input!
and check the sticky on the forum to see when the mouse gets implemented.
Re: Help using mouse input!
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...
Re: Help using mouse input!
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?
- viruskiller
- Posts: 399
- Joined: June 14th, 2012, 5:07 pm
Re: Help using mouse input!
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.
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.
Re: Help using mouse input!
yeap, I finally did it, but the resulting code was way to long.. Anyway, I'm happy with that for now, thanks a lot