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.
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.
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.
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).
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?
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.