> Hi Luke,
>
> I understand your point. But how about using 'actorList' and 'on
> stepFrame' handler. It doesn't need 'if test' either. Are there any
> reason you prefer 'ancestor' approach?
Hi Fumio,
The actorList and stepFrame would work as well. My preference of using the
ancestor property with sprites (and actorList with more abstract things that
need a cyclic event, such as stepframe) is because
1. - objects attached to sprites via the ancestor link receive all the
sprite events (mouseDown, exitframe, etc) -- although the code I posted
before only took advantage of 'on prepareframe', most of my sprite
behaviours also respond to mouseClicks and sendSprite messages
2. - easier garbage management - ie. when the sprite ends, all the
behaviours you've attached via the ancestor link get removed automatically
(provided they're not referenced anywhere else). With the actorList, you
will need to manually remove objects from it (Incidentally, in the old days,
having actors on stepframe call handlers which removed that actor from the
actorList would cause nasty memory allocation errors - a bit like the
problem of having MIAWs tell the stage to forget that MIAW. Consequently, I
tend to use a custom garbage collector for actors)
3. - Using ancestors means that you can take advantage of masking and
re-direction of methods and messages
As a test, try this script below. Notice that the parent script even learns
the 'spriteNum' property from the sprite its attached to without ever having
to explicitly pass this as a property (unfortunately, the spriteNum property
isn't learnt by the ancestor until after the ancestor has received the first
'sprite' event, such as an exitframe our mouseDown - so in practice, you
need to pass the spriteNum or sprite instance when you are creating a new
instance of the ancestor if you want to access that property in its 'on new'
handler)
-------- sprite behaviour --------
property ancestor
on mTest me
ancestor = script("ParentScript").new()
put ancestor
end
-------- ParentScript --------
on new me
return me
end
on exitframe me
put ("sprite" && me.spriteNum && "got exitframe")
end
on mouseDown me
put ("sprite" && me.spriteNum && "got mouseDown")
end
on keyDown me
put ("sprite" && me.spriteNum && "got keyDown")
end
on mCustomMessage me
put ("sprite" && me.spriteNum && "received sendSprite message")
end
-- Message Window
sendAllSprites(#mTest)
-- "sprite 2 got exitframe"
-- "sprite 2 got mouseDown"
sendAllSprites(#mCustomMessage)
-- "sprite 2 received sendSprite message"
-- "sprite 2 got exitframe"
etc
Luke
on 13/9/00 9:16 PM, Fumio Nonaka at [EMAIL PROTECTED] wrote:
> _____
> Luke Wigley wrote:
>> PS - This approach might appear a little more complicated than necessary
>> since it uses two scripts - ie. you could make a single behaviour that did
>> "if IamBeingDragged then doDrag" test every exitframe. However, I think the
>> approach I've used is a lot more neater (and the project I am working on has
>> a lot of sprites, and with all of them doing 'if tests' on exit frame,
>> performance slows down noticeably)
>
> Regards,
>
> Fumio Nonaka
> Attain Corporation
> [EMAIL PROTECTED]
>
> [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!]
--
Luke Wigley
Multimedia Director/Producer
Mecca Medialight Pty Ltd
Mecca Medialight: Medialight Sound Studio:
111 Moor Street 1 Bakehouse Lane
Fitzroy, Vic. 3065 North Fitzroy, Vic. 3068
Tel +613 9416 2033 Tel +613 9416 2033
Fax +613 9416 2055 Fax +613 9416 2055
www.medialight.com.au
__________________________________________________________________________
[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!]