Any examples out there of a "line tool" effect for GS?

part12studiospart12studios Member Posts: 620
edited October 2012 in Working with GS (Mac)
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

Best Answers

  • RThurmanRThurman Posts: 2,881
    Accepted Answer
    Almost 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
  • RThurmanRThurman Posts: 2,881
    Accepted Answer
    @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.
  • RThurmanRThurman Posts: 2,881
    Accepted Answer
    Glad it's working for you!

Answers

  • part12studiospart12studios Member Posts: 620
    This is the template i'm messing with. I wish TSB could explain this. http://gshelper.com/ink-limit-line-draw-gamesalad-video-tutorial/

    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.
  • part12studiospart12studios Member Posts: 620
    bump..

    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
  • part12studiospart12studios Member Posts: 620
    awesome i'm going to try this out tomorrow with a clear head.. thanks so much! :)
  • part12studiospart12studios Member Posts: 620
    @RThurman I had a chance to try those numbers.. not quite behaving right and i'm not sure why because I believe I follow what you're doing.. this is the updated project https://www.dropbox.com/sh/f6rk3zzfoj2cgzk/ztIQyE3aJC making the changes you outlined.. the only deviation i mad was add a second ) to the end of the (magnitude(game.Mouse.Position.X-self.Position.X,game.Mouse.Position.Y-self.Position.Y))*2 because i saw you added one at the start of (magnitude.. however with or without them, it really didn't seem to have a perceivable difference. Thanks for helping with this. I'm so excited to get this working!
  • part12studiospart12studios Member Posts: 620
    edited October 2012
    @RThurman ah ok yep now it works! :) good to know that shared links can be modified by viewers.. heh. That rocks!

    Now to apply it in my game. although i think that part will be manageable. So excited to apply this!
  • part12studiospart12studios Member Posts: 620
    @RThurman Yes! i was able to get it working in relation to the game i'm working on which had a few other challenges, but they were nothing like the line effect (i.e. no fancy math)

    Thanks!
    Caleb
  • part12studiospart12studios Member Posts: 620
    hey at @RThurman and everyone else who helped with this! Here is a demo of the game i'm working on right now in action. this is still early, but its working out really well once i got that line effect working. http://www.youtube.com/watch?feature=player_embedded&v=8Pmalm2dhpE a lot more stuff to add like more player vehicles on screen and smarter enemies..
  • TesseractEngineTesseractEngine Member Posts: 180
    That's looking really cool, @part12studios! I've a proper hankering to make a Car Wars-esque game myself. Great work!
  • part12studiospart12studios Member Posts: 620
    edited October 2012
    thanks! yea this is a fusion of things like spy hunter, speed rumbler and the road warrior mixed together.. and a little battlestar galactica (when the story / convoy element comes in)
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    Great concept! The graphics and dust trails look spot on. (And the line thingy is looking good too.)
  • part12studiospart12studios Member Posts: 620
    Thanks! :) yea unfortunately the dust effect is too expensive on the ipad.. but seems to hold up ok on a decent mac / pc.. still have a lot of work to do though.. but i feel like overall GS is holding up even with a lot of constraints.
  • SocksSocks London, UK.Member Posts: 12,822
    hey at @RThurman and everyone else who helped with this! Here is a demo of the game i'm working on right now in action. this is still early, but its working out really well once i got that line effect working. http://www.youtube.com/watch?feature=player_embedded&v=8Pmalm2dhpE a lot more stuff to add like more player vehicles on screen and smarter enemies..

    That looks great ! :)

    Really good idea.
  • SocksSocks London, UK.Member Posts: 12,822
    @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.
    @RThurman

    Good stuff !
Sign In or Register to comment.