2014-12-06 3 views
0

정말 멍청한 질문에 대한 시간이지만, 만족스러운 답을 찾을 수 없습니다. 배열 자습서를 검색 할 때마다 배열의 다른 문자열을 어떻게 배열하고 다시 액세스하는지에 관한 것입니다. 여기AS3에서 동일한 영화 클립을 다른 장소에 추가하는 것을 어떻게 제어합니까?

내가 무엇을 가지고 : 당신이 게임을 시작하면

, 당신은 단 5 개 버튼을 말할 수 언론에 수 있습니다. 당신은 (간체) 버튼을 1 플래시를 누르면 이동 :

하는 AddChild (배경) 하는 AddChild (세계) world.gotoAndStop (1) 하는 AddChild (문자) 등 다른 버튼

그리고 변화하는 세계 당신은에있어 여기

내가 원하는 무엇인가. 내가 어떤 버튼 플레이어 프레스에 따라, 특정 같은 적 무비 클립 장소를 을 추가 할 수 있어야합니다.

플레이어가 버튼 3을 누르고 3 세계에서 x 200, y 300의 적, x 600, y 450의 적, 다른 적의 특정 장소가 있기를 원한다고 가정 해 봅시다. 모든 적들은 같은 무비 클립입니다.

그래서 어떻게 그런 적을 추가 할 수 있습니까 ???

배열이 필요하지만 원하는 영화 클립에 어떻게 액세스합니까?

내 코드 :

패키지는 {

import flash.display.MovieClip; 
import flash.events.Event; 
import flash.events.MouseEvent; 

public class Main extends MovieClip { 

    public var character:Character; 
    public var backGround:BackGround; 
    public var world:World; 
    public var worldMap:WorldMap; 
    public var monster1:Monster1; 
    public var worldLevel:int; 
    public var currentLevel:int; 

    public function Main() { 

     backGround = new BackGround; 
     world = new World; 
     monster1 = new Monster1 
     character = new Character(); 
     worldMap = new WorldMap; 

     // Every world lies in a different frame in the "world" movieclip 
     world.worldDangers.gotoAndStop(currentLevel); 
     world.SafeGround.gotoAndStop(currentLevel); 
     world.GroundViz.gotoAndStop(currentLevel); 
     world.PortaltoNew.gotoAndStop(currentLevel); 

     //----- on the world map is the different world buttons --- 
     addChild(worldMap); 

     addEventListener(Event.ENTER_FRAME, moveWorld) 

     //------------------- world buttons -------------------- 
     worldMap.buttonWorld1.addEventListener(MouseEvent.CLICK, gotoWorld1) 
     worldMap.buttonWorld2.addEventListener(MouseEvent.CLICK, gotoWorld2) 
     worldMap.buttonWorld3.addEventListener(MouseEvent.CLICK, gotoWorld3) 
     worldMap.buttonWorld4.addEventListener(MouseEvent.CLICK, gotoWorld4) 
    } 


    function gotoWorld1 (m:MouseEvent):void 
    { 
     currentLevel = 1; 
     addChild(backGround); 

     addChild(world); 
     world.x = 0; 
     world.y = 0; 

     isinWorld = true 

     addChild(character); 
     character.x = 300; 
     character.y = 650; 
     character.gotoAndStop(3); 


     worldMap.parent.removeChild(worldMap); 
    } 


    //----------------- function world 2 --------------------- 
    function gotoWorld2 (m:MouseEvent):void 
    { 
     currentLevel = 2; 
     addChild(backGround); 

     addChild(world); 
     world.x = 0; 
     world.y = 0; 

     isinWorld = true 

     addChild(character); 
     character.x = 300; 
     character.y = 650; 
     character.gotoAndStop(3); 

     worldMap.parent.removeChild(worldMap); 
    } 

    //----------------- function world 3 ----------------------- 
    function gotoWorld3 (m:MouseEvent):void 
    { 
     currentLevel = 3; 
     addChild(backGround); 

     addChild(world); 
     world.x = 0; 
     world.y = 0; 

     isinWorld = true 

     addChild(character); 
     character.x = 300; 
     character.y = 650; 
     character.gotoAndStop(3); 


     worldMap.parent.removeChild(worldMap); 
    } 

    function gotoWorld4 (m:MouseEvent):void 
    { 
     currentLevel = 4; 
     addChild(backGround); 

     addChild(world); 
     world.x = 0; 
     world.y = 0; 

     isinWorld = true 

     addChild(character); 
     character.x = 300; 
     character.y = 650; 
     character.gotoAndStop(3); 


     worldMap.parent.removeChild(worldMap); 
    } 




    function moveWorld (e:Event) 
    { 


     if (isinWorld) 
     { 
      world.y = world.y + 5; 


      if (character.hitTestObject(monster1)) 
      { 
      world.parent.removeChild(world); 
      backGround.parent.removeChild(backGround); 
      character.parent.removeChild(character); 

      isinWorld = false 


      } 
     } 
    } 
} 

은}

+0

을하지 좌표 사물. – akmozo

답변

0

같은 뭔가가 트릭해야 다음 : 당신은 그냥 원수를 절약 할 수 배열에서

// Define a bunch of positions for this world 
var positions:Array = [ 
    new Point(200, 300), 
    new Point(600, 450), 
    new Point(50, 350) 
]; 

// Probably makes sense to store your enemies on 
// an array for access later in your game 
var enemies:Array = []; 

// Temporary variables for the loop 
var enemy:Enemy; 
var position:Point; 

// Iterate over the positions array 
for (var i:int = 0; i < positions.length; i ++) 
{ 
    // Get the position 
    position = positions[i] as Point; 

    // Create a new enemy and position him 
    enemy = new Enemy(); 
    enemy.x = position.x; 
    enemy.y = position.y; 

    // Add child and store it on an array 
    addChild(enemy); 
    enemies.push(enemy); 
} 
+0

답변 해 주셔서 감사합니다. 예를 들어이 코드를 button3 (세계 3으로 이동하는 버튼) 함수에 씁니까? 그리고 다른 위치로 button4 함수에 같은 코드를 씁니다. (왜냐하면 적들은 세계 4에서 서로 다른 입장을 취할 것이기 때문이다.) – Jens

+0

보다 나은 시각적 표현을 제공한다면 코드를 추가했다. – Jens