Not to sound like an idiot or anything but... how do you handle collisions on side scrollers? So far I've only had trouble when the level scrolled
but when it had no offsets it worked fine . Right now the game is a 15x15 grid of 32x32 tiles, and I've tried about 10 ways in the past month
to get this to work and so far they've failed.
Ps. Sorry if I sound retarded, I'm just frustrated and tired
Collision Detection for side scrolling games
Moderator: Coders of Rage
- GroundUpEngine
- Chaos Rift Devotee
- Posts: 835
- Joined: Sun Nov 08, 2009 2:01 pm
- Current Project: mixture
- Favorite Gaming Platforms: PC
- Programming Language of Choice: C++
- Location: UK
Re: Collision Detection for side scrolling games
If your doing collision e.g. player vs tile, then you will need to test the object against the player's position + the offset
Something like this will work->
Something like this will work->
Code: Select all
bool Player::IsCollide(Tile tile, int offsetX, int offsetY)
{
// add the offsetx
_x = x + offsetX;
_y = y + offsetY;
if( (_x >= tile.x) && (_x <= tile.x + tile.w) && (_y >= tile.y) && (_y <= tile.y + tile.h) )
return true;
}
Re: Collision Detection for side scrolling games
yeah it isn't easy to figure out how to help without some code, or an explanation of how you're doing things, but GUE's advice should help :D
In layman's terms: give us more info, so we can better help you...
In layman's terms: give us more info, so we can better help you...
Re: Collision Detection for side scrolling games
Generally, I will always store player position and calculate collisions using "world" coordinates (i.e. positions relative to the level). I store the "camera" position separately and use it as an offset to convert "world" to "screen" coordinates only when drawing. This means that scrolling has no effect on game logic/collision code.ajtgarber wrote:So far I've only had trouble when the level scrolled but when it had no offsets it worked fine
- Falco Girgis
- Elysian Shadows Team
- Posts: 10294
- Joined: Thu May 20, 2004 2:04 pm
- Current Project: Elysian Shadows
- Favorite Gaming Platforms: Dreamcast, SNES, NES
- Programming Language of Choice: C/++
- Location: Studio Vorbis, AL
- Contact:
Re: Collision Detection for side scrolling games
It should be the exact same as with nonscrolling. The only "offsets" that scrolling is applying is only for RENDERING, not to the actual location of the entities. So I'm not exactly sure how you're handling it.ajtgarber wrote:Not to sound like an idiot or anything but... how do you handle collisions on side scrollers? So far I've only had trouble when the level scrolled
but when it had no offsets it worked fine . Right now the game is a 15x15 grid of 32x32 tiles, and I've tried about 10 ways in the past month
to get this to work and so far they've failed.
Ps. Sorry if I sound retarded, I'm just frustrated and tired
But like ClassA said, it shouldn't make any difference how things are "rendered."
Imagine if my collision checks changed when we zoomed in/out and rotated the world in ES.
- GroundUpEngine
- Chaos Rift Devotee
- Posts: 835
- Joined: Sun Nov 08, 2009 2:01 pm
- Current Project: mixture
- Favorite Gaming Platforms: PC
- Programming Language of Choice: C++
- Location: UK
Re: Collision Detection for side scrolling games
Soz ignore my post, I haven't got enough sleep recently
But ye only the tile rendering gets affected by the offsets, whereas the collision checks are normal just like non-scrollers.
But ye only the tile rendering gets affected by the offsets, whereas the collision checks are normal just like non-scrollers.
Re: Collision Detection for side scrolling games
Thanks for the replies! I think I figured out how to get it working *crosses fingers*, thanks everyone! Falco, great work on LibGyro btw!