0

我对 AS3 很陌生。我想创建一个我在自己的构造函数类中定义的形状。

它应该在创建类时创建一个形状。(构造函数)

我在以下代码中评论了我的需求:

球形类

public class ballShape {

        public function ballShape() {
            // define shape properties.
            // create shape and put that in x = 0, y = 0 
        }

    }

任何帮助都会很棒。

4

1 回答 1

2

您可以轻松地做到这一点,同时将您的类扩展到 Shape 或 Sprite

这是你的代码

public class ballShape extends Sprite {

    public function ballShape() {
        // define shape properties. The graphics object is already added to your Sprite, no need to manually addChild() this object.
        graphics.beginFill(color, alpha); // you can begin a fill with this method, there are also methods to start a bitmap fill, gradient fill. 
        graphics.drawRect( x, y, width, height ); // draw a shape
        graphics.endFill();
    }

}

虽然 Shape 可以具有绘制形状和线条的相同功能,但我选择了 Sprite,因为:

  • 您将具有交互性并能够从该类调度事件
  • 您将拥有一组 Sprite 具有的有用属性。

有关 Graphics 类的更多信息,请参阅http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/Graphics.html

于 2013-08-23T05:20:10.423 回答