A Flash Developer Resource Site

Results 1 to 10 of 10

Thread: Games & Processor Speed

  1. #1
    Senior Member kendude's Avatar
    Join Date
    Sep 2003
    Location
    Hartford, CT USA
    Posts
    877

    Games & Processor Speed

    I rewrote my Castle Adventure for mobile devices. It is way better than the original, much more efficient, better treasure, etc...The problem is I am told it runs "slow". It is written w/ Flash 5 syntax, from what I understand it takes a while to load the next room. It is tile based and I do not see how it can be any more efficient. I used the gotoAndStop engine, I am making a version with the arrays compressed, that will reduce the file size, but may tax the processor a bit more to uncompress them. I will send that out for testing tomorrow. Has anyone else written any tile based games for a mobile device and if so , lets talk. Thanks.

    I am open to any suggestions.

  2. #2
    Can you post a few chunks of code? Perhaps the main engine or part that runs slow?

    Also, what are your tiles made out of (vector, bitmap, etc).

    Nader

  3. #3
    Senior Member kendude's Avatar
    Join Date
    Sep 2003
    Location
    Hartford, CT USA
    Posts
    877
    There are 400 tiles (20 x 20) being drawn at once. Each tile is 10px, I think this is where it is bogging down. I used a gotoAndStop engine, with all my tile info in arrays. I think I should try a game with maybe only 100 tiles (10 x 10) per room. The graphics are gifs, they are very small in file size. It is super fast and efficient on a computer, but it's the phone processor that bogs.
    Thanks.

    Here is a sample of the graphics:
    http://kendude.com/games/castleescape.html

  4. #4
    you could:
    1. try laying out all your tiles ahead of time
    (instead of dynmically and probably within a loop)
    2. and then tell targeting.

    Can't do much more w/o code samples...

    Nader

  5. #5
    Senior Member kendude's Avatar
    Join Date
    Sep 2003
    Location
    Hartford, CT USA
    Posts
    877
    PHP Code:
    function buildRoom (map) {
        
    =1;
        var 
    mapWidth map[0].length;
        var 
    mapHeight map.length;
        for (var 
    0i<mapHeight; ++i) {
            for (var 
    0j<mapWidth; ++j) {
                
    this.ZZ.attachMovie("tile""t_"+i+"_"+j, ++d);
                
    this.ZZ["t_"+i+"_"+j]._x = (j*tileW);
                
    this.ZZ["t_"+i+"_"+j]._y = (i*tileH);
                
    this.ZZ["t_"+i+"_"+j].gotoAndStop(map[i][j]);
            }
        }

    The arrays are large and not yet compressed.(20 x 20)

  6. #6
    Try physically laying out your tiles and then just
    just setting the proper images thru your loop.

    I'm doing something simliar in another app of about
    15x20 tiles and it's about .5 seconds rendering time.

    Tell targeting may look like
    (converted to Flash 4 syntax for fastest processing):
    myMapPiece = map[i][j];
    tellTarget ("ZZ/t_" add i add "_" add j) {gotoAndStop (../:myMapPiece) }

    Nader

  7. #7
    Senior Member kendude's Avatar
    Join Date
    Sep 2003
    Location
    Hartford, CT USA
    Posts
    877
    I am not sure of how to "physically lay out the tiles". Do you mean always have the tiles on the screen, then just tell them what frame to go to. I think I can dig it. Is this correct?

    code:
    function initRoom (map) {
    d =1;
    var mapWidth = map[0].length;
    var mapHeight = map.length;
    for (var i = 0; i<mapHeight; ++i) {
    for (var j = 0; j<mapWidth; ++j) {
    this.ZZ.attachMovie("tile", "t_"+i+"_"+j, ++d);
    this.ZZ["t_"+i+"_"+j]._x = (j*tileW);
    this.ZZ["t_"+i+"_"+j]._y = (i*tileH);
    this.ZZ["t_"+i+"_"+j].gotoAndStop(map[i][j]);
    }
    }
    }
    //--
    function buildRoom (map) {
    var mapWidth = map[0].length;
    var mapHeight = map.length;
    for (var i = 0; i<mapHeight; ++i) {
    for (var j = 0; j<mapWidth; ++j) {
    this.ZZ["t_"+i+"_"+j].gotoAndStop(map[i][j]);
    }
    }
    }


    the buildRoom function now only changes the frame# of the tile.
    The initRoom is only called at the beginning of the game.
    Last edited by kendude; 03-09-2004 at 01:51 PM.

  8. #8
    Yeah. Instead of placing tiles via attachmovie or duplicate movie clip,
    copy/paste them on the screen and assign instance names manually such
    r1t1, r1t2, r1t3, etc

    So the tiles are always there. If they need to be hidden, they could be placed in a container and then just turned on and off (_visible = true or false).

    Please let us know how it goes.

    Good luck,
    Nader

  9. #9
    Senior Member kendude's Avatar
    Join Date
    Sep 2003
    Location
    Hartford, CT USA
    Posts
    877
    I have to send it out to have them test it. I attach the clips dynamically at first when the game loads (initRoom()), that is the only time I attach them now. That will be the same as physically doing it, right? I know it will take a few seconds lomger only when it first loads. But then each time i change the room, only the tiles' frames change. Or is your way of doing it manually better?
    Last edited by kendude; 03-09-2004 at 02:04 PM.

  10. #10
    Not better - I prefer dynamically, but sometimes
    it's faster.

    One thing I've found really helpful on mobile devices
    when testing for speed is to display the amount
    of time it takes to run a function in milliseconds
    via a dynamic text field.

    It's helped me to identify bottlenecks - and usually
    the slowest parts can be isolated to a small area
    of your code.

    Nader

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