Color Cursors born from Parent Scripts

Date:    Thu, 14 Dec 1995 02:07:08 +0000
From:    Matthew Caldwell <sexkittn@BURN.DEMON.CO.UK>
Subject: colour cursors/fun with objects

>Does anyone have a way of changing the fore/back color of a 1 bit cursor,
>or do they have to be B+W?
They have to be b&w. Standard xplatform workaround is to hide the cursor and puppet a picture sprite to track the mouse. This is a perfect candidate for p/c scripting using the actorList, because it's asynchronous and generalized, so here's a utility class to do it:
  ------------------------------------------------------------------
  -- parent script for an object to manage cursors easily         --
  --   advantages -- takes care of itself and doesn't require     --
  --      a repeat loop that starves other parts of the movie     --
  --   disadvantages -- requires a permanently puppeted channel   --
  --      (48, since cursors must be at the front) to work with,  --
  --      adds a global, and will starve if some other part of    --
  --      the movie sits in a repeat loop or executes a "pause"   --
  ------------------------------------------------------------------

  on birth me
    -- note that this birth creates its own global rather
    -- than returning itself -- this is often not good practice
    -- but it keeps everything self-contained here
    global gCursor
    set gCursor = me
    puppetSprite 48, true
  end birth

  ------------------

  on mSet me, whichCast
    -- hide the real cursor and place the substitute cast in the
    -- topmost channel
    cursor 200
    set the castNum of sprite 48 = whichCast

    -- put ourselves in the actorlist if we aren't there
    -- already
    if not getOne(the actorList, me) then add(the actorList, me)

    stepFrame me
  end mSet

  ------------------

  on mReset me
    -- reshow the default cursor and hide the topmost sprite
    cursor 0
    set the castNum of sprite 48 = 0

    -- remove ourselves from the actorlist
    deleteOne(the actorList, me)
  end mReset

  ------------------

  on stepFrame me
    -- follow the mouse
    set the loc of sprite 48 = point(the mouseH, the mouseV)
  end stepFrame

  ------------------
(this was extemporized at the keyboard, so there may be a few errors, but I've used this class before & it works)

Usage:

  1. put a bitmap castmember offstage in channel 48 -- this is not absolutely necessary, but it makes life easier; you'll probably want to set it to background transparent ink

  2. put the following line in your initialization handler, substituting the actual script name or number for "cursor object script":
      birth script("cursor object script")

  3. ideally, you'll give your movie the highest possible frame rate (this is usually no problem with lingo-based movies, but not so suitable for score-heavy stuff)

  4. to install any castmember of your choice as an ersatz cursor, say:
      global gCursor
      mSet gCursor, myCast
    (you can do this multiple times in a row without having to reset it in between)

  5. to remove it, say:
      global gCursor
      mReset gCursor