Any examples out there of a "line tool" effect for GS?
part12studios
Member Posts: 620
i've seen demos where its like you can draw a line like MS Paint and such.. but i was wondering if anyone has done it where imagine no matter where your mouse position is.. a line stays connected stretching and rotating so its always connected between a spot on the screen and the mouse position.
for Photoshop users.. click the line tool and click and hold seeing a line constantly tracking the mouse.
Thanks
Caleb
for Photoshop users.. click the line tool and click and hold seeing a line constantly tracking the mouse.
Thanks
Caleb
Best Answers
-
RThurman Posts: 2,881Almost there! Multiply magnitude by 2 and then add two x,y constrains. Like this:
Constrain Attribute: self.Size.Width To: (magnitude(game.Mouse.Position.X-self.Position.X,game.Mouse.Position.Y-self.Position.Y)*2
Constrain Attribute: self.Position.X To: 240+( game.Mouse.Position.X -240)/2
Constrain Attribute: self.Position.Y To: 160+( game.Mouse.Position.Y -160)/2
-
RThurman Posts: 2,881@part12studios Very, very, close!
You need to change the constrain for the xPosition to:
240+( game.Mouse.Position.X -240)/2
Right now you have self.Position.X in there (instead of mouse position).
Also I would suggest you change the self.rotation constraint to:
vectorToAngle( game.Mouse.Position.X-240, game.Mouse.Position.Y-160)
Right now you have it backward and its giving you the opposite angle.
Other than that -- it should work for you as you are expecting.
Answers
it seems like fundamentally all i'd want to do is what this template does.. except rather than continuously updating where the last point was and the next mouse point.. i'd just keep a fixed "origin" point and keep redrawing the line to connect from there to where the mouse is at... but i'm weak in the function/math stuff.. so i can't really understand how i could achieve this. vector to angle / cosign / magnitude.. i understand their descriptions but the application of them still confuses me.
ok so here is where i'm getting stuck.. i understand how to do vector to angle.. and magnitude is working..
the part i can't figure out is how to get the growing/shrinking line to not be centered on the middle of the screen. I mean i understand why it is where it is..you can see the project file here https://www.dropbox.com/sh/f6rk3zzfoj2cgzk/ztIQyE3aJC
It seems like if i could figure out the distance between the 240x160 position and the mouse and then divide that by 2 i'd know where it needs to be, but constraints only work on one value at a time and magnitude wants an x and y.. so my efforts there end up with crazy moving lines..
what i would want is one side to stay stationary while the other end touches the mouse.. i can get this effect if i ad a *2 to the magnitude, but of course then i end up with this huge other counter-side which is not the desired effect.. something like this http://alienryderflex.com/point_left_of_ray/point_left_of_ray_0.gif
Thanks!
Caleb
Now to apply it in my game. although i think that part will be manageable. So excited to apply this!
Thanks!
Caleb
That looks great !
Really good idea.
Good stuff !