Shape, Sprite, MovieClip and other display objects: when to use?

此生再无相见时 提交于 2020-01-04 02:35:08

问题


there's a large ammount of display objects in flash.display package. It's not clear for me in what situation I should use Shape, Sprite or MovieClip. What is the pro and contras in using each of them?

Thank you in advance!!


回答1:


  • Shape is the simplest display object you can add on stage. It is the most limited one: you can't add childen to it (does not extend DisplayObjectContainer), does not have interactivity (does not extend InteractiveObject), does not have a timeline
  • Sprite extends DisplayObjectContainer and InteractiveObject, therefore it's interactive and you can add children to it. It's the most useful display class in my opinion, as long as you don't need a timeline.
  • MovieClip extends Sprite, so all of the above are true and you also get methods/properties associated with timeline control, but note that it's a dynamic class, so you can do some hacky thing on the fly, but you'll lose speed.

In short, stick to Sprite in most cases, unless you need to integrate with MovieClips from Flash Authoring. Shape is handy to quickly draw into and it's 'lighter' than Sprite, but not very flexible since you can't nest other elements to it.




回答2:


You should always use the lightest component depending on what you need:

  • Shape is the one with the least possibilities. Use it when you only want a DisplayObject with graphics, and no mouse interaction.
  • Sprite is the parent class of quite everything you need. Since it is a DisplayObjectContainer, you can use it as a basic container for other components. You can also catch mouse events on this one.
  • MovieClip is a Sprite with the ability to use frames. Only use it for frame-by-frame animation (Flash style).


来源:https://stackoverflow.com/questions/10192923/shape-sprite-movieclip-and-other-display-objects-when-to-use

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!