Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I have a 2D map, for each element I apply this isometric projection to place my Sprite

 //Element e;
 float[] f= projection(e.getX(), e.getY() ,z);
         // x and y represent Sprite Coordonate (tile_width and height depend of my 
         // camera size and the number of elements in x and in y
 float x =  f[0]*tile_width;
 float y =  f[1]*tile_height;

   public float[] projection(float x, float y, float z)
   {
     return new float[]{  (( x )-(y) ) , ((x/2) + (y/2) - z  )}; 
   }

the sprite for one element :

enter image description here

The result of my projection :

enter image description here


The problem is I need to add an offset of tile_height/2 to the y and tile_width/2 to the x to have something like this (in the red rectangle I drawed with paint what I want) :

enter image description here

Where did I make wrong?

(I found the projection method in How should I sort images in an isometric game so that they appear in the correct order? )

edit : How I calculate my tile_height and tile_width :

    tile_height = (float) ((CAMERA_HEIGHT/(game.map.getHeight()/2)));
    tile_width =  (float) ((CAMERA_HEIGHT/(game.map.getWidth()/2)));
share|improve this question
    
I haven't done isometric projection before, but shouldn't the tile_height and tile_width be the height and width of the tile sprite? –  tugs Nov 21 '12 at 22:13

1 Answer 1

I am not sure how to create a single projection for multiplying with width and height, but I believe if you send the height and width along, the Projection would be:

public float[] projection(float x, float y, float z, float width, float height)
{
  return new float[]{  
    (x * width / 2) + (y * width / 2),
    (y * height / 2) - (x * height / 2) - (z*height)
  }; 
}

Maybe have a look at 1ManBandStudios' post here.

I hope this helps :)

share|improve this answer
    
I notice an interesting difference in the calculations here. Your code calculates the projection as [x+y, y-x-z] where the code in the question uses [x-y, x+y-z] –  tugs Nov 20 '12 at 23:05
    
That doesn't matter - it just changes the orientation (which direction is x/y). –  Mario Nov 21 '12 at 0:55
    
It doesn't work –  Christophe Debove Nov 21 '12 at 8:17

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.