1

我的代码有一个小问题。我想链接所有三个类来制作一个简单的平台游戏。这是代码:

数组类:

package 
{
import flash.display.*;
public dynamic class setupStage extends Thiny
{
    var mapWid = 24;
    var mapHei = 40;
    var tileSide = 10;
    var totalTiles = mapWid * mapHei;
    var cell:tile=new tile();

    var firstStage:Array=[
      /*1*/[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]
      /*2*/[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1]
      /*3*/[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1]
      /*4*/[1,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1]
      /*5*/[1,0,0,0,1,0,0,0,0,0,1,1,1,1,1,0,0,0,1,1,1,1,0,1]
      /*6*/[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1]
      /*7*/[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1]
      /*8*/[1,0,0,0,0,1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,1]
      /*9*/[1,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,1]
     /*10*/[1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,1]
     /*11*/[1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,1]
     /*12*/[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1]
     /*13*/[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1]
     /*14*/[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1]
     /*15*/[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1]
     /*16*/[1,0,0,0,0,0,0,0,0,0,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1,1,1,1,1,1]
     /*35*/[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1]
     /*36*/[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1]
     /*37*/[1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1]
     /*38*/[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1]
     /*39*/[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1]
     /*40*/[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]
      ];
    function setupStage()
    {
        trace("access granted");
    }
    function drawMap():void
    {
        for (var i:int=0; i<mapWid; i++)
        {
            for (var u:int=0; u<mapHei; u++)
            {
                cell.gotoAndStop(firstStage[i][u]+1);
                cell.x = tileSide * i;
                cell.y = tileSide * u;
                with (stage)
                {
                    stage.addChild(cell);
                }
            }
        }
    }
}
}

运动类:

package 
{
import flash.display.*;
import flash.utils.*;
import flash.events.*;
import flash.sampler.StackFrame;

public dynamic class JAJEBIE extends Thiny{
var granica:setupStage = new setupStage();
var thinX = 0;
var thinY = 0;
var acc = 6;
var thin:thiny1 = new thiny1();
var przycisk:Object = {};

stage.addEventListener(KeyboardEvent.KEY_DOWN,Move);
stage.addEventListener(KeyboardEvent.KEY_UP,Halt);
//with (thin){addEventListener(Event.ENTER_FRAME,Opadanie);}

function wrzut():void
{
    addChild(thin);
    thin.x = 200;
    thin.y = 390;

}
function Move(k:KeyboardEvent):void
{
    przycisk[k.keyCode] = true;
    if (przycisk[Keyboard.LEFT] && granica.firstStage[thinX][thinY] == 0 && granica.firstStage[thinX - 1][thinY] == 0)
    {
        thin.x = thin.x - 10;
    }
    if (przycisk[Keyboard.RIGHT] && granica.firstStage[thinX][thinY] == 0 &&     granica.firstStage[thinX - 1][thinY] == 0)
    {
        thin.x = thin.x + 10;
    }
    if (przycisk[Keyboard.SPACE])
    {
        acc = 3;
        thin.y = thin.y + 30;
    }
}
//function Opadanie(Event);
//{
//thin.y = thin.y - 30;
//}
function Halt(k:KeyboardEvent):void
{
    przycisk[k.keyCode] = false;
}

}

}

主fla文件:

stop();
import flash.events.Event;
import flash.display.DisplayObject;
import flash.utils.*;
import flash.events.*;
import flash.sampler.StackFrame;

stage.addEventListener(Event.ENTER_FRAME,initialize);

function initialize(main_event:Event):void{
        with(setupStage){drawMap();};
        with(JAJEBIE){wrzut();};
        stage.removeEventListener(Event.ENTER_FRAME,initialize);
}

我们尝试了很多东西,但编译器一直抛出错误,即使我们设法删除了所有代码问题,主类似乎不想修补所有内容。任何帮助,将不胜感激!谢谢!

4

1 回答 1

0

您需要拥有每个类的实例JAJEBIEsetupStage,以便您拥有平台游戏关卡和玩家的样本。你的代码说这JAJEBIE是一个静态类,因为它没有构造函数,所以你通过类名来解决它是正确的——除非错误 5000 被抛出JAJEBIE,在这种情况下你的代码是纯错误的。

var jajebie:JAJEBIE;
function initialize(main_event:Event):void{
    jajebie=new JAJEBIE();
    addChild(jajebie);
    addChild(jajebie.granica);
    // while neither is added to stage, they 
    // cannot reach the stage! You have to point them to actual stage.
    jajebie.granica.drawMap(); // now, as we have stage access, draw the map
    jajebie.wrzut();
    stage.removeEventListener(Event.ENTER_FRAME,initialize);
}

此外,您只有一个cell实例setupStage,并且您反复尝试设置其坐标并将其放到舞台上。这种方法是错误的,因为您最终会cell在屏幕上看到一个实例,它会在右下角。通过重新实例化你cell的内部循环来解决这个问题。

函数 drawMap():void { for (var i:int=0; i

最后,您需要学会自己阅读和解释错误消息,以便了解 Flash 想要告诉您什么。比如说,错误 5000 意味着您必须为您的任何一个类扩展一个给定的类(很可能MovieClip),这可能会迫使您立即重新编写大部分代码。

于 2013-07-01T05:30:37.320 回答