2012-04-24 12 views
0

私はFlash Professional CS5.5を使用しています。加速度計を使用して移動するボール(シンボル)がある場所にアプリケーションを作成する必要があります。ボール座標Aがこの座標Bに到達するとフレーム2に移動します(gotoAndPlay(2))。私は最初に、ボールのcoordを見つける必要がありますか?これをどうやって作るの?ここでAS3 - シンボルの座標がここに来たら?

は、私があれば、それは座標をretrivingた後、仕事となりました

c_ball.addEventListener(MouseEvent.MOUSE_DOWN, fl_ClickToDrag); 
function fl_ClickToDrag(event:MouseEvent):void{ 
c_ball.startDrag();} 
stage.addEventListener(MouseEvent.MOUSE_UP, fl_ReleaseToDrop); 
function fl_ReleaseToDrop(event:MouseEvent):void{ 
c_ball.stopDrag();} 

したコードのですか?

function f_level (e) if (c_ball.x==100 && c_ball.y==100) { 
gotoAndStop(2);} 

答えて

0

MOUSE_UPとMOUSE_DOWNは、加速度計のデータを探している場合に必要なものではありません。 Accelerometerクラスとそれに関連するイベントが必要です。

このような何か試してください:あなたは、おそらくいくつかを追加したいとしているので、今これは画面の外にあなたが「ロール」あなたのMCをさせます

function handleAccelUpdate(e:AccelerometerEvent):void{ 
    //inside this function you now have access to acceleration x/y/z data 
    trace("x: " + e.accelerationX); 
    trace("y: " + e.accelerationY); 
    trace("z: " + e.accelerationZ); 
    //using this you can move your MC in the correct direction 
    c_ball.x -= (e.accelerationX * 10); //using 10 as a speed multiplier, play around with this number for different rates of speed 
    c_ball.y += (e.accelerationY * 10); //same idea here but note the += instead of -= 

    //you can now check the x/y of your c_ball mc 
    if(c_ball.x == 100 && c_ball.y == 100){ 
     trace("you win!"); //fires when c_ball is at 100, 100 
    } 
} 

import flash.sensors.Accelerometer; 
import flash.events.AccelerometerEvent; 

var accel:Accelerometer = new Accelerometer(); 


accel.addEventListener(AccelerometerEvent.UPDATE, handleAccelUpdate); 

更新ハンドラを一種の境界チェック。

詳細は、この偉大な過去記事チェックアウト:

http://www.republicofcode.com/tutorials/flash/as3accelerometer/

0

簡単にし、(ユーザーのために満たすことは困難である何)exectly 1つの位置のために代わりテストの、仕方がcolission検出を使用することであるあなたを救いますターゲット地域に行く:

package 
{ 
import flash.display.Sprite; 
import flash.events.Event; 
import flash.events.MouseEvent; 

public class Hittester extends Sprite 
{ 

    var ball:Sprite = new Sprite(); 
    var testarea:Sprite = new Sprite(); 

    public function Hittester() 
    { 
     super(); 
     ball.graphics.beginFill(0xff0000); 
     ball.graphics.drawCircle(0,0,10); 

     testarea.graphics.beginFill(0x00ff00); 
     testarea.graphics.drawRect(0,0,50,50); 
     testarea.x = 100; 
     testarea.y = 100; 

     // if testarea should be invisble 
     /*testarea.alpha = 0; 
     testarea.mouseEnabled = false; 
     */ 

     ball.addEventListener(MouseEvent.MOUSE_DOWN, startDragging); 

     addChild(testarea); 
     addChild(ball); 
    } 
    private function startDragging(E:Event = null):void{ 
     ball.startDrag(); 
     stage.addEventListener(MouseEvent.MOUSE_UP, stopDragging); 
    } 
    private function stopDragging(E:Event = null):void{ 
     stage.removeEventListener(MouseEvent.MOUSE_UP, stopDragging);  
     ball.stopDrag(); 

     test(); 
    } 
    private function test():void{ 
     if(! ball.hitTestObject(testarea)){ 
      ball.x = 10; 
      ball.y = 10; 
     } 
     else{ 
      // here goes next frame command ;) 
     } 
    } 
} 
} 
関連する問題