我正在使用AS3 的物理引擎,下面的代码基本上是 hello world 示例。但是,我通过在类定义的开头将属性“ball”声明为 WheelParticle 进行了轻微更改。(如果有错,请原谅我的术语)。之前,它在构造函数中被声明为
var ball:WheelParticle = new WheelParticle(...);
效果很好。但是现在,以我的方式尝试我得到了错误
将 org.cove.ape.WheelParticle 类型的值隐式强制转换为不相关的类型 Class | 球:WheelParticle = 新...等
“非法分配给 WheelParticle 类”
所以我想我的声明public var ball:WheelParticle
应该是别的东西。但是什么?
无论如何,这是代码。它很短。我会参考文档,但没有。反正我也找不到。
包裹{
import org.cove.ape.*;
import flash.events.*;
import flash.display.Sprite;
public class Bounce extends Sprite {
public var ball:WheelParticle;
public function Bounce() {
stage.focus = this;
stage.frameRate = 100;
addEventListener(Event.ENTER_FRAME, run);
stage.addEventListener(KeyboardEvent.KEY_DOWN, moveLeft);
APEngine.init(0.3);
APEngine.container = this;
APEngine.addMasslessForce(new Vector(0,2));
var defaultGroup:Group = new Group();
defaultGroup.collideInternal = true;
var ball:WheelParticle = new WheelParticle(250,10,40, false, 1, 0.7, 0.1);
defaultGroup.addParticle(ball);
var rp:RectangleParticle = new RectangleParticle(250,300,300,50,0,true);
defaultGroup.addParticle(rp);
APEngine.addGroup(defaultGroup);
}
private function moveLeft(e:Event):void{
ball.speed += 1;
}
private function run(evt:Event):void {
APEngine.step();
APEngine.paint();
}
}
}