Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (499)
Games in Android Showcase (118)
games submitted by our members
Games in WIP (567)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Tiled world - Z-ordered drawing  (Read 1418 times)
0 Members and 1 Guest are viewing this topic.
Offline Mads

JGO Ninja


Medals: 26
Projects: 3
Exp: 6 years


One for all!


« Posted 2011-01-12 14:51:10 »

I have a tiled world, which is really neat. I have an object for the objects in my tiled world, that doesn't move and I'm z-ordering them by
casting them in an arraylist by biggest Y-coord, so I can draw the objects accordingly to that and the z-ordering would be correct.

However, I need a player aswell which i'm quite unsure about how to render with correct z-ordering. Do I need to make the player have the same superclass as the other objects, throw them in the same list, and then update that list everytime update() is called? That seems like a bad solution to me.. Please give me your input on this, and please ask if I haven't explained something good enough Smiley

Thanks guys  Cheesy

Offline Bonbon-Chan

JGO Coder


Medals: 12



« Reply #1 - Posted 2011-01-12 15:40:52 »

It doesn't seems too bad to me. I have done it like that several times.
When you say "and then update that list everytime update() is called", I think you want to say that you need to sort that list every frame. Depending on the number of object in the list (+10000  Grin), it is not a problem. The list is "almost sorted" each time so it may not take a lot of time to sort them (to verify).
Offline Mads

JGO Ninja


Medals: 26
Projects: 3
Exp: 6 years


One for all!


« Reply #2 - Posted 2011-01-12 16:30:29 »

Thanks for the reply.  Cool
 If I'm going to do it that way, how do you suggest sorting them?
I can't think of a way right now.

A different approach is having a method for drawing the objects, that takes the objects and the player as arguments (different objects), and then loop through the list of still-objects (houses, trees, etc.), but with drawing the player when the loop reaches that x-coord. I can't see any downsides on that, except complexity, when NPC's are going to wander my world. That doesn't seem bad though..
That way all the still objects wouldn't have to be sorted every frame, but only once while in that scene. However, I still need a way to update the list. I have not worked much with lists - could someone perhaps provide pseudocode just for sorting a list of instances of the objects? Cheesy

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Orangy Tang

JGO Kernel


Medals: 56
Projects: 11


Monkey for a head


« Reply #3 - Posted 2011-01-12 18:14:20 »

My solution is usually to sort every frame. This is actually pretty quick providing you:

1. place different objects into different layers. ie. the 'floor' layer never needs sorting as it's always drawn first. the 'object' layer (with walls and players) needs sorting, but has much less things in it.
2. first find the visible items, then add them to the sorting list. That means you're only sorting the 50ish visible characters and walls, not the 1000+ in your level.

[ TriangularPixels.com - Play Growth Spurt, Rescue Squad and Snowman Village ] [ Rebirth - game resource library ]
Offline Mads

JGO Ninja


Medals: 26
Projects: 3
Exp: 6 years


One for all!


« Reply #4 - Posted 2011-01-12 19:21:44 »

My solution is usually to sort every frame. This is actually pretty quick providing you:

1. place different objects into different layers. ie. the 'floor' layer never needs sorting as it's always drawn first. the 'object' layer (with walls and players) needs sorting, but has much less things in it.
2. first find the visible items, then add them to the sorting list. That means you're only sorting the 50ish visible characters and walls, not the 1000+ in your level.

I didn't think of not drawing the objects that aren't seen - Thanks for that idea. I might go with the sorting in each frame, but how can I do so from a list of all the instances? Do I need to create a new list?

Offline xinaesthetic

Senior Member


Medals: 1



« Reply #5 - Posted 2011-01-12 23:00:57 »

You need a collection of all the objects with their coordinates projected into view space, then you can sort on that (ie with a comparator)
Offline SwampChicken
« Reply #6 - Posted 2011-01-13 01:58:21 »

I love tiled games, any screenshots of your W.I.P.?
Offline Mads

JGO Ninja


Medals: 26
Projects: 3
Exp: 6 years


One for all!


« Reply #7 - Posted 2011-01-13 08:17:43 »

You need a collection of all the objects with their coordinates projected into view space, then you can sort on that (ie with a comparator)

I can't do that  Sad Can you perhaps give a pseudocode example?

I love tiled games, any screenshots of your W.I.P.?

Right now it's not much, as objects are completely left out due to this rendering issue. When that's in place, smooth walking is my only obstacle Smiley
I'll supply pictures when I got objects to render with correct Z-ordering.

Offline cylab

JGO Ninja


Medals: 50



« Reply #8 - Posted 2011-01-13 09:40:01 »

I can't do that  Sad Can you perhaps give a pseudocode example?

You can! Read the article and make yourself a selfcontained test case to try it out.

Mathias - I Know What [you] Did Last Summer!
Offline Mads

JGO Ninja


Medals: 26
Projects: 3
Exp: 6 years


One for all!


« Reply #9 - Posted 2011-01-13 14:08:42 »

I can't do that  Sad Can you perhaps give a pseudocode example?

You can! Read the article and make yourself a selfcontained test case to try it out.

I actually see where this article is going now (had to have a closer look). I'll read the whole article, when I get home  Smiley

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Pippogeek (39 views)
2014-09-24 16:13:29

Pippogeek (30 views)
2014-09-24 16:12:22

Pippogeek (19 views)
2014-09-24 16:12:06

Grunnt (45 views)
2014-09-23 14:38:19

radar3301 (27 views)
2014-09-21 23:33:17

BurntPizza (63 views)
2014-09-21 02:42:18

BurntPizza (33 views)
2014-09-21 01:30:30

moogie (41 views)
2014-09-21 00:26:15

UprightPath (50 views)
2014-09-20 20:14:06

BurntPizza (54 views)
2014-09-19 03:14:18
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
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
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!