questios about an isometric game

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
rokit boy
Party member
Posts: 198
Joined: Wed Jan 18, 2012 7:40 pm

questios about an isometric game

Post by rokit boy »

i have 2 questions

1 is "layers" or z_index. how can i make 1 sprite draw behind or infront of another given sprite.

2nd is how would i make a 2d coords to 3d coords function?

i have 1 function called coords3dto2d which is this:

Code: Select all

function coords3dto2d(x,y,z)
	return (x-y)*tilesize/2,(x+y)*tilesize/2/2-z*tilesize/2+(love.keyboard.isDown(" ") and math.random(-2,2) or 0)
end
how would i make 2d coordinates like 25.2,51 back to 3d coordinates like 1,2,1

if there is any more info i need to add please tell me
u wot m8
User avatar
Plu
Inner party member
Posts: 722
Joined: Fri Mar 15, 2013 9:36 pm

Re: questios about an isometric game

Post by Plu »

Regarding the first, as far as I know draw calls overwrite older calls, so in order to draw things in the right order, start drawing stuff with the lowest Z-value and work up from there and they should appear properly.

Regarding transforming 2d coordinates to 3d coordinates... you don't. There's data missing in the 2d coordinate so you won't be able to properly calculate a coordinate in a 3d space from them. You'll need to internally keep track of both sets of coordinates for each object and use the 3d coordinate for calculation and the 2d coordinate for drawing.
User avatar
rokit boy
Party member
Posts: 198
Joined: Wed Jan 18, 2012 7:40 pm

Re: questios about an isometric game

Post by rokit boy »

Plu wrote:Regarding the first, as far as I know draw calls overwrite older calls, so in order to draw things in the right order, start drawing stuff with the lowest Z-value and work up from there and they should appear properly.

Regarding transforming 2d coordinates to 3d coordinates... you don't. There's data missing in the 2d coordinate so you won't be able to properly calculate a coordinate in a 3d space from them. You'll need to internally keep track of both sets of coordinates for each object and use the 3d coordinate for calculation and the 2d coordinate for drawing.
for the last one i mistyped, i meant to turn something like 25.5, 51 to 1,2. without the z.
i have tried so many times
u wot m8
User avatar
micha
Inner party member
Posts: 1083
Joined: Wed Sep 26, 2012 5:13 pm

Re: questios about an isometric game

Post by micha »

From your code the formula from 3d to 2d is

Code: Select all

x2 = (x3-y3)*tilesize/2
y2 = (x3+y3)*tilesize/2/2
(x2,y2) are the 2d-coordinates, (x3,y3) are the 3d-coordinates.

You can solve this for x3 and y3 by multiplying the first by 2/tilesize and the second by 4/tilesize.
You get (this are equations, not lua-code)

Code: Select all

2*x2/tilesize = x3-y3
4*y2/tilesize = x3+y3
and then add/subtract

Code: Select all

4*y2/tilesize+2*x2/tilesize = 2*x3
4*y2/tilesize-2*x2/tilesize = 2*y3
and then make it a bit nicer:

Code: Select all

x3 = (2*y2+x2)/tilesize
y3 = (2*y2-x2)/tilesize
User avatar
rokit boy
Party member
Posts: 198
Joined: Wed Jan 18, 2012 7:40 pm

Re: questios about an isometric game

Post by rokit boy »

micha wrote:From your code the formula from 3d to 2d is

Code: Select all

x2 = (x3-y3)*tilesize/2
y2 = (x3+y3)*tilesize/2/2
(x2,y2) are the 2d-coordinates, (x3,y3) are the 3d-coordinates.

You can solve this for x3 and y3 by multiplying the first by 2/tilesize and the second by 4/tilesize.
You get (this are equations, not lua-code)

Code: Select all

2*x2/tilesize = x3-y3
4*y2/tilesize = x3+y3
and then add/subtract

Code: Select all

4*y2/tilesize+2*x2/tilesize = 2*x3
4*y2/tilesize-2*x2/tilesize = 2*y3
and then make it a bit nicer:

Code: Select all

x3 = (2*y2+x2)/tilesize
y3 = (2*y2-x2)/tilesize
thanks!
u wot m8
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 3 guests