2012-04-24 1 views
0

저는 Flash Professional CS5.5를 사용하고 있으며, 가속도계를 사용하여 움직이는 공 (기호)이있는 앱을 만들어야합니다. 공을 A 좌표로 조정하면 프레임 2로 이동합니다. (gotoAndPlay (2)). 먼저 볼을 찾아야 해. 그렇지? 어떻게해야합니까? 여기 AS3 - 기호의 좌표가 여기에 오는 경우?

내가했습니다 코드가 지금

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 데이터를 찾는 경우 필요하지 않습니다. Accelerometer 클래스 및 관련 이벤트가 필요합니다.

이 같은 것을보십시오 :

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

var accel:Accelerometer = new Accelerometer(); 


accel.addEventListener(AccelerometerEvent.UPDATE, handleAccelUpdate); 

업데이트 처리기 : 당신은 아마 몇 가지를 추가 할거야, 그래서

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 
    } 
} 

지금이 화면 밖으로 당신 "롤"당신의 MC를 드릴 것입니다 범위 검사의 종류.

대한 추가 정보를 원하시면이 위대한 작성자 체크 아웃 :

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

0

쉬운 및 (사용자 충족하기 어려운 것) exectly 한 위치 대신 테스트, 방법은 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 ;) 
     } 
    } 
} 
} 
관련 문제