首先,我是AS3的新手。我想要做的是製作球,以圓形旋轉。這是我當前的代碼: 這是Circular.as爲什麼我不能在此代碼中設置位置(AS3)?
public class Circular extends Sprite {
private var ball:Ball;
private var centerX:Number = stage.stageWidth/2;
private var centerY:Number = stage.stageHeight/2;
private var radiusX:Number = 500;
private var radiusY:Number = 500;
//private var temp:Number = 180;
private static const speed:Number = 0.1;
public function Oval() {
init();
}
private function init():void {
ball = new Ball(40,0x00ff00,180.0);
addChild(ball);
ball.addEventListener(Event.ENTER_FRAME, startMoving(ball,ball.getAngle()));
}
private function startMoving(object:Ball, angle:Number) {
return function(evt:Event){
onStart(object,angle);
}
}
private function onStart(object:Ball,angle:Number){
object.x = centerX + Math.sin(angle) * radiusX;
object.y = centerY + Math.cos(angle) * radiusY;
ball.setAngle(speed);
//trace(ball.getAngle());
}
}
,這是Ball.as類文件
public class Ball extends Sprite {
private var _radius:Number;
private var _color:uint;
private var _angle:Number;
public function Ball(radius:Number,color:uint, angle:Number) {
_radius = radius;
_color = color;
_angle = angle;
init();
}
public function init():void {
graphics.beginFill(_color);
graphics.drawCircle(0,0,_radius);
graphics.endFill();
}
public function getAngle():Number{
return _angle;
}
public function setAngle(speed:Number){
_angle += speed;
}
}
我很抱歉,我忘了提,我現在面臨的問題。我現在的問題是,球沒有移動。有任何想法嗎?
謝謝。但我自己解決了這些問題。它不是類名,我忘了在這裏改變它:P我所做的是更改爲:object.x = centerX + Math.sin(object.getAngle())* radiusX; 無論如何,感謝提到類名稱 – 2010-08-20 03:00:28