6 Replies Latest reply on Apr 14, 2007 7:33 AM by midnight_cg

    Please Help

    midnight_cg Level 1
      I am designing a shoot'em up game for my coursework and need the gun to rotate based on where the mouse is positioned on the stage i.e. to give a 3D effect.
      I have previously been given the code :-
      global moveShotgun

      on moveShotgun
      set the castNum of Sprite 27 to 111 = ¬
      (the mouseH /266)

      I have entered this code into my movie script , however it is not accepted. Does anyone no a way around this problem?
      Many Thanks,
        • 1. Re: Please Help
          midnight_cg Level 1
          I have also added ssongs to my music channels. Does anyone know how to make them loop within the same frame when the song has played the whole way through?
          • 2. Re: Please Help
            Level 7
            Hi Steven,

            Yes, that code won't work. There is a behavior in the Library, Move,
            Rotate and Scale, that will do what you need. Take a look at that.

            Rob Dillon
            Adobe Community Expert

            • 3. Re: Please Help
              midnight_cg Level 1
              thnx - but it seems that you need to use specific keyboard instructions in order to rotate the gun - is there any way to create an illusion of the gun rotating according to the position of the mouse on the screen i.e. by splitting the stage into sections and replacing the sprite with another rotated cast member according to the section the cursor is in?
              • 4. Re: Please Help
                Level 7
                Here's a customized version of the Drag to Rotate behavior from the
                library that will allow a sprite to rotate to follow the cursor. You may
                be able to further customize this to meet your needs.

                -- DESCRIPTION --

                on getBehaviorDescription me
                return \
                "DRAG TO ROTATE" & RETURN & RETURN & \
                "Use the mouse to drag a sprite in a circle around its registration
                point." & RETURN & RETURN & \
                "PERMITTED MEMBER TYPES:" & RETURN & \
                "bitmap, Flash, picture, text, vector shape" & RETURN & RETURN & \
                "The scroll bar of scrolling Text members does not rotate. " & \
                "If attached to a sprite with a scrolling Text member, this behavior
                will convert the member to one with a fixed box size." & RETURN & RETURN
                & \
                "PARAMETERS:" & RETURN & \
                end getBehaviorDescription

                on getBehaviorTooltip me
                return \
                "Use with bitmaps, Flash, picture, text, and vector shape members."
                & RETURN & RETURN & \
                "Allows a sprite to be dragged in a circle around its registration
                end getBehaviorTooltip

                -- NOTES FOR DEVELOPERS --

                -- Basically, this behavior compares the position of the mouse when it
                -- clicked on the sprite and its current position. First the slope
                -- the clickLoc and the loc of mySprite is converted to an angle. Turn
                -- (called on each prepareFrame) then repeates the operation for the
                -- mouseLoc and the current loc of mySprite. By subtracting one angle
                from the
                -- other, it knows how much the sprite should be turned from its original
                -- position.

                -- HISTORY --

                -- 14 September 1998: written for the D7 Behaviors Palette by James
                -- 16 November 1998: ErrorAlert changed, made compatible with Draw

                -- PROPERTIES --

                property spriteNum
                property mySprite
                property myMember

                -- internal properties
                property myMouseDown
                property myPrevAngle
                property myClickAngle

                -- EVENT HANDLERS --

                on beginSprite me
                Initialize me
                StartDrag me
                end beginSprite

                on mouseDown me
                end mouseDown

                on prepareFrame me
                --if myMouseDown then
                -- if the mouseDown then
                Turn me
                -- else
                -- StopDrag me
                -- end if
                -- end if
                end prepareFrame

                -- CUSTOM HANDLERS --

                on Initialize me -- sent by beginSprite
                mySprite = sprite(me.spriteNum)
                myMember = mySprite.member
                memberType = myMember.type

                end Initialize

                --on Forwarded_mouseDown me
                -- -- The mouseclick was intercepted by a different behavior and
                -- if not myMouseDown then
                -- mouseDown me
                -- return myMouseDown
                -- end if
                --end mouseUp

                on StartDrag me -- sent by mouseDown
                -- if sprite (spriteNum).ink = 8 then
                -- -- Matte ink
                -- if the mouseMember <> sprite (spriteNum).member then
                -- exit
                -- end if
                -- end if

                -- myMouseDown = TRUE
                -- sendAllSprites #Active_Sprite, myMouseDown
                slope = the mouseLoc - mySprite.loc -- the clickLoc -
                myClickAngle = GetAngle (me, slope)
                myPrevAngle = mySprite.rotation
                end StartDrag

                --on StopDrag me
                -- myMouseDown = FALSE
                -- sendAllSprites #Active_Sprite, myMouseDown
                --end StopDrag

                on Turn me -- sent by prepareFrame
                slope = the mouseLoc - mySprite.loc
                newAngle = myPrevAngle + getAngle (me, slope) - myClickAngle
                mySprite.rotation = newAngle
                end Turn

                on GetAngle me, slope -- sent by Turn
                deltaH = slope[1]
                deltaV = slope[2]
                if deltaH then
                slope = float (deltaV) / deltaH
                angle = atan (slope)
                if deltaH < 0 then
                angle = angle + pi
                end if
                else if deltaV > 0 then
                angle = pi / 2
                else if deltaV < 0 then
                angle = (3 * pi) / 2
                angle = 0
                end if
                -- Convert to degrees for .rotation
                angle = (angle * 180) / pi

                return angle
                end GetAngle

                -- ERROR CHECKING --

                --on isOKToAttach (me, aSpriteType, aSpriteNum)
                -- case aSpriteType of
                -- #graphic:
                -- return getPos([#bitmap, #flash, #picture, #text, #vectorShape],
                sprite(aSpriteNum).member.type) <> 0
                -- #script:
                -- return FALSE
                -- end case
                --end isOKToAttach
                --on getPropertyDescriptionList me
                -- if not the currentSpriteNum then exit
                --end getPropertyDescriptionList

                Rob Dillon
                Adobe Community Expert

                • 5. Re: Please Help
                  midnight_cg Level 1
                  thanx Rob will try it out!
                  • 6. Re: Please Help
                    midnight_cg Level 1
                    I have found that the rotation problem can actually be solved by saving multiple rotated images in the cast and calling upon them on mouse position. Code similar to below fixed the problem:-
                    property pMySprite, pLeftBound1, pRightBound1

                    on beginsprite me
                    pMySprite = sprite(me.spritenum)
                    pLeftBound1 = 0
                    pRightBound1 = 200

                    on mouseEnter
                    if pRightBound1 < the mouseh then

                    sprite(27).memberNum = 111
                    end if