-2

在我的 Adob​​e Flash 游戏中,我在舞台上放置了两个动态文本字段。游戏的图形是使用 Actionscript 3 制作的。无论如何,代码生成的块总是会掩盖文本。任何人都可以帮忙吗?

var lvlHolder:Sprite = new Sprite();
addChild(lvlHolder);
//creating the level
//this guy will hold all of the blocks
//hold all trampolines
var trampHolder:Sprite = new Sprite();
lvlHolder.addChild(trampHolder);
var bgHolder:Sprite = new Sprite();
lvlHolder.addChild(bgHolder);
var blockHolder:Sprite = new Sprite();
//then we add him to stage
lvlHolder.addChild(blockHolder);
var scoreHolder:Sprite = new Sprite();
lvlHolder.addChild(scoreHolder);
var deathHolder:Sprite = new Sprite();
lvlHolder.addChild(deathHolder);
//this guy will hold all of the ladders
var ladderHolder:Sprite = new Sprite();
//adding him to stage
lvlHolder.addChild(ladderHolder);
//this guy will hold all of the bumpers
var bumperHolder:Sprite = new Sprite();
lvlHolder.addChild(bumperHolder);
var enemyHolder:Sprite = new Sprite();
lvlHolder.addChild(enemyHolder);
//hold all trampolines
var invisMarkerHolder:Sprite = new Sprite();
lvlHolder.addChild(invisMarkerHolder);
var coinHolder:Sprite = new Sprite();
lvlHolder.addChild(coinHolder);
var goalHolder:Sprite = new Sprite();
lvlHolder.addChild(goalHolder);
var bigCoinHolder:Sprite = new Sprite();
lvlHolder.addChild(bigCoinHolder);



function createLvl():void{
//getting the current level that we are on
var lvlArray:Array = MovieClip(root)['lvlArray'+lvlCurrent];
//we have to find how far this level goes
//this will be used so we know when to move to the next row
//there will always be 16 rows, so this is how we find it out
//of course, this will make the lvl formatting very strict
var lvlColumns:int = Math.ceil(lvlArray.length/16);
//now we must create the level
score.text = "Score = " + mainScore;
deaths.text = "Deaths = " + deathNum;
for(var i:int = 0;i<lvlArray.length;i++){
    //checking if we move onto the next row
    //this checks if i is divisible by the # of columns
    if(i/lvlColumns == int(i/lvlColumns)){
        row ++;
    }
    //defining a target
    var newPlacement;
    if(lvlArray[i] == 1){
        //making a new block
        newPlacement = new Block();
        //drawing the block
        newPlacement.graphics.beginFill(0xFFFFFF/*The color for shape*/,1/*The alpha for the shape*/);
        //turning the shape into a square
        newPlacement.graphics.drawRect(0,0,25,25);
        //then finally adding it to stage
        blockHolder.addChild(newPlacement);
    } else if (lvlArray[i] == 'MAIN'){
        newPlacement = mcMain;
    } else if (lvlArray[i] == 2){
        newPlacement = new Sprite();
        //drawing the ladder
        newPlacement.graphics.beginFill(0xFFFF00,1);
        //turning it into a square
        newPlacement.graphics.drawRect(0,0,25,25);
        //then adding it to stage
        ladderHolder.addChild(newPlacement);
    } else if (lvlArray[i] == 3){
        newPlacement = new Sprite();
        //drawing the bumper
        newPlacement.graphics.beginFill(0xFFFFFF,1);
        //turning it into a square
        newPlacement.graphics.drawRect(0,0,25,25);
        //then adding it to stage
        bumperHolder.addChild(newPlacement);
    } else if (lvlArray[i] == 4){
        newPlacement = new Shape();
        newPlacement.graphics.beginFill(0x00FF00);
        newPlacement.graphics.drawCircle(12.5,25,12.5);
        trampHolder.addChild(newPlacement);
    } else if (lvlArray[i] == 5){
        //adding an enemy
        newPlacement = new Enemy();
        enemyHolder.addChild(newPlacement);
    } else if (lvlArray[i] == 6){
        //adding an invisible marker for the enemy to turn around
        newPlacement = new Shape();
        newPlacement.graphics.beginFill(0x000000,0);
        newPlacement.graphics.drawRect(0,0,25,25);
        invisMarkerHolder.addChild(newPlacement);
    } else if (lvlArray[i] == 7){
        //adding coins
        newPlacement = new Coin();
        //we'll put it in the enemyHolder because this is the only symbol
        //that isn't being looped through
        coinHolder.addChild(newPlacement);
    } else if (lvlArray[i] == 8){
        //the goal!
        newPlacement = new Goal();
        goalHolder.addChild(newPlacement);
    } else if (lvlArray[i] == 9){
        newPlacement = new BigCoin();
        bigCoinHolder.addChild(newPlacement);
    } else if (lvlArray[i] == 'LEFTR'){
        newPlacement = new Block();
        newPlacement.graphics.beginFill(0xFFFFFF,1);
        newPlacement.graphics.drawRoundRect(0, 0, 25, 25, 9);
        newPlacement.graphics.endFill();
        newPlacement.graphics.beginFill(0xFFFFFF);
        newPlacement.graphics.drawRect(15,0,10,25);
        newPlacement.graphics.endFill();
        blockHolder.addChild(newPlacement);
    } else if (lvlArray[i] == 'RIGHTR'){
        newPlacement = new Block();
        newPlacement.graphics.beginFill(0xFFFFFF);
        newPlacement.graphics.drawRoundRect(0, 0, 25, 25, 9);
        newPlacement.graphics.endFill();
        newPlacement.graphics.beginFill(0xFFFFFF);
        newPlacement.graphics.drawRect(0,0,10,25);
        newPlacement.graphics.endFill();
        blockHolder.addChild(newPlacement);
    }  

    if(lvlArray[i] != 0){
        //change the coordinates of the block
        newPlacement.x = (i-(row-1)*lvlColumns)*newPlacement.width;
        newPlacement.y = (row-1)*newPlacement.height;
    }

}
//reset the row for another use
row = 0;
//then we center the screen on the main character
//this variable will tell us how far away we have to move everything
//250 is about centered for mcMain we'll use that number
var mainMove:int = 250 - mcMain.x;
//then move mcMain and the entire level to center on him
mcMain.x += mainMove;
lvlHolder.x += mainMove;

}

'score' 和 'deaths' 是舞台上两个动态文本字段的实例名称。

在这里,您可以看到生成的图形覆盖了得分和死亡计数器。

4

1 回答 1

1

因为addChild函数会DisplayObject在没有索引的父级顶部添加。你可以用index来管理你DisplayObject的s,但是很麻烦。

我建议你创建两个层(MovieClip),然后添加Graphics到下层,添加TextField到上层。以便TextField始终处于顶部。

于 2016-05-28T00:30:08.440 回答