Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Game Image Layering Help

  1. #1
    Junior Member
    Join Date
    Aug 2011
    Posts
    25
    My Mood
    Bored
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Game Image Layering Help

    I'm making this game in java, as it is my first attempt at a full fledged game. It's fairly going well, until I hit the NPC part. The depth of them needs to change when I'm in front of, and behind them. When I'm behind him, he needs to appear in front of the player, and when I'm in front of him, it needs to appear behind me. Problem is, the only way I can do this is JLayeredPane, and it hasn't worked at all so far, seeing as the entities in my games just use simple images and not icons. The render looks like this:

    //Draw here
    map.drawMap(g, screenX, screenY, player.X, player.Y);
    time.drawTimeOverlay(g, screenWidth+20, screenHeight+20);
    levelMessage = stats.tick();
    eman.tick(g, player, screenX, screenY, map);
    player.tick(g,screenWidth,screenHeight,screenX, screenY, this);
    inven.drawInventory(g);
    stats.drawMeters(g);

    All that needs to be done is eman and player to be switched when necessary, however nothing is this simple in Java.
    Any suggestions?


  2. #2
    Forum VIP
    Join Date
    Jun 2011
    Posts
    317
    My Mood
    Bored
    Thanks
    47
    Thanked 89 Times in 74 Posts
    Blog Entries
    4

    Default Re: Game Image Layering Help

    Is this a top down orthographic or a 2D sidescroller? I don't know if I can help you (do most of my games programming in C++) but the order in which you render the sprites on screen relates to which one is on top. The last one you draw will draw over the other ones. Try putting the player.tick line before the eman. If you need one in front of the other based on certain conditions just create a boolean and an if.

    if (playerInFront) {
       player.tick(g,screenWidth,screenHeight,screenX, screenY, this);
       eman.tick(g, player, screenX, screenY, map);
    else {
       eman.tick(g, player, screenX, screenY, map);
       player.tick(g,screenWidth,screenHeight,screenX, screenY, this);
    }

    Oh, and try to use the highlight tag around code. It makes it easier for us to read and help you.

  3. #3
    Junior Member
    Join Date
    Aug 2011
    Posts
    25
    My Mood
    Bored
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Game Image Layering Help

    Quote Originally Posted by ChristopherLowe View Post
    Is this a top down orthographic or a 2D sidescroller? I don't know if I can help you (do most of my games programming in C++) but the order in which you render the sprites on screen relates to which one is on top. The last one you draw will draw over the other ones. Try putting the player.tick line before the eman. If you need one in front of the other based on certain conditions just create a boolean and an if.

    if (playerInFront) {
       player.tick(g,screenWidth,screenHeight,screenX, screenY, this);
       eman.tick(g, player, screenX, screenY, map);
    else {
       eman.tick(g, player, screenX, screenY, map);
       player.tick(g,screenWidth,screenHeight,screenX, screenY, this);
    }

    Oh, and try to use the highlight tag around code. It makes it easier for us to read and help you.
    That looks like it'll work! Thanks man. I appreciate it!
    Oh, and it's Top Down, Like pokemon, or the retro Final Fantasies.

    EDIT!
    Actually, no that wouldn't haha.
    eman is the Entity Manager, which manages numerous entities.
    Essentially, Imagine the player between two vertically parallel NPCs.
    Last edited by SkyAphid; December 31st, 2011 at 01:36 AM.

  4. #4
    Forum VIP
    Join Date
    Jun 2011
    Posts
    317
    My Mood
    Bored
    Thanks
    47
    Thanked 89 Times in 74 Posts
    Blog Entries
    4

    Default Re: Game Image Layering Help

    Quote Originally Posted by SkyAphid View Post
    EDIT!
    Actually, no that wouldn't haha.
    eman is the Entity Manager, which manages numerous entities.
    Essentially, Imagine the player between two vertically parallel NPCs.
    In that case you will need to redesign to get what you want. One cheap and quick option may be to pass the player object into your entity manager as a parameter and then gig things around in eman.tick so the player gets drawn where you want. Without looking at how you designed your game it is kind of difficult to know how to advise you, this suggestion may be way off.

    Actually, I am not entirely sure what the problem is now. Perhaps you could provide a screenshot? If it a top down, then won't the player ALWAYS be on top?

Similar Threads

  1. Create image Jpeg from an object of Image class.
    By Ramandeep in forum File I/O & Other I/O Streams
    Replies: 2
    Last Post: December 31st, 2011, 11:34 PM
  2. Replies: 1
    Last Post: August 18th, 2011, 06:48 AM
  3. Replies: 2
    Last Post: February 14th, 2011, 05:36 PM
  4. Replies: 1
    Last Post: December 7th, 2009, 01:55 PM
  5. Pixel Alteration in an image/image rotation
    By bguy in forum Java Theory & Questions
    Replies: 3
    Last Post: November 1st, 2009, 10:50 AM