A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: stage size

  1. #1
    Junior Member
    Join Date
    May 2015
    Posts
    2

    Unhappy stage size

    Hi, I recently had some trouble with re-sizing the stage for a game. It's a snake game, and when I re-sized the stage by modifying the document, my snake wouldn't go all the way to the other side of the stage, the borders stayed in the middle. How would I go about re-sizing it and making the snake go all away across the stage? Thank you very much!

    snakeGame.fla

  2. #2
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi,

    Firstly you might want to change your publish settings to AS2 and higher the flah player settings.
    Turn the yellow box into a movieclip and call it "board" no qoutes.
    We are making this into a movieclip as the height and width are different to the stage height and width.

    PHP Code:
    var unit:Number 15;
    var 
    uwh:Number 20;
    var 
    canMove:Boolean false;
    var 
    dir:Number 2;
    var 
    score:Number 0;

    var 
    maxX:Number Math.round(board._width unit);
    trace(maxX);
    var 
    maxY:Number Math.round(board._height unit);
    trace(maxY);

    var 
    aPieceList:Array = new Array();

    var 
    mouseListener:Object = new Object();
    mouseListener.onMouseDown = function()
    {
        if (!
    canMove)
        {
            
    canMove true;
            
    startGame();
        }
    };
    Mouse.addListener(mouseListener);

    var 
    k:Object = new Object();
    k.onKeyDown = function()
    {
        var 
    Key.getCode();
        if (
    == Key.UP && dir != && canMove)
        {
            
    dir 0;
            
    canMove false;
        }
        else if (
    == Key.LEFT && dir != && canMove)
        {
            
    dir 1;
            
    canMove false;
        }
        else if (
    == Key.DOWN && dir != && canMove)
        {
            
    dir 2;
            
    canMove false;
        }
        else if (
    == Key.RIGHT && dir != && canMove)
        {
            
    dir 3;
            
    canMove false;
        }
    };
    Key.addListener(k);

    function 
    addPiece()
    {
        var 
    this.attachMovie("piece""piece" aPieceList.lengthaPieceList.length);
        
    p._x aPieceList[aPieceList.length 1]._x;
        
    p._y aPieceList[aPieceList.length 1]._y;
        
    aPieceList.push(p);
    }

    function 
    moveFood()
    {
        var 
    moveIt:Boolean true;
        while (
    moveIt)
        {
            
    food._x Math.floor(Math.random() * uwh) * unit;
            
    food._y Math.floor(Math.random() * uwh) * unit;
            
    moveIt false;
            for (var 
    0aPieceList.lengthi++)
            {
                if (
    aPieceList[i]._x == food._x && aPieceList[i]._y == food._y)
                {
                    
    moveIt true;
                }
            }
        }
    }

    function 
    gameOver()
    {
        
    delete this.onEnterFrame;
        
    tScore.text "You Lose.  Score: " score;
        
    canMove false;
    }

    function 
    startGame()
    {
        for (var 
    i:Number aPieceList.length 1>= 0i--)
        {
            
    aPieceList[i].removeMovieClip();
            
    aPieceList.pop();
        }
        
    score 0;
        var 
    p:MovieClip this.attachMovie("piece""piece" aPieceList.lengthaPieceList.length);
        
    aPieceList.push(p);

        
    p._x 10 unit;
        
    p._y 10 unit;

        var 
    food:MovieClip this.attachMovie("food""food", -1);
        var 
    c:Number 0;

        
    moveFood();

        var 
    startingLength:Number 3;

        for (var 
    i:Number 1startingLengthi++)
        {
            
    addPiece();
        }

        
    this.onEnterFrame = function()
        {
            
    canMove true;
            
    tScore.text score;
            for (var 
    aPieceList.length 10i--)
            {
                
    aPieceList[i]._x aPieceList[1]._x;
                
    aPieceList[i]._y aPieceList[1]._y;
            }
            if (
    dir == 0)
            {
                
    aPieceList[0]._y -= unit;
            }
            else if (
    dir == 1)
            {
                
    aPieceList[0]._x -= unit;
            }
            else if (
    dir == 2)
            {
                
    aPieceList[0]._y += unit;
            }
            else if (
    dir == 3)
            {
                
    aPieceList[0]._x += unit;
            }
            if (
    aPieceList[0]._y unit == maxY)
            {
                
    aPieceList[0]._y 0;
            }
            else if (
    aPieceList[0]._y unit == -1)
            {
                
    aPieceList[0]._y 19 unit;
            }
            else if (
    aPieceList[0]._x unit == -1)
            {
                
    aPieceList[0]._x 19 unit;
            }
            else if (
    aPieceList[0]._x unit == maxX)
            {
                
    aPieceList[0]._x 0;
            }

            if (
    aPieceList[0]._x == food._x && aPieceList[0]._y == food._y)
            {
                
    score += 10 aPieceList.length 2;
                
    moveFood();
                
    addPiece();
            }

            for (var 
    1aPieceList.lengthi++)
            {
                if (
    aPieceList[0]._x == aPieceList[i]._x && aPieceList[0]._y == aPieceList[i]._y)
                {
                    
    gameOver();
                }
            }
        };


  3. #3
    Junior Member
    Join Date
    May 2015
    Posts
    2
    When I did that, the borders stayed the same when the snake was moving across the screen, but when I moved up or down the snake just disappeared forever

  4. #4
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi,

    You must be doing something differently then, attach the newer version fla that you have done

  5. #5
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi,

    Width and height of board for best results should be divisible by unit var, which is 15 in this case.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center