Professional Web Applications Themes

Moving Randomly Moving Sprite To New Location on mouseEnter - Macromedia Director Lingo

Hi All, This is way over my head. I am currently using Director 8. I have a randomly moving sprite(call it X) on stage (I accomplished this random movement using the Random Movement and Rotation Behavior in the Library Palette). I have a button on the stage. What I want to do is when the user's mouse enters the button I want Sprite X to move to a new location on the stage from where ever it is currently on the stage (remember it's randomly moving). I want the user to be able to see Sprite X move to it's ...

  1. #1

    Default Moving Randomly Moving Sprite To New Location on mouseEnter

    Hi All,

    This is way over my head. I am currently using Director 8.

    I have a randomly moving sprite(call it X) on stage (I accomplished this random movement using the Random Movement and Rotation Behavior in the Library Palette).

    I have a button on the stage. What I want to do is when the user's mouse enters the button I want Sprite X to move to a new location on the stage from where ever it is currently on the stage (remember it's randomly moving). I want the user to be able to see Sprite X move to it's new location from wherever it currently is on stage and then stay at this new location for as long as the user's mouse is within the button.

    on mouseOut me I want Sprite X return to approximately where it was and continue it's random movement.

    The net effect I hope to accomplish is this: Basically there will be serveral randomly moving sprites on the stage and when the mouse enters the buttom I want these sprites to move to a new location (each sprite is a letter) which will then spell a word. So each sprite will have a different locH value.

    I'm somewhat of a newbie with Lingo so please be as specific as your time allows.

    Many Thanks!
    Scott Elkins





    ScottE Guest

  2. #2

    Default Re: Moving Randomly Moving Sprite To New Location on mouseEnter

    Hi All,

    Can someone please help me with this?

    Many Thanks,
    ScottE


    ScottE Guest

  3. #3

    Default Re: Moving Randomly Moving Sprite To New Location on mouseEnter

    You would create a new behaviour, say called something like
    "MoveOnMouseOver" a bit like this
    I've done most of it, the rest is up to you.This is untested by the way, so
    I hope it works. The only thing
    left to do is to move it bit by bit on each enterFrame event. I have
    included comments. I partly left it
    cause i'm lazy, and I wasn't sure if you wanted linear tweening, or easing
    in, etc.

    Adam

    property pMoved
    property pMoving
    property pDestLocH
    property pDestLocV

    on getPropertyDescriptionList
    description = [:]
    addProp description,#pDestLocH, [#default:1, #format:#integer,
    #comment:"Destination locH"]
    return description
    end

    on beginSprite me
    pMoved = false
    pMoving = false
    -- change this to suit your movie
    pDestLocV = 100
    end

    on mouseEnter me
    if not pMoved then pMoving = true
    end

    on enterFrame me
    if not pMoved and pMoving then
    -- code to move the sprite closer to dest pos
    myLocH = sprite(me.spriteNum).locH
    myLocV = sprite(me.spriteNum).locV
    myDiff = abs((myLocH+myLocV) - (pDestLocH+pDestLocV))

    if myDiff < 5 then -- snap if we're close
    -- set it to our destination
    sprite(me.spriteNum).locH = pDestLocH
    sprite(me.spriteNum).locV = pDestLocV
    pMoved = true
    pMoving = false
    else
    -- move it closer here bit by bit
    -- no more than 5 pixels at a time if we're close to our dest
    end if
    end if
    end

    "ScottE" <elkinsmsaol.com> wrote in message
    news:bo9q5k$si8$1forums.macromedia.com...
    > Hi All,
    >
    > Can someone please help me with this?
    >
    > Many Thanks,
    > ScottE
    >
    >

    Adam Royle Guest

  4. #4

    Default Re: Moving Randomly Moving Sprite To New Location on mouseEnter

    Hi Adam,

    I appreciate your help on this. I'm not an expert on Lingo and could use some additional help if you are willing.

    Can you help me with the code you left out for the behavior? I'd like to ease in the sprites to the new location and then have them ease back to random movement.

    Many Thanks,
    Scott




    ScottE Guest

  5. #5

    Default Re: Moving Randomly Moving Sprite To New Location on mouseEnter

    I'm not an expert on Lingo either! I only started getting into it about 3
    weeks ago. However, I do know flash pretty well. The thing I wrote for you
    will only move them to the new location, not back again, you'd need to add
    more events, and possibly set some more properties. Also, I just realised
    you'll probably have to use setScriptList to disable the random movement
    object (unless you want to hack up the behaviour).

    Sorry I can't really help you any more than I have, but hopefully I have put
    you in the right direction.

    Adam

    "ScottE" <elkinsmsaol.com> wrote in message
    news:bobid9$19u$1forums.macromedia.com...
    > Hi Adam,
    >
    > I appreciate your help on this. I'm not an expert on Lingo and could use
    some additional help if you are willing.
    >
    > Can you help me with the code you left out for the behavior? I'd like to
    ease in the sprites to the new location and then have them ease back to
    random movement.
    >
    > Many Thanks,
    > Scott
    >
    >
    >

    Adam Royle Guest

  6. #6

    Default Re: Moving Randomly Moving Sprite To New Location on mouseEnter

    Adam thanks but I'm not really getting any where on this.

    Do you or does anyone else know of some web sites that might have examples of behaviors so I can try to put this together?

    Many Thanks,
    Scott



    ScottE Guest

  7. #7

    Default Re: Moving Randomly Moving Sprite To New Location on mouseEnter

    Hi Judy,

    YES! Almost exactly what I need!!!!

    The only thing I need to change is to define a rectangle that limits the random movement of the sprites. The example you gave me (and THANK YOU so much!) moves the spirtes all over the stage.

    Any ideas on how to define the rectangle?

    MANY THANKS!

    Scott


    ScottE Guest

  8. #8

    Default Re: Moving Randomly Moving Sprite To New Location on mouseEnter

    Just look at the exitFrame handler. That's where the limits are set:
    If (pCurrentLoc.locH) >= (the stage).rect.width and pRandomVector.locH>=0
    then
    pCurrentLoc.locH=0
    ....
    That's just simply saying that if the locH goes off the stage to the right,
    then force it back to the left edge of the stage.

    The next line in the handler does the same, but checks to see if your locH
    is off to the left (< 0).

    Set your own boundaries in that handler.

    Judy

    "ScottE" <elkinsmsaol.com> wrote in message
    news:bogj7h$a8f$1forums.macromedia.com...
    > Hi Judy,
    >
    > YES! Almost exactly what I need!!!!
    >
    > The only thing I need to change is to define a rectangle that limits the
    random movement of the sprites. The example you gave me (and THANK YOU so
    much!) moves the spirtes all over the stage.
    >
    > Any ideas on how to define the rectangle?
    >
    > MANY THANKS!
    >
    > Scott
    >
    >

    JPrice Guest

  9. #9

    Default Re: Moving Randomly Moving Sprite To New Location on mouseEnter

    Hi Judy,

    Well this is embarrassing. I've tried to set the rectangle limits so the sprites move within a defined area rather than all over the stage. No luck.

    The rectangle is 812W and 334H and I've tried those values and variations thereof and just simply can't get it to work.

    Can you or anyone else help with this?

    Many Thanks!
    Scott


    ScottE Guest

  10. #10

    Default Re: Moving Randomly Moving Sprite To New Location on mouseEnter

    Scott,

    You have to consider the location of the rectangle as well as the size.

    How big is your stage, and where is the rectangle located within the stage?

    Instead of using (the stage).rect.width, you might consider using your
    rectangle's sprite's rect coordinates: (x is your rectangle's spriteNum)

    If (pCurrentLoc.locH) >= sprite(x).right and pRandomVector.locH>=0 then
    pCurrentLoc.locH=sprite(x).left
    ....

    Judy


    "ScottE" <elkinsmsaol.com> wrote in message
    news:boideb$cki$1forums.macromedia.com...
    > Hi Judy,
    >
    > Well this is embarrassing. I've tried to set the rectangle limits so the
    sprites move within a defined area rather than all over the stage. No luck.
    >
    > The rectangle is 812W and 334H and I've tried those values and variations
    thereof and just simply can't get it to work.
    >
    > Can you or anyone else help with this?
    >
    > Many Thanks!
    > Scott
    >
    >

    JPrice Guest

Similar Threads

  1. Moving the ASPNET directory location
    By ghitjo in forum ASP.NET Security
    Replies: 0
    Last Post: August 16th, 06:57 PM
  2. mouseEnter / mouseLeave sprite error
    By geneonlbk webforumsuser@macromedia.com in forum Macromedia Director Lingo
    Replies: 5
    Last Post: December 4th, 03:55 PM
  3. moving sprite behavior in a CALCULATED parabola
    By takabean webforumsuser@macromedia.com in forum Macromedia Director Lingo
    Replies: 4
    Last Post: September 25th, 12:57 PM
  4. Replies: 0
    Last Post: July 27th, 11:13 PM
  5. Moving to a location on a page
    By michael - london webforumsuser@macromedia.com in forum Macromedia Dreamweaver
    Replies: 2
    Last Post: July 23rd, 12:58 PM

Bookmarks

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139