Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


[java] How do I do image priority?

This topic is 5459 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Don''t really know if that title explains itself so here I go. I want to know how to display sprites over eachother. IE: A plane overtop of a ground image. If anyone could help, it would be greatly appreciated, thanx! Point Blank Winners never quit, Quitters never win, and people who never win and never quit are just plain stupid

Share this post

Link to post
Share on other sites
That''s a really vague question. There''s countless ways.

The general way to do it is to draw the background then the airplane. If you have some sort of Sprite class that stores frames for the sprite, and can be told to draw itself when it should, just have the background sprite draw, then the airplane sprite.

How to actually implement that? There''s countless ways, and it all depends on your setup, what graphics libraries you are using, your engine in general, etc.

The way I usually do it is have a Renderer class who controls the screen. If say this is AWT, the Renderer class controls the Graphics object of the main game window/panel/whatever. Sprites register themselves with the Renderer, and when they do they indicate which layer they''d like to be in. Like:

Renderer.getInstance().addSprite(mySprite, 2);

place it on layer two.

Then when its time to draw the screen, the Renderer just goes through each layer in order, and tells each sprite in each layer to draw themselves. Within a layer a sprite has no guarantee it will be in front of/behind another sprite, but between layers, it totally knows. If it''s in layer two, it knows it will always be drawn on top of anything in layer 0 and layer 1.

interface Sprite {
public void draw(Graphics g);

class Renderer {
List[] sprites;

public void addSprite(Sprite s, int layer) {

public void paintComponent(Graphics g) {

for(int i = 0; i < sprites.length; ++i) {
for(int k = 0; k < sprites[i].size(); ++k) {
Sprite s = (Sprite)sprites[i].get(k);


Again, that''s just (a very simplified version of) how I do it. There''s a zillion ways.

Share this post

Link to post
Share on other sites
Uh, don''t you mean "Z-Order", that''s when there are multiple
layers of images being displayed over top and below eachother.
I''m not really sure how that works, but I''m pretty sure your
talking about z-order.

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!