Results 1 to 3 of 3
  1. #1
    MW130 is offline Senior Member
    Join Date
    Jan 2013
    Posts
    317
    Rep Power
    2

    Default A few questions for my game

    I am making a little game, and I have a few questions.
    First, I have a figure that moves around the screen. It uses keylisteners and just subtracts or adds pixels. However, I notice the movement is not smooth at all. It is very rigid and laggy movement. How can I make it smoother movement?
    Second, you get three lives in the game. The lives are subtracting correctly, but I want the game to say "GAME OVER" on a dialog box. How would I get this to happen? My JFrame and my life int are in separate classes. I know I should use an if statement, saying if lives are at or less than zero, open the box, but how do I open the box?
    Third, I want to display the time on the screen. I have a swing timer, but how do I put it on the screen? DrawString is not working for me.
    Fourth, I want to set an icon for the game, the code is running, but not doing anything.
    Java Code:
        	frame.setIconImage(Toolkit.getDefaultToolkit().getImage("/Users/MW/Downloads/petericon.jpg"));
    I can provide code if necessary. Thanks guys!

  2. #2
    pj6444 is offline Senior Member
    Join Date
    Jan 2013
    Posts
    162
    Rep Power
    2

    Default Re: A few questions for my game

    Well first you may want to double buffer your game so that you do not skip any frames.
    Second, you could create a getter and setter for your lives int. This is something you should know how to do if you are making a game. Here's how to do it:
    Java Code:
    public int getLives() {
        return lives;
    }
    
    public void setLives(int lives) {
        this.lives = lives;
    }
    Once you do that you just want to create a JDialogBox for the condition of having no lives left.

    I do not know about the icon but my best guess is to do this:
    https://www.google.com/#q=java+JFrame+icon

  3. #3
    MW130 is offline Senior Member
    Join Date
    Jan 2013
    Posts
    317
    Rep Power
    2

    Default Re: A few questions for my game

    Thanks! Really helped:
    Two things that are still outstanding;
    how do I display the timer in seconds on the screen, and how do I make a jdialogbox that will not only appear, but also stop the game?

    EDIT: Also, my class in which I set the if statement for the open box if lives are zero is different from the main class, which has the JFrame. So, how do I open the JDialog in the other class, since I can't access the frame which is in the other (main) class?
    And lastly, is there any preset method that can just restart my program from the top?
    I have an option to quit or restart, and I know how to exit, but not how to just restart
    Last edited by MW130; 01-23-2014 at 03:40 PM.

Similar Threads

  1. Puzzle game questions
    By tzeus in forum New To Java
    Replies: 4
    Last Post: 12-11-2013, 07:07 PM
  2. Replies: 4
    Last Post: 07-08-2012, 09:07 AM
  3. 3D game questions.
    By Disaster in forum New To Java
    Replies: 2
    Last Post: 07-06-2011, 10:05 PM
  4. Replies: 1
    Last Post: 06-02-2011, 09:29 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •