0
我想創建一個圍繞圓圈旋轉的迷你遊戲 但是,我有一個問題,當我拍攝圓圈時,它撞擊第二個圓圈,它不會繼續角度,但「跳躍」到另一個我敢肯定,它應該重置或什麼的角度var的東西。你能幫助我即時通訊越來越緊張在這裏... :( check the exampleAs3三角函數和數學
這是我的輸入框的功能與圓
public function UpdateCircles(e:Event):void
{
for (var i:int = 0; i < EnemySpriteVector.length; i++)
{
EnemySpriteVector[i].rotation += EnemySpriteVector[i].enemyspeed;
}
var rad:Number = angle * (Math.PI/180); // Converting Degrees To Radians
if (IsplayerShoot)
{
playerSprite.x += Math.cos(rad) * PlayerCircleShootSpeed;
playerSprite.y += Math.sin(rad) * PlayerCircleShootSpeed;
for (var j:int = 0; j < EnemySpriteVector.length; j++)
{
if (EnemySpriteVector[j].hitTestPoint(playerSprite.x,playerSprite.y) && (EnemySpriteVector[j].IsCircleHit == false))
{
trace("hit");
EnemySpriteVector[j].IsCircleHit = true;
removeChild(EnemySpriteVector[0]);
EnemySpriteVector.splice(0, 1);
var EnemySprite:Sprite = new EnemySpriteClass();
EnemySpriteVector.push(EnemySprite);
addChild(EnemySprite);
EnemySprite.x = Math.random() * stage.stageWidth;
EnemySprite.y = Math.random() * stage.stageHeight;
IsplayerShoot = false;
}
}
}
else
{
playerSprite.x = EnemySpriteVector[0].x + EnemySpriteVector[0].radius * Math.cos(rad); // Position The Orbiter Along x-axis
playerSprite.y = EnemySpriteVector[0].y + EnemySpriteVector[0].radius * Math.sin(rad); // Position The Orbiter Along y-axis
angle += EnemySpriteVector[0].enemyspeed; // Object will orbit clockwise
playerSprite.rotation = (Math.atan2(playerSprite.y - EnemySpriteVector[0].y, playerSprite.x - EnemySpriteVector[0].x) * 180/Math.PI); //only rotates the player circle itself
}
}
謝謝,我應該在哪裏添加180以及如何, 您的意思是添加到角度var 180或將其轉換爲rad? 再次感謝:) – tomergott 2014-09-29 10:18:56
好吧,從上面的代碼看起來像**角**被定義在其他地方,所以我猜測它從它離開的地方繼續。擊中時你應該增加180°,因爲角度會纏繞_(540°= 180°)_。如果你更喜歡弧度,那麼只需添加PI。 – Iggy 2014-09-29 12:28:54
非常感謝,我會試試:) – tomergott 2014-09-29 14:47:56