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 9055439
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T13:57:15+00:00 2026-06-16T13:57:15+00:00

I hope that the title has not made this post more confusing than it

  • 0

I hope that the title has not made this post more confusing than it already is. The problem I am having may be better explained if I tell you exactly what I have done so far:

The Game

I have made a very simple 2D game, the basics are, a player moves around a 2D map with keyboard input (up, down, left. right arrows) this game is kind of like a pokemon view where the view is from the top, his speed is set simply by using the following code for each keyboard input:

 if(input.isKeyDown(Input.KEY_DOWN)){
    bucky = movingDown;
    buckyPositionY -= 2;
    if(buckyPositionY<-550){//this is used to stop player from leaving the map
        buckyPositionY += 2;}}

The same is done for the other 3 keyboard inputs.

The Problem

I have made the game where the player can move around but the problem is I have objects on the map and at the moment my player just walks through them, so I need to set up collisions, I know how to set up collisions using the rectangle method but the problem is actually making the rectangles. I know it is a simple task but on this game whenever I place my Rectangle down it moves when I move my player, I tested for this by drawing the rectangle with the following code:

g.fillRect(0,0,100,100);

Thats the coordinates for an obstacle on my map, when I draw the rectangle it appears on the top left cornor of my screen and when I move my player it stays there (it keeps moving to stay in the top left cornor), now this is a big problem for me because if my rectangles are moving how is my collision supposed to work. I think the reason that this is happening is because my map is very big meaning that rather than showing the full thing I just centered my player on the center of my screen and when he moves the screen also moves with him to show the rest of the map.

The Code

Here is the code in my game class, it has methods such as render, init and update in it but I think the only code required to fix this problem is the render method and the variables so here they are (if the full code is required please tell me)

The Variables

 Animation bucky, movingUp, movingDown, movingLeft, movingRight
Image worldMap;
boolean quit = false;
int[] duration = {200, 200};
int buckyPositionX = 0;
int buckyPositionY = 0;
int shiftX = buckyPositionX + 320;
int shiftY = buckyPositionY + 160;

The render Method

public void render(GameContainer gc, StateBasedGame sbg, Graphics g) throws SlickException{
worldMap.draw(buckyPositionX, buckyPositionY);//position 0,0
bucky.draw(shiftX, shiftY);//makes him appear at center of map

if(quit==true){
    g.drawString("Resume(R)", 250, 100);
    g.drawString("Main(M)", 250, 150);
    g.drawString("Quit Game(Q)", 250, 200);      
    if(quit==false){
        g.clear();
    }}}

I am sorry about this thread being so long bit if you could please take the time to help me and answer my question I would really appreciate it.

Thank you.

  • 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-16T13:57:17+00:00Added an answer on June 16, 2026 at 1:57 pm

    As I said the rectangles(obstacles) are moving because the drawing coordinates are defined with respect to the screen, not the game map. That is when the character moves and you repaint the game map the rectangle is still drawn at (0,0) i.e. top-left of the screen.

    Here are some suggestions.

    • Use a seperate offscreen Image for the game map. The image size will be of
      the same size as of the game map.
    • Rectangles(obstacles) & other stuff excluding the character should be drawn on this image by getting a graphic context of this image using getGraphics
    • Finally when the character moves you paint a part of the image on screen using drawImage(Image img, int dstx1, int dsty1, int dstx2, int dsty2, int srcx1, int srcy1, int srcx2, int srcy2, ImageObserver observer) method. The explanation of this method is avaliable here. You have to calculate which part of the image to paint from the position of the character

    A thing to keep in mind is the character should only be drawn on screen, not on the game map Image. The character should be drawn on screen after drawing the game map image.

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

Sidebar

Related Questions

The title is probably not accurate but I hope that reading this post you
[I hope that this question is not too broad, I think that the subject
Not too sure how to formulate my question and I hope that this is
I know the title of my question sounds like a question that already has
I'm not sure how to explain this problem so the title is kind of
I hope the title makes sense. I have a set of items that I
I thought I'd post here in the hope that maybe someone with MVVM expertise
This is my first question on Stack Overflow, so I hope that I'm clear
Ok, I'm not sure that my title was clear enough, but I will try
That title is a mouthful and a bit confusing, but you are still reading

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.