PDA

View Full Version : isometric scrolling - problem



icon
March 29th, 2005, 09:36 AM
Having a brain freeze today. I've got a function which builds a tile map, nothing special.

Here's some of the code:



function build(map) {
_root.createEmptyMovieClip("game", 10);
_root.game.attachMovie("chopper","chopper",5000);
_root.game.chopper._x = 200
_root.game.chopper._y = 100
_root.game.chopper.onEnterFrame = handleFrame;
game._x = startX;
game._y = startY;
for (i=0; i < mapH; i++) {
for (j=0; j < mapW; j++) {
_root.game.attachMovie("tiles", "tile_"+i+"_"+j, ++d);
_root.game["tile_"+i+"_"+j]._x = (tileW/2)*(j-i);
_root.game["tile_"+i+"_"+j]._y = (tileH/2)*(j+i);
_root.game["tile_"+i+"_"+j].gotoAndStop(map[i][j]+1);
}
}
game.chopper.swapDepths(++d);
}



That's nice and simple. I've a frame handler for the chopper mc, which handles which direction the chopper is moving in, and calls the following function:



function moveMap(x, y) {
speed = 3;
movx = x/speed
movy = y/speed
game._x -= movx;
game._y -= movy;
game.chopper._x += movx;
game.chopper._y += movy;
}


Again nice and simple, I just can't seem to get my head around how I would work out which tile the chopperis currently over.

Any pointers would be much appreciated !

I'm feeling pretty dumb over this one

nessaja
March 29th, 2005, 10:28 AM
Hmmmmmm....
That is kind of tough,
If my advice is crap then bear in mind that I have no idea what your game looks like...
:D
here goes... If you could create an Instance for your tiles when you randomly generate them couldn't you try and make a kind of hittest on either the tiles or the chopper???
That would be my first guess, I would also consider the fact wether you are using the mouse to control your chopper or the Keys, also if the chopper is moving without a lock to the map then it would make the matter even worse for example,
using a movie clip to animate the movement of the chopper... example

if (Key.isDown(Key.DOWN)) {
_y += 1;
choppermc.gotoandplay(2);
}

And then it plays a movie of the chopper flying downwards?
If so then I have no idea and all as I can think of is a Hittest....
If not and it is something like 'choppermc_x -= 1' or something then you could make it know which tile it is on easily by locating what position the chopper is on the map for example

_x.choppermc == 240.7
_y.choppermc == 357.2

then you could see what tile is in that area?
I'm sorry if this is no help at all...
If it is completely off the subject then maybe it might have given you an idea on another way to make the game...
Let me know how it goes ;)
Cheersio :)
Nessaja*

nih
March 29th, 2005, 06:20 PM
Yeah, hittests are very convenient. If you do a simple hittest (rect-based rather than shape-based) it's just as fast as any comparison method you would write in Flash.

You COULD work out how to keep track of the chopper's location in the first place - but that's not as mechanically safe as doing a hittest. I'm a big fan of simplifying code, and a hittest fits the bill nicely.