A Flash Developer Resource Site

Results 1 to 16 of 16

Thread: Line between mouse and MC

  1. #1
    Who needs pants? hooligan2001's Avatar
    Join Date
    Apr 2001
    Location
    Somewhere
    Posts
    1,976

    Line between mouse and MC

    Ive tried this but can seem to get it to work properly and im fed up.

    What i want is i have a mc which at this point is stationary, and the mouse pointer which moves around the screen. What i want is for their to be a line drawn between the 2 objects. I want it to rotate according to where the mouse is on the screen and also strech and shrink according to the distance between the 2 objects.

    If anyone could maybe provide a fla with some comments in it to help me out i would appretiate it alot.

    ThankS in AdvancE


    [-hooligan-]

  2. #2
    Who needs pants? hooligan2001's Avatar
    Join Date
    Apr 2001
    Location
    Somewhere
    Posts
    1,976
    Dont tell me no one knows how to do it i see it all the time.

    If you dont understand what i want just ask me to explain it agian

    ThankS in AdvancE

    [-hooligan-]

  3. #3
    avatar free
    Join Date
    Jul 2002
    Location
    UK
    Posts
    835
    Sorry, i did this when i saw your post, but never got chance to post it as i'm in the middle of exams

    It's not the most efficient/best way of doing it, but it should give you an idea of where to go... no comment tags sorry, but it's pretty self explanatory.

    By the way, i did this in MX using the dynamic drawing stuff. Hope you dont want it in flash 5. Possible, sure, but a bit more complicated.
    Attached Files Attached Files
    jonmack
    flash racer blog - advanced arcade racer development blog

  4. #4
    Who needs pants? hooligan2001's Avatar
    Join Date
    Apr 2001
    Location
    Somewhere
    Posts
    1,976
    Thanks for that man i really aprettiate it. But i cant download the file. The MX file will just fine thanks agian for doing that

  5. #5
    Who needs pants? hooligan2001's Avatar
    Join Date
    Apr 2001
    Location
    Somewhere
    Posts
    1,976
    I tried it agian man and it worked so thanks heaps its exactly what i wanted. Havent looked at the code yet but be prepared to answer some questions when i have a look

  6. #6
    Who needs pants? hooligan2001's Avatar
    Join Date
    Apr 2001
    Location
    Somewhere
    Posts
    1,976
    LoL didnt realise how easy that is .

    One more quick question. Dunno if you can help me on this. But ill ask ne way. What i want is that onmouse down move a Ball movie clip from the original movie clip in the direction of the line

  7. #7
    avatar free
    Join Date
    Jul 2002
    Location
    UK
    Posts
    835
    I've done a fairly siply example of what (I think) you're looking for. Copy the below code into the original file, not changed anything to it, only added.

    Code:
    _root.onMouseDown = function()
    {
       var speed = 5;
    	
       // attach & position ball to mc...
       var a = _root.attachMovie("ball", "ball", 2);
       a._x = _root.mc._x;
       a._y = _root.mc._y;
    	
       // which direction it goes...
       a.x = (_root._xmouse - _root.mc._x)/speed;
       a.y = (_root._ymouse - _root.mc._y)/speed;
    	
       a.onEnterFrame = function()
          {
    	// move it...
    	this._x += this.x;
    	this._y += this.y;
    		
    	// remove if off screen...
    	if (this._x > Stage.width || this._x < 0 || this._y < 0 || this._y > Stage.height) {
    	   this.removeMovieClip();
    	}
          };
    };
    (Hope this comes out nce with the new colour code tags )

    All you have to do is make an mc with a linkage name of "ball".

    There can be only one ball on the screenat a time with this, clicking again when there's already a ball on the screen will replace it with a new one. Also, the way i've done it maens that the ball will go faster the longer the line, as to indicate the strength, if you like, of the force. IT also doesn't stop to where the mouse was, just keeps going to edge of screen.

    P.S. Commented just fou you
    jonmack
    flash racer blog - advanced arcade racer development blog

  8. #8
    Who needs pants? hooligan2001's Avatar
    Join Date
    Apr 2001
    Location
    Somewhere
    Posts
    1,976
    That is exactly what i want. I really appretiate all this.

    Question:- Is it better to make all my actionscript into functions ?

    I normally only use functions when i need to do multiple things at once. So i dont need to re-write the same lot of code.

  9. #9
    Who needs pants? hooligan2001's Avatar
    Join Date
    Apr 2001
    Location
    Somewhere
    Posts
    1,976
    Is their a way to limit the distance the line can stretch ?

    Sorry to be a hastle

  10. #10
    avatar free
    Join Date
    Jul 2002
    Location
    UK
    Posts
    835
    No hassle! I like a good problem. -> -> ->

    functions

    well, of course functions are best for multiple use, that's great that you do that. But another thing they're good for is when you want a block of code to run. You don't want the "end screen" codes to run when the movie first plays, so you can put them in a function, and call them when they are needed. Of course, if you've got them all on different frames, then you probably won't need to do that. But i always try to code on a single frame if i can. Mostly for games, so no-one can cheat by clicking play, and going to next frame he he.

    restricted line length

    well, this was a bit tougher than i first though. So much so, i had to sleep on it. Turned out quite good though i think. There's a fair bit of code changes, so i'll just attach the file again. It's fairly easy to understand if you know a bit of basic of trig.

    if (line too long) {
    shorten it to the max length;
    } else {
    don't bother - it's fine!;
    }

    stuff like that. Trig comes in when you want to shorten it to max length. Change length with variable linelength. That's basically it.

    What is it you're using it for anyway? Would like to know. Good luck!
    Attached Files Attached Files
    jonmack
    flash racer blog - advanced arcade racer development blog

  11. #11
    Who needs pants? hooligan2001's Avatar
    Join Date
    Apr 2001
    Location
    Somewhere
    Posts
    1,976
    Thanks for that its exactly what i wanted, you have been a great help.

    One more question and i think its my last

    Would i use the same techniques to restrict the line to a 90 degree movement. So the line can only move from 270 - 360 degree angle


    ThankS in AdvancE

    [-hooligan-]
    Last edited by hooligan2001; 01-17-2003 at 09:01 PM.

  12. #12
    Mental Deficit Nionicle's Avatar
    Join Date
    Mar 2002
    Location
    Utah, Hyrum
    Posts
    1,348
    Lol so there are only 4 spots the line can be in?


    Cause you can just do that with a button instead of a script =)
    just oppinion
    I can only postulate the probability of performing at a paramount level of perfection praised by the pulchritudinous paragon whose only practice is to preserve such a paradigm.

  13. #13
    avatar free
    Join Date
    Jul 2002
    Location
    UK
    Posts
    835
    i think hooligan maybe meant restrict it in the 270 -> 360 quadrant. (9 o'clock to 12 o'clcok only) ???

    You would only need to use the "endx = mcx-linelength*Math.cos(angle);" lines (the one's with negative signs) if you wanted to do that, because the "+" ones are for the right hand side of the circle. But yeah, same theory, just another if statement should do it.

    Have a go, see what you can do. I'll not post code, you should be able to do this Practicing is the best way to learn. Will still help on anything more if you can't, of course.
    jonmack
    flash racer blog - advanced arcade racer development blog

  14. #14
    Who needs pants? hooligan2001's Avatar
    Join Date
    Apr 2001
    Location
    Somewhere
    Posts
    1,976
    LOL stupid me. Didnt look at the code properly woops

    Thanks Jonmack you have been a great help.

    Also thanks for your input Nionicle

  15. #15
    Mental Deficit Nionicle's Avatar
    Join Date
    Mar 2002
    Location
    Utah, Hyrum
    Posts
    1,348
    thanx


    I wish i could have helped more but i dont have mx =(
    I can only postulate the probability of performing at a paramount level of perfection praised by the pulchritudinous paragon whose only practice is to preserve such a paradigm.

  16. #16
    Who needs pants? hooligan2001's Avatar
    Join Date
    Apr 2001
    Location
    Somewhere
    Posts
    1,976
    Nah thats no problem, least you tried to help Keep it up.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center