At 7:30 PM +0100 1/16/01, Marcus Adolfsson wrote:
>Hej again.
>
>I guess I failed describing what I really wanted to know. I do know how put
>a specific sprite at random position every mouseDown/mouseUp event. What I
>would like to know is how to put a _new_ sprite, a _new_ instance of say
>"abc.bmp", at a random position every time the mouse is pressed(or key is
>pressed, or whatever). So that i finally end up with 100(or 200 or so)
>instances of the same bitmap. Your sample code simply moves sprite no 1,
>doesn't it?
>
>I'm sure this is easily done, but I'm very new to this Director/Lingo thing.
>
A simple way is to put "abc.bmp" into the channels where you
potentially want them to appear (e.g., channels 100 to 199 - this
would give 100 images, expand as you wish), but move them all
offstage. That is, set their locV to -1000. Then you need a general
handler and a global list to keep track of the state of your world (I
would use an object, but that complicates the issue).
Here's an approach (untested):
global gNextChannelToAssign
global gLastChannelToAssign
on preparemovie
end
on GetNextChannel me
thisChannelNum = gNextChannelToAssign
if thisChannelNum > gLastChannelToAssign then
alert("Sorry bub, out of channels")
return
end if
gNextChannelToAssign = gNextChannelToAssign + 1
end
-- This places abc.bmp in a random location
on PlacePicture
ch = GetNextChannel()
sprite(ch).locH = random(640) -- whatever your screen width
sprite(ch).locV = random(480) -- whatever your screen height
end
Then on each copy of your abc.bmp in channels 100 to 199 (or
whatever) add a behavior like this:
global gNextChannelToAssign
global gLastChannelToAssign
property spriteNum
on beginSprite me
if voidp(gNextChannelToAssign) then
gNextChannelToAssign = spriteNum -- only executes on first sprite
end
gLastChannelToAssign = spriteNum -- executes on every sprite
end
Good luck,
Irv
--
Lingo / Director / Shockwave development for all occasions.
(Over two millions lines of Lingo code served!)
[To remove yourself from this list, or to change to digest mode, go to
http://www.penworks.com/LUJ/lingo-l.cgi To post messages to the list,
email [EMAIL PROTECTED] (Problems, email [EMAIL PROTECTED])
Lingo-L is for learning and helping with programming Lingo. Thanks!]