Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Actionscript 3 AS3:我如何在自己的课上画形状_Actionscript 3_Flash_Oop - Fatal编程技术网

Actionscript 3 AS3:我如何在自己的课上画形状

Actionscript 3 AS3:我如何在自己的课上画形状,actionscript-3,flash,oop,Actionscript 3,Flash,Oop,我对AS3非常陌生。我想创建一个我在自己的构造函数类中定义的形状 它应该在创建类时创建一个形状。(建造商) 我在以下代码中注释了我的需要: 球形类 public class ballShape { public function ballShape() { // define shape properties. // create shape and put that in x = 0, y = 0 }

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

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

我在以下代码中注释了我的需要:

球形类

public class ballShape {

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

    }

任何帮助都是非常棒的。

您可以轻松完成这一任务,同时将您的类扩展到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所具有的有用属性

有关图形类的更多信息,请参阅

谢谢您的解释。我正在尝试用你们的方法创建一个形状,你们可以在第三方网站中看到我的代码。从
ballShape
创建实例后,它会正确地跟踪某些内容。但运行后不显示任何形状。创建ballShape对象(var ball:ballShape=new ballShape())时,需要将该对象添加到显示列表(addChild(ball));否则,ballShape将创建一个形状,但ballShape本身不会添加到舞台。