Hey!Is there some way to draw my Image with a Z Coordinate not just x,y?So that my spaceship is behind some rocks or before.

Im using Slick and g.drawImage().

You need to draw them at right order. If you want use z coordinate make some array for all images and just sort it every time before drawing and then you can have this feature but with "some" overhead.

You want float for Z because every other OpenGL param is a float, and what if you put something at depth 4 and something at depth 5, and then realize you want something at depth 4.5? You'd have to redo everything with an integer. I don't see any reason why you wouldn't use a float.

I'm not sure why he did Comparable<Object> either. Maybe he's used to Java 1.4-isms (everything being Object) and is just trying to avoid compiler warnings? I agree it seems like doing things half way.

You want float for Z because every other OpenGL param is a float, and what if you put something at depth 4 and something at depth 5, and then realize you want something at depth 4.5? You'd have to redo everything with an integer. I don't see any reason why you wouldn't use a float.

I'm not sure why he did Comparable<Object> either. Maybe he's used to Java 1.4-isms (everything being Object) and is just trying to avoid compiler warnings? I agree it seems like doing things half way.

I agree with you at float. It just has to be float if there is any dynamic ordering. About (Object): That was just some legacy code without any thought.

You want float for Z because every other OpenGL param is a float, and what if you put something at depth 4 and something at depth 5, and then realize you want something at depth 4.5? You'd have to redo everything with an integer. I don't see any reason why you wouldn't use a float.

I'm not sure why he did Comparable<Object> either. Maybe he's used to Java 1.4-isms (everything being Object) and is just trying to avoid compiler warnings? I agree it seems like doing things half way.

I agree with you at float. It just has to be float if there is any dynamic ordering. About (Object): That was just some legacy code without any thought.

Makes sense. I know some people who actually swear by keeping everything as Object and doing typecasting everywhere, and they can never really explain their reasoning to me. Usually it's "flexibility," but it's like... why?

EDIT: Read here first!I didn't explain myself. When you have this problem, you don't want to artificially make up a new Z-layer. What you do, is to just figure out the order the things needs to be drawn in. Here, you always want to draw terrain first, then characters. Your problem, is "Which character is upper-most on screen?" because that character should be drawn first! You can have the entities in a Collection, and you can sort that so when you loop through it, it will hand you the characters starting with the upper-most one, and then slowly getting to the buttom of the screen. This ensures that the correct characters overlaps eachother. Now read what I originally posted.

If you have the entites that needs to be drawn in a Collection, you can very easily use Collection.sort, and get that *bluub* sorted according to whatever you want. It has to be variables you're 100% sure all entries in the Collection posses, so you'd need a Collection like ArrayList<Entity>, and you can sort according to variables in Entity.

You have two options for sorting: Either, you implement an interface in Entity, so that it can be sorted, because Entity isn't known by Java to be an object that has a natural sorting. That's the Comparator-interface. Avoid that for this situation. The other option, is to make a Comparator that compares the entities, according to a variable they have. In this case: The Y-coord.

Here's a class that can sort collections according to both X, and Y-coords.

Then, when you have a collection you want sorted, you simply make a call this way:

1

Collections.sort(entities, CompareUtils.getYOrder());

The field "entities" is your collection here, with all your characters.

Then you can draw your characters like this:

1 2 3

for(Entitye : entites) {//draw code here}

and it will automaticly be in that correct order.

Cheers!

EDIT: In the code I gave you, you might want to change X from a double to an int if you're using tiles. Characters don't stand of half-tiles or 1/3 tiles, do they? The code is from a minor jam last week, and it was used with free-pixel movement.

Well, once you have sorted it ( and its really sorted the right way) you can render it with

1 2 3

for(Entitye : entites) { //draw code here }

As Mads said

I don't even know why you differentiate drawNPC and drawPlayer

Both things, npcs and player, and even enemies, ought to be the same class, or super class. I mean you can do a sub-class for each, but everyone should be the same super class, and be rendered in the same way

Entity npcs[]Entity Player

When you create a sorted list, just throw the player in there too, sorted, and then just draw all

java-gaming.org is not responsible for the content posted by its members, including references to external websites,
and other references that may or may not have a relation with our primarily
gaming and game production oriented community.
inquiries and complaints can be sent via email to the info‑account of the
company managing the website of java‑gaming.org