Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9278359
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T17:20:52+00:00 2026-06-18T17:20:52+00:00

I am creating a very simple Java Slick game in 2d. I can use

  • 0

I am creating a very simple Java Slick game in 2d. I can use the renderer method int the class that extends the BasicGameState but i would like to render into my game container using a DarwMap class.

Here is my source code for the game and the not working DrawMap class:

public class GamePlay extends BasicGameState{

    DrawMap map;

    public GamePlay(int state){

    }

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

    @Override
    public void render(GameContainer gc, StateBasedGame sbg, Graphics g) throws SlickException {
        map.render();
    }

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

    }

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

and the next class

public class DrawMap {

    //size of the map
    int x,y;
    //size of the tile
    int size;

    //tile
    Image tile;

    //creator
    public DrawMap(GameContainer gc, int x, int y, int size){
         this.x = x;
         this.y = y;
         this.size = size;
    }

    public void render() throws SlickException{

         tile = new Image("res/Tile.png");

         for(int i=0; i<(y/size); i++){
             for(int j=0; j < (x/size); j++){
                 tile.draw(j*size, i*size, 2);
            }
         }
    }

}

I know that this is wrong but if someone could help me figure it out and solve my problem of drawind with a DrawMap class.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T17:20:53+00:00Added an answer on June 18, 2026 at 5:20 pm

    I don’t see it in your constructor, but I’m assuming you’re creating your map instance there.

    Now, to draw onto the screen (and this is valid to Slick and Java2D in general) you need a Graphics object, that represents a graphics context, which is the object that manages to put your data into the screen. In the case of Slick2D, you can get the graphics from the GameContainer using a call to it’s getGraphics method. Then, you can draw your image into the screen calling the drawImage method on the Graphics object you just obtained.

    Here is an example, passing the graphics context as a parameter of the DrawMap‘s render method:

    public class GamePlay extends BasicGameState{
    
        DrawMap map;    
        ...
    
        @Override
        public void render(GameContainer gc, StateBasedGame sbg, Graphics g) throws SlickException {
            map.render(gc.getGraphics());
        }
        ...
    }
    

    And the DrawMap class…

    public class DrawMap {
    
        Image tile;
        ...        
    
        public void render(Graphics g) throws SlickException {
        // your logic to draw in the image goes here
    
            // then we draw the image. The second and third parameter
            // arte the coordinates where to draw the image
            g.drawImage(this.tile, 0, 0);
        }   
    }
    

    Of course, you can go ahead and draw directly into the Graphics object.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

A very simple use case for creating users in webapp2/appengine can be as follows:
I have a very simple Java JTable question. I am creating this class to
Suppose I am building a very simple eclipse plugin for creating new java projects.
I'm creating a very simple Java chat program, using the Java TCP sockets. I'm
I'm writing a very simple Java Game. Let me describe it briefly: There are
I am creating a simple REST service, which owns only REST resource (java class
I am attempting to implement a very simple Trie in Java that supports 3
I'm creating an app on android in java, very simple, which has a button
I have a very simple java applet that I took from here: http://docs.oracle.com/javase/tutorial/deployment/applet/subclass.html import
I am creating a very simple application that only has a seek bar that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.