顶部的动态文本字段

时间:2016-05-27 17:54:15

标签: actionscript-3 graphics dynamic-text

在我的Adobe 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;

}

'得分'和'死亡'是舞台上两个动态文本字段的实例名称。

Here you can see the score and death counter being covered up by the generated graphics.

1 个答案:

答案 0 :(得分:1)

因为addChild函数会在父级的顶部添加DisplayObject而没有索引。您可以使用索引来管理DisplayObject,但这很麻烦。

我建议你创建两个图层(MovieClip),然后将Graphics添加到下层,将TextField添加到上层。因此TextField始终位于顶部。