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

  • Home
  • SEARCH
  • 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 8132371
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T09:19:59+00:00 2026-06-06T09:19:59+00:00

Ok so I’ve just started learning java (I usually program in Objective-C). My first

  • 0

Ok so I’ve just started learning java (I usually program in Objective-C). My first game is a game similar to Pokémon, however, its a lot more simplified obviously…

The trouble I’m having is I can’t find a way to stop 2 sprites from ‘ghosting’ through each other. On screen I have borders set up (boundaries), A player sprite, and an Enemy sprite.

public void playerUpdate(GameContainer gc, int delta) throws SlickException
{
    Input input = gc.getInput();

    // Right Key Pressed
    if (input.isKeyDown(Input.KEY_RIGHT) && (leftKeyPressed == false)
            && (upKeyPressed == false) && (downKeyPressed == false))
    {
        player = walkRight;
        playerX += speed * delta;
        rightKeyPressed = true;
        if (playerX >= Main.getWindowWidth() - pImageWidth)
        {
            playerX -= speed * delta;
        }
    } else if (rightKeyPressed == true) 
    {
        player = standRight; 
        rightKeyPressed = false;
    } 

^^ this is where I need to implement the collision detection.
I have added rectangles to each image for collision detection, however, I’m not after a way to make one disappear. I need a way to stop one sprite from walking through another.

Any ideas?

I have tried using

if (this.playerBoundingBox.intersects(Enemy.getEnemyBoundingBox())
{
    playerX += speed * delta;
}

However, when i implement this the player gets stuck and can not be freed.

Thanks guys

  • 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-06T09:20:01+00:00Added an answer on June 6, 2026 at 9:20 am

    Collision detection is a broad and deep topic, and there are many ways to implement it.

    I’d strongly recommend reading The Guide To Implementing 2D Platformers, which should give you some great advice. I’ve implemented a 2D platform engine using the Sonic Retro Physics Guide, which was really useful.

    In my game Clover: A Curious Tale I (needlessly!) implemented a more complicated hybrid of per-pixel collision with bounding boxes. The approach was to work out the desired movement path, and then check pixel-by-pixel to see if anything was in the way – if it was, only move as far as that pixel-minus-one.

    Creating a 2D engine that is flawless in all circumstances is a very tall order, and not something you should attempt. Having some limits on things like size of an actor, and the maximum speed anything can travel in a single tick will make your life easier. Omitting things that can push the player will be much easier, as then you only have to do the collision detection once and in one ‘direction’ (ie when the player moves, rather than when all the other actors move).

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

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
In my XML file chapters tag has more chapter tag.i need to display chapters
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I have thousands of HTML files to process using Groovy/Java and I need to
I'm making a simple page using Google Maps API 3. My first. One marker
For some reason, after submitting a string like this Jack’s Spindle from a text
That's pretty much it. I'm using Nokogiri to scrape a web page what has

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.