Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Codejunkie

Pages: [1]
1
Java / Re: Collision Detection
« on: August 25, 2015, 03:25:31 am »
I think I figured it out. I have all of my sprites (including the one I designated as my "player" sprite) in the ArrayList of sprites to check for collision. Thus, it was checking for a collision against itself... *doh* how embarrassing...

2
Java / Re: Collision Detection
« on: August 25, 2015, 02:58:28 am »
Okay, I added this line to my code:
Code: [Select]
System.out.println("spriteA: " + spriteA.getGlobalBounds() + "\nsprite" + i + ": " + sprite.getGlobalBounds());
And got this as a result:
Quote
spriteA: FloatRect{left=561.0, top=296.0, width=128.0, height=128.0}
sprite1: FloatRect{left=56.0, top=176.0, width=128.0, height=128.0}
spriteA: FloatRect{left=561.0, top=296.0, width=128.0, height=128.0}
sprite2: FloatRect{left=176.0, top=56.0, width=128.0, height=128.0}
spriteA: FloatRect{left=561.0, top=296.0, width=128.0, height=128.0}
sprite3: FloatRect{left=176.0, top=296.0, width=128.0, height=128.0}
spriteA: FloatRect{left=561.0, top=296.0, width=128.0, height=128.0}
sprite4: FloatRect{left=296.0, top=176.0, width=128.0, height=128.0}
spriteA: FloatRect{left=561.0, top=296.0, width=128.0, height=128.0}
sprite5: FloatRect{left=561.0, top=296.0, width=128.0, height=128.0}
Should I be using getPosition() instead of getGlobalBounds() possibly?

3
Java / Collision Detection
« on: August 24, 2015, 09:23:44 pm »
It runs fine without collision detection, but as soon as I enable it; the sprite won't move at all.

4
Java / Collision Detection
« on: August 24, 2015, 02:28:46 am »
Hi, I'm somewhat new to java game development and thought I'd give SFML a try. I'm trying to do some basic collision detection. For some reason it's not detecting anything. Here's my function for my collision:
Code: [Select]
public static boolean isColliding(ArrayList<Sprite> sprites, Sprite spriteA){
boolean result = false;
for(Sprite sprite : sprites){
if(spriteA.getGlobalBounds().intersection(sprite.getGlobalBounds())!= null){
result = true;
break;
}

}
return result;
}
Am I on the right track at least?

Pages: [1]