2 Replies Latest reply on Apr 15, 2007 5:08 AM by midnight_cg

    Help Needed

      I am designing a shoot'em up game for my coursework and need a rat to turn in2 a blood image then for the blood to fade out after so many seconds and the rat to return to its original position.
      So far I have the rat moving accross the stage and it changes to the blood sprite on mouse up. I have used a fade in/out behaviour so as the blood fades away after a few second. Whenever I use the reset sprite loc:
      n resetMe
      set the moveableSprite of pMySprite = true
      set the loc of pMySprite = pStartingLoc

      it returns the blood to the position of the rat and fades out - is there no way of allowing the blood to fade and then return the rat to its starting position?

      Many Thanks,
        • 1. Re: Help Needed
          Lukewig Level 1

          One approach is to code a series of 'behaviours' (actually, they could be parent scripts) that you add and remove from a sprite. For example, this could be your main 'rat behaviour':

          -- 'rat behaviour attached to a sprite
          property SpriteObj
          property StartLoc

          on beginSprite (me)
          SpriteObj = sprite(me.spriteNum)
          StartLoc = SpriteObj.loc

          on mouseUp me

          on enterframe (me)
          SpriteObj.locH = SpriteObj.locH + 1

          on Kill (me)
          -- temporarilty remove this object from the sprite

          -- create a new instance of the blood behaviour
          -- and add it to the the sprite
          blood = script("bloodbehviour").new(me)


          on Reset (me)
          SpriteObj.loc = StartLoc
          SpriteObj.member= member("rat")
          SpriteObj.blend = 100

          So when you you 'kill' the rat, you add a new behviour to the sprite - which sort of 'activates it' (since onces its added the sprite scriptInstanceList, it will start receiving enterframe events). The "Blood" behaviour could look like this:

          -- script "bloodbehviour" (behaivour or parent script that is not attached to a sprite)

          property RatObject
          property SpriteObj

          on new (me, ratinstance)
          -- keep a pointer to the RatObject so we can put it back on teh sprite
          -- when this behaviour has finished.
          RatObject = ratinstance
          SpriteObj = ratinstance.SpriteObj
          SpriteObj.member = member("blood")
          return me

          on enterframe (me)
          if SpriteObj.blend > 0 then
          -- fade out
          SpriteObj.blend = SpriteObj.blend-5
          -- finished doing our job, put the rat object back into
          -- the scriptInstanceList of the sprite and reset it
          -- remove this script instance from the sprite
          end if

          -- Luke
          • 2. Re: Help Needed
            midnight_cg Level 1
            Many Thanks Luke - it has worked a treat!!