Date: Sat, 30 Jul 1994 04:17:42 +0000 From: Matthew Caldwell <sexkittn@BURN.DEMON.CO.UK> Subject: Re: need help on object creationMake the whole screen a single picture with all buttons in their unhilited state. When a mouseDown occurs, compare its position to the areas occupied by the buttons and act appropriately. To hilite (or depress or whatever) the button, use a puppet sprite sized and positioned to cover up the unhilited button in the background.
Since you can never have more than one button depressed at a time, you only need 2 channels for a potentially infinite number of buttons.
One way to process the mouseDowns: you (conceptually) divide up the stage into identical blocks, say 5 across and 5 down. Each block represents a button (numbered from 0 in the top left to 24 in the bottom right). The number of the button pressed (and therefore the action you should take) is given by:
buttonNum = acrossIndex + 5 * downIndexwhere
acrossIndex = integer(the mouseH / blockWidth) downIndex = integer(the mouseV / blockHeight)At the beginning of the movie you calculate
blockWidth = (the stageRight - the stageLeft) / 5 blockHeight = (the stageBottom - the stageTop) / 5and store as globals to avoid calling the stage size functions for every mouseClick.
The location for the hilited button sprite is calculated thus:
put (blockHeight * downIndex) into the locV of sprite HiliteSprite put (blockWidth * acrossIndex) into the locH of sprite HiliteSprite(provided all your hilite picts have their registration point in the top left corner) and the cast containing the hilite picture for each button can be indexed from a set base number, so you can switch the pictures easily:
set the castNum of sprite HiliteSprite = baseCastNum + buttonNum(really you should only call the cast change & sprite position bits at the mouseDown itself or when the mouse, stillDown, moves into a different block; otherwise you'll confuse the poor thing, and slow things down terribly too) (minimal complications: you should really track the mouse, changing the button hilite as appropriate, and allowing the user to change their mind; performing the button script should wait for a mouseUp within the button... In this case you'll also have to check for the mouse moving off the stage altogether, since this will screw up indexing the blocks from the mouse position...)
Of course, this requires that all your buttons be the same size (though the images representing them needn't be), but otherwise it's pretty cool, no?
[disclaimer: it's 4am and I haven't tested this, so check the arithmetic for yourself!]