isometric tile setup

i have a 2D array of tiles, and each tile is 32x32 pixels.
public void toIso(){
int newX = x+y;
int newY = (int) (0.5*(y-x));

x = newX;
y = newY;
}
public void toIso(){
int newX = x+y;
int newY = (int) (0.5*(y-x));

x = newX;
y = newY;
}
im using this function to convert a normal 2d grid to an isometric view but im not getting an unform grid in return. (0,0 is the top left)
No description
11 Replies
JavaBot
JavaBot4mo ago
This post has been reserved for your question.
Hey @asdru! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
asdru
asdruOP4mo ago
this is en example tile texture
No description
tjoener
tjoener4mo ago
those cubes don't look isometric the angles aren't 45 degrees So if you're trying stuff based on isometric measurements it won't work plus because you're overlapping you need to get your drawing order right
asdru
asdruOP4mo ago
adjusting the position made it work
No description
tjoener
tjoener4mo ago
Cute though 🙂 Always liked the voxelly pastel look
asdru
asdruOP4mo ago
public void toIso(){
int screenWidth = GamePanel.instance.getScreenWidth();
int screenHeight = GamePanel.instance.getScreenHeight();

int newX = (int) ((x-y)*0.66)+screenWidth/2;
int newY = (int) ((x+y)*0.33)+screenHeight/3;
x = newX;
y = newY;
}
public void toIso(){
int screenWidth = GamePanel.instance.getScreenWidth();
int screenHeight = GamePanel.instance.getScreenHeight();

int newX = (int) ((x-y)*0.66)+screenWidth/2;
int newY = (int) ((x+y)*0.33)+screenHeight/3;
x = newX;
y = newY;
}
this is the new function but as u can see from the image the tiles arent perfectly aligned due to float multiplication. so instead of getting 48 i get 47 for example. is there a way to get the right value? thanks :)
tjoener
tjoener4mo ago
yeah, don't just truncate but round should help quite a bit Also GamePanel.instance...
asdru
asdruOP4mo ago
yeah i know its bad practise it helped but its still not perfect 😩 since its a 32x32 tile is it better to just write a function to round numbers up to the closest multiple of 32?
tjoener
tjoener4mo ago
then you won't have smooth scrolling you're doing everything using floating point numbers of course you will have rounding issues also I don't get why you're modifying your x and y Just have a draw function that holds the grid coordinates and make the draw function convert them to screen coordinates This function has too many levels of abstraction
Kyo-chan
Kyo-chan4mo ago
Compute the coordinates of only one tile using the formula you want. All other tile positions, compute them by number of times a tile's width and length
JavaBot
JavaBot4mo ago
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.
Want results from more Discord servers?
Add your server