|
Lingo Tutorial: Sprite Pool READING: Chapter 11, pages 360-362 in D8D for the repeat function Manual pages of the commands described here. File "naomis_colorforms.dir"In this application you have a "pool" of items at the bottom of the screen (eyes, ears, noses, lips, moustaches). They are on channels 1 through 4. Having a pool means that you want to be able to generate dynamically several (up to 10 copies in this application) of these pool items in any combination (8 eyes and 2 noses, or 1 eye, 3 ears and 7 moustaches, for example.) There is also
an easy - though clumsy - way to implement the pool effect by having
a bunch of sprites perfectly aligned on each other. How do you implement this pool behavior? One way is to
have a pool 10 generic items that you can take and place on the stage on
demand.
That is really cool, and not difficult to implement: on startMovie global nextIcon, maxIcons nextIcon = 10 -- 10 phantom shapes are in channels 10 to 19 maxIcons = 19 end sprite(nextIcon).member = the mouseCast Recall that the mouseCast returns the cast number of the sprite that the mouse clicked on. Once generated, you want them to move them around and place them somewhere on the screen. You can then move them around by having them follow the location of the mouse while the mouse is still down:
repeat while the stillDown
sprite(nextIcon).loc = the mouseloc
updateStage
end repeat
Here is the whole script that produces a new item:
on produceChild -- give a new image from the pool of images
global nextIcon, maxIcons
-- the mouseCast gives you the cast number that is currently under the mouse
sprite(nextIcon).member = the mouseCast
if nextIcon > maxIcons then -- we only have no more icons
alert "Sorry, I ran out of ink!"
end if
repeat while the stillDown
sprite(nextIcon).loc = the mouseloc
updateStage
end repeat
nextIcon = nextIcon + 1
end
You may also want
them to be repositioned later on. This is accomplished by the moveAround
handler. The repeat loop above is also the core of the moveAround handler.
on moveAround -- move image around screen
x = the clickOn
repeat while the stillDown
sprite(x).loc = the mouseloc
updateStage
end repeat
end
|
|
|
Maintained By: Takis Metaxas
|
|