PDA

Click to See Complete Forum and Search --> : Games & Processor Speed



kendude
03-09-2004, 08:54 AM
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.

mmdev
03-09-2004, 11:25 AM
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

kendude
03-09-2004, 12:28 PM
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

mmdev
03-09-2004, 12:55 PM
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

kendude
03-09-2004, 01:04 PM
function buildRoom (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]);
}
}
}


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

mmdev
03-09-2004, 01:27 PM
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

kendude
03-09-2004, 01:41 PM
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?

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.

mmdev
03-09-2004, 01:57 PM
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

kendude
03-09-2004, 02:01 PM
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?

mmdev
03-09-2004, 02:20 PM
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