The forums have permanently moved to forum.kirupa.com. This forum will be kept around in read-only mode for archival purposes. To learn how to continue using your existing account on the new forums, check out this thread.


Results 1 to 7 of 7

Thread: isometric tile game (swapdepths problems?)

  1. #1

    isometric tile game (swapdepths problems?)

    hi there,

    I'm trying to create an isometric tile game engine, and everything was going well as long as the hero moved a whole tile at a time. I've now added code in to make the hero move more smoothly, but the depthswapping is wrong (until you move fully onto a new tile, and then it's corrected)
    there's also a weird bug where if you scroll around the map fully a couple of times, then occassional tiles start disappearing, and whole lines get left in odd places on the screen.

    would anyone be kind enough to take a quick look and see if they can see where I'm going wrong? - any help would be greatly appreciated.

    there's an example of the swf here:
    http://www.salmacis.co.uk/isometry/trials.html

    and a zipped Flash 5 file (hopefully commented sufficiently!) here:
    http://www.salmacis.co.uk/isometry/trials.zip

    thanks again,
    john

  2. #2
    Hoi

    Ok am working on a iso type game too. Not as far as you.
    I looked at you fla and I hope you don't mind but I don't feel like looking through all your code but I did note that you swap the depths of all your tiles and hero...bad idea. You are going to make a mess of all your depths so this is that I was thinking of

    Have each tile on its own depth and never change it. The topmost tile has the lows depth and the lowest tile have the highest depth. Then the have the rest of you tile in between that. Keep some space in between the depths of your tiles, 2 or more see attachment
    just look at one of the tiles, if you look at the tiles above it your depths are all lower and if you look at the tile under it, are all higher like this they are all nicely sorted. The spaces are for the hero to move around in. ok here is a function the calculates the depth
    Code:
    calculateDepth = function(x, z, worldXMax, worldZMax ) {
    	var leeway = 2;
    	var x = Math.abs(x)*leeway;
    	var z = Math.abs(z)*leeway;
    	var a = worldXMax;
    	var b = worldYMax;
    	var floor = a*(b-1)+x;
    	var depth = a*(z-1)+x+floor;
    	return depth;
    };
    You can use this to put the tile on their right depth. To put the hero on the right depth just get the depth of the tile he is on and add one to it.

    There hope that helps

    .....

  3. #3
    cool - thanks for the reply.

    I'll have a go at that tonight!

  4. #4
    bit quiet at work at the moment, so I thought I'd try it quickly. I had to change your code slightly as my tile (0,0) is the furthest left tile (as in the kirupa isometry tutorial) and got this:

    PHP Code:
    function calculatedepth (tilecoordxtilecoordyobj) {
        var 
    factor 2;
        
    // factor is the space between 1 tile's depth and the next
        
    var tiledepth = ((maplengthy-tilecoordy)*10)+(tilecoordx*factor);
        if (
    obj == "tile") {
            return 
    tiledepth;
        } else {
            
    // for hero's depth:
            
    return (tiledepth+1);
        }


    I've altered the draw map function to this:

    PHP Code:
    function buildmap () {
        for (var 
    = (herox-visx); x<=(herox+visx); x++) {
            for (var 
    = (heroy-visy); y<=(heroy+visy); y++) {
                var 
    counter calculatedepth(xy"tile");
                
    trace (x+","+y+" depth: "+counter);
                
    _root.scrollclip.attachMovie("tile""t_"+x+"_"+ycounter);
                
    _root.scrollclip["t_"+x+"_"+y]._x spacing*(x+y);
                
    _root.scrollclip["t_"+x+"_"+y]._y spacing/2*(x-y);
                
    frame map1[x][y];
                
    // 
                // if tile not defined in array, show blank tile
                
    if (!frame) {
                    
    frame 100;
                }
                
    _root.scrollclip["t_"+x+"_"+y].gotoAndStop(frame);
            }
        }

    which loops through the area around the hero, attaching a movieclip from the library to an empty clip each time it loops, and checks the map array which gives the frame number to display.

    I've traced all my variables, and it's looping through the buildmap function correctly. I've traced the depths and drawn them all out and they're perfect, but now for some reason I'm getting whole blocks just not existing. When I display the variables in the output window, the missing objects aren't there (either not created or have been deleted for some reason I guess)

    I'm stumped!
    the only other function running is the one to create the empty container movie clip.

    can anyone see where the error is? please!?

    thanks again
    john

    here's an image of what's happening (there shouldn't be those blank tiles along the top left edge)

  5. #5
    don't know if this helps but...

    just noticed that it seems to be the 'visx' variable that determines how many blocks don't show.
    'visx' is the number of tiles either side of the hero that will be shown.

    if visx is 2 then 0 rows are missing (ie. everything is drawn correctly)
    if visx is 3 then 2 rows are missing, (as in the image above)
    if visx is 4 then 4 rows are missing,
    if visx is 5 then 6 rows are missing ... and so on,

    any help would be REALLY appreciated

    cheers

  6. #6
    I havent looked at your code, but judging from what you are doing I would assume you are still having depth problems. the blocks are dissapearing because other blocks are taking their depth (or the hero is.) If I were going to look into the problem, I would check your depth code.

  7. #7
    APDesign was right it was still a depth prob

    here I updated the function to work well with your buildmap function you just need to debug your other function.
    Code:
    function calculatedepth(tilecoordx, tilecoordy, obj) {
    	var factor = 2;
    	var x = Math.abs(tilecoordx)*factor;// very importent !?!
    	var y = Math.abs(tilecoordy)*factor;// very importent !?!
    	var tiledepth = maplengthx*(x-1)-y;
    	if (obj == "tile") {
    		return tiledepth;
    	} else {
    		// for hero's depth:
    		return (tiledepth+1);
    	}
    }

    .....

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012