Isometric Engine (RCT style) - Major update 14.Sep

Yeah, rectangular checking is easy, but that iso tile stuff is a bit trickier. I could really use some code and guidance.

Btw, i m also developing an engine of my own, so i ll add your iso implementation to it. :wink:

Thanx in advance.

The basic idea is very simple:

Every object on the map inherites a basic sprite class, in my engine called a MapObject.

Every mapobject har a function Draw(Graphics g) that draws it onto the graphics surface g.

Whenever an object is drawn, it’s x and y coodinates are stored localy in variables called drawnToxX and drawnToY. (that is the screen coordinates, not the isometric/map coordinates)

Then, when you want to check if the mouse is over this object, simply check if it is between drawnToX and drawnToX+spriteWidth. same for Y coordinates.

Further, grab the color of the pixel at (mouseX-drawnToX, mouseY-drawnToY) from the MapObjects sprite.
If this pixel is opaque it means we found our object =)

If it is transparant it would mean this object (even though the mouse is within its boundingbox) is not the one we want, and we should proceed our search…

Code:

//returns the object under the cursor
public MapObject getClickedObject(int sx, int sy){
    for(int i=partnerWorld.getMapObjectList().size()-1; i>=0; i--){//move backwards through the list
        MapObject o = partnerWorld.getMapObjectList().get(i);
        int x = o.drewToX, y = o.drewToY;
        int w = o.spriteW, h = o.spriteH;
        //check if the mouse is within the object sprite
        if(sx>x && sx<x+w)//are we within this objects bounding box x-wise?
            if(sy>y && sy<y+h){//are we within this objects bounding box y-wise?
                //get color at coord. and correct for frame and rotation sprite offset and stuff. idunno, tired now                
                if(o.getImage().getRGB(sx-x+o.getFrameOffset()   ,sy-y+o.getRotationOffset()) >>> 24 == 255){//is this pixel opaque
                    return o;//if so, return this object
                }
            }
    }
    
    return null;
}

But as I said, you’re gonna need alot more to get a fully functional GUI. You guys want the whole engine perhaps? its open source anyways :wink:

Whoa neat stuff to check for transparency. I thought that i had to make up with some maths to find rombs :wink:

Idea is great, thx a lot!

But you might have tiles with transparent areas in the romb… then that method doesn’t work…

but that’s stating the obvious of course…

:~/Desktop/iso$ java -classpath . misc.MainClass
ERROR LOADING IMAGE FILE: tiles.gif
----Terminating----

Could you fix a linux version, please?
the problem might be the “\” instead File.separatorChar on the file path.

thanks :slight_smile:

Very nice.

I would mention that start.bat didn’t work until I added a “-cp .” option to java.

Note that when you raise your foreground tiles sufficiently, their edges become visually colinear with background tiles. This causes a loss of depth perception. You could overcome this by shading your tiles based on height. Even a subtle gradient would convey the necessary information.

Below I have a shot of a little map I made to demonstrate the problem, and then a photoshopped example suggestion. You could also shade the tiles based on vertex distance from ‘camera’, which would basically be a fogging effect, which would be more subtle but maybe neater.

Again, very cool.

Thanks for the feedback guys.
Im working on a linux version, and it shouldn’t be much work. the only problem as I see it is my picture loading algorythm.
If anyone knows how this is best done, so it works on all platforms, I’d REALLY appreciate it.

This is my code as it is now:

//ripped from http://wiki.java.net/bin/view/Games/TextureLoadingExample, all hail them
private static BufferedImage loadImage(String ref) throws IOException { 
  File file = new File("images\\" + ref);
    if (!file.isFile()) {
        throw new IOException("Cannot find: images\\"+ref);
    }
    BufferedImage bufferedImage = ImageIO.read(new BufferedInputStream(
       new FileInputStream(file))
    ); 
    System.out.println("picture preloaded: " + ref);
    return bufferedImage;
} 

To adress the height problem, ive kinda got an idea.
If you look at other engines like this you’ll see that tiles that are elevated and does not
have a tile behind it at the same level have an extra line drawn on them.

http://www.jonask.com/img/rct_height_issue.png

This picture from RCT illustrates the solution.
I was thinking maybe i could do something like that later on, but right now im focused on other elements of the game =)

It’s really no work at all to make file loading plataform independent just replace every “//” by the File.separatorChar field.

[quote]File file = new File(“images\” + ref);
[/quote]
by

File file = new File("images"+ File.separatorChar + ref);

and

[quote]throw new IOException(“Cannot find: images\”+ref);
[/quote]
by

throw new IOException("Cannot find: images" + File.separatorChar + ref);

separatorChar is a plataform dependant constant: “\” on win and “/” on every other system afaik. see javadoc for sure.

[edit]quotes misplaced[/edit]

Smart!
I did the change, it still works under windows. Im out traveling so i cant test on linux right now, but

try replacing the imagecontroller:

http://www.jonask.com/ImageController.class

that should be an updated version =)
Hope it’ll work

it works :slight_smile:

great engine, i’m taking some ideas for a future project

attached an screenshot

Thats great =)
I’m changing the source on all my projects to match your standard. Again, thanks for the idea.

Best of luck to you guys, and you need only to ask if you want some code

Could u give us the entire code for this engine(if it is not too much too ask).
I m stufed now, so i dont get much time to spare for game coding.
Thx

Yeah sure. The reason I havn’t published it is because it’s not cleaned up. There’s a lot of old code there,
esp in the GUI section. But it will prob be helpfull anyway =)

And antoher thing: I’d really like to know if someone ever uses this code for something (just out of curiosity),
so if you do use any of it, it would be sweet if you dropped me a line so i could see what people did with it :slight_smile:

now, you can get the complete source at www.jonask.com/pro/advancedIsometrics.zip

Best of luck,
Jonas

Thx man. I ll take a look at your code, though that idea for transparency checking was most helpful.
Have fun.

Great! ^^

I allways add a header to every file (in fact, eclipse does it for me :slight_smile: ) with some gpl stuff and my email, so everyone can contact me if he finds bugs or wathever

Jonask’s idea to check for transparent pixels is great, but i wonder if any1 knows to do this in a more “mathematical” way. Well i m sure that there is a way, though it bothers me to find it myself-just not enough spare time and i really dont like to make some math formulas for mysefl-better to get already made and just to understand.

So if any1 knows something like that…well u could share it with the rest of us lazy matemathicans. :wink:

That was a fun little demo. It ran great.