6 Replies Latest reply on Mar 31, 2010 2:19 AM by Sean_Wilson

    Sprite not seen by Director

    NOCK2k8

      Hey guys,

       

      I have a massive problem that I've been struggling over for days now.  I have a green rectangle that a sprite can travel over.  I have code set up to tell me what colour the next Pixel along is, but for some reason the sprite is seeing the edge of the rectangle sooner than it should be seen.

       

      I'm not sure whether I have explained that very well.

       

      The file is here, you will see what I mean.

       

      My problem is on the "Level 1" Marker.

       

      Please can somebody help, I'm desperate for an answer on this as my deadline is near.

        • 1. Re: Sprite not seen by Director
          Sean_Wilson Adobe Community Professional

          Are you still having trouble? This thread suggests not, but you've been posting all over the place making it difficult to keep track...

          • 2. Re: Sprite not seen by Director
            NOCK2k8 Level 1

            Hey, yeah majour trouble, I really need some help on this. My other problem was slightly different and I managed to work it out in the end. However this one has got me completely stumped. Please can you help me if possible. Any suggestions will be greatly appreciated. Thanks

            • 3. Re: Sprite not seen by Director
              Sean_Wilson Adobe Community Professional

              Try the following alterations to the script attached to your moveable character:

              -- properties used in this script:
              -- pSprite - the sprite reference
              -- pSpeed - the speed the sprite should move
              -- myLocH - the current horizontal position of the sprite
              -- myLocV - the current vertical position of the sprite
              property spriteNum
              property my
              property myReferenceImage
              property myReferenceImageOffset
              property myWidthOffset
              property myHeightOffset
              property pSprite, pSpeed, myLocH, myLocV
              
              on beginSprite me
                -- initialise sprite properties
                my = sprite(spriteNum)
                myReferenceImage = member("Level_1_Maze").image
                -- reference bitmap is offset from (0, 0) by (9, 12)
                myReferenceImageOffset = point(9, 12)
                -- account for l, t, r, b colliding with "walls"
                -- regPoint is centered, so:
                myWidthOffset  = my.width/2
                myHeightOffset = my.height/2
                -- controls the speed that the sprite moves at
                pSpeed = 10
              end
              
              on keyPress me, aDirection
                -- actions THIS sprite should take on key press
                
                -- store current location
                myLocH = my.locH
                myLocV = my.locV
                
                -- find which direction to move
                case aDirection of
                  #left:  me.goLeft()
                  #right: me.goRight()
                  #up:    me.goUp()
                  #down:  me.goDown()
                end case
                
              end
              
              -- individual custom event handlers for movement
              on goLeft me
                -- swap the sprite for one based on the 
                -- left film loop cast member
                my.member = member("left")
                -- move the sprite to the left if no hedge to the left of the cast member
                newlocH = myLocH - pSpeed
                iColor = myReferenceImage.getPixel(point(newlocH - myWidthOffset, myLocV) - myReferenceImageOffset, #integer)
                if iColor = -16720640 then
                  --grass colour is legal so allow move
                  my.locH = newLocH
                else
                  put iColor
                  beep
                end if
              end
              
              on goRight me
                my.member = member("right")
                newlocH = myLocH + pSpeed
                iColor = myReferenceImage.getPixel(point(newlocH + myWidthOffset, myLocV) - myReferenceImageOffset, #integer)
                if iColor = -16720640 then
                  --grass colour is legal so allow move
                  my.locH = newLocH
                else
                  put iColor
                  beep
                end if
              end
              
              on goUp me
                my.member = member("up")
                newLocV = myLocV - pSpeed
                --find out if newLoc is a legal space
                iColor = myReferenceImage.getPixel(point(myLocH, newLocV- myHeightOffset) - myReferenceImageOffset, #integer)
                if iColor = -16720640 then
                  --grass colour is legal so allow move
                  my.locV = newLocV
                else
                  put iColor
                  beep
                end if
              end
              
              on goDown me
                my.member = member("down")
                newLocV = myLocV + pSpeed
                --find out if newLoc is a legal space
                iColor = myReferenceImage.getPixel(point(myLocH, newLocV + myHeightOffset) - myReferenceImageOffset, #integer)
                if iColor = -16720640 then
                  -- grass colour is legal so allow move
                  my.locV = newLocV
                else
                  put iColor
                  beep
                end if
              end
              

               

               

               

               

              This could do with a degree more rationalisation/optimisation/consolidation yet. For example:

               

              -- properties used in this script:
              -- pSprite - the sprite reference
              -- pSpeed - the speed the sprite should move
              -- myLocH - the current horizontal position of the sprite
              -- myLocV - the current vertical position of the sprite
              property spriteNum
              property my
              property myReferenceImage
              property myReferenceImageOffset
              property myWidthOffset
              property myHeightOffset
              property pSprite, pSpeed, myLocH, myLocV
              
              on beginSprite me
                -- initialise sprite properties
                my = sprite(spriteNum)
                myReferenceImage = member("Level_1_Maze").image
                -- reference bitmap is offset from (0, 0) by (9, 12)
                myReferenceImageOffset = point(9, 12)
                -- account for l, t, r, b colliding with "walls"
                -- regPoint is centered, so:
                myWidthOffset  = my.width/2
                myHeightOffset = my.height/2
                -- controls the speed that the sprite moves at
                pSpeed = 10
              end
              
              on keyPress me, aDirection
                -- find which direction to move
                case aDirection of
                  #left:
                    tMember = member("left")
                    tPoint  = my.loc - point(pSpeed + myWidthOffset, 0)
                  #right:
                    tMember = member("right")
                    tPoint  = my.loc + point(pSpeed + myWidthOffset, 0)
                  #up:
                    tMember = member("up")
                    tPoint  = my.loc - point(0, pSpeed + myHeightOffset)
                  #down:
                    tMember = member("down")
                    tPoint  = my.loc + point(0, pSpeed + myHeightOffset)
                end case
                
                my.member = tMember
                iColor = myReferenceImage.getPixel(tPoint - myReferenceImageOffset, #integer)
                if iColor = -16720640 then
                  --grass colour is legal so allow move
                  my.loc = tPoint
                else
                  put iColor
                  beep
                end if
              end
              
              • 4. Re: Sprite not seen by Director
                NOCK2k8 Level 1

                Thank you so much you are a star! That works brilliant, and consolidated looks so much tidier too! I owe you for this big time!

                 

                Just one more thing, how could I change my man so that his arm cannot go in the hedges?  Like make his boundary bigger (I know that's probably not correct terminology).

                • 5. Re: Sprite not seen by Director
                  Sean_Wilson Adobe Community Professional

                  Try setting pSpeed to 1 and upping your frame rate.

                  1 person found this helpful
                  • 6. Re: Sprite not seen by Director
                    NOCK2k8 Level 1

                    Tried them and it hasn't changed anything unfortunately, any other ideas?