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

    Help Needed

    midnight_cg
      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
      end

      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,
      Midnight
        • 1. Re: Help Needed
          Lukewig Level 1
          Hi.

          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
          end

          on mouseUp me
          me.Kill()
          end

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

          on Kill (me)
          -- temporarilty remove this object from the sprite
          SpriteObj.scriptInstanceList.deleteOne(me)

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

          end

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

          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
          end

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

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