Tell me more ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I have this main class:

package javagame;

import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.state.BasicGameState;
import org.newdawn.slick.state.StateBasedGame;

public class tests extends BasicGameState{

        public boolean render=false;

        tests1 test = new tests1();
    public tests(int test) {
        // TODO Auto-generated constructor stub
    }

    @Override
    public void init(GameContainer arg0, StateBasedGame arg1)
            throws SlickException {
        // TODO Auto-generated method stub

    }

    @Override
    public void render(GameContainer arg0, StateBasedGame arg1, Graphics g)
            throws SlickException {
        // TODO Auto-generated method stub

        if(render==true)
        {
            g.drawString("Hello",100,100);
        }
    }

    @Override
    public void update(GameContainer gc, StateBasedGame s, int delta)
            throws SlickException {
        // TODO Auto-generated method stub

        test.render=render;
        test.update(gc, s, delta);
    }

    @Override
    public int getID() {
        // TODO Auto-generated method stub
        return 1000;
    }

}

and its sub-class:

package javagame;

import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Input;
import org.newdawn.slick.state.StateBasedGame;

public class tests1 {
    public boolean render;
    public void update(GameContainer gc, StateBasedGame s, int delta)
    {
        Input input = gc.getInput();


        if(input.isKeyPressed(Input.KEY_X))
        {
            render=true;
        }
    }
}

I was finding a way to prevent many codes in one class. I'm new to java. When I try running my game, then when I press X, it does not work. How am I suppose to fix that?

share|improve this question
6  
This has nothing to do with games programming, and your question about classes would require an answer the size of a java programming book. Your last question (does not jump) is most likely too localized and is basically a request for others to debug your code. I suggest you look up a programming course in your local area to attend, and buy some "learn java" style books. Once you have gone through those you should be able to fix this problem easily. – Daniel Carlsson Nov 1 '12 at 9:25

closed as off topic by Jonathan Hobbs, Maik Semder, Josh Petrie, Noctrine Nov 2 '12 at 20:53

Questions on Game Development Stack Exchange are expected to relate to game development within the scope defined in the FAQ. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about closed questions here.

Browse other questions tagged or ask your own question.