XNA Platformer lagging really bad

Started by
4 comments, last by speciesUnknown 12 years, 7 months ago
I've programmed a platfomer in sfml before and used this simlimar method but for some reason it isnt working. Im even passing by reference.. I'm posting the project folder because its really hard to show it on here. I'm kind of rushed on getting this working guys so help is appreciated.. Thanks!!

****************************************
****************************************
EDIT:

I have been using console.writeline to debug logical errors.. will this cause a peformance hit???
Advertisement
okay so for some reason this isnt wanting to return true?
help appreciated and also ideas to optimize collision. thanks
.. couldnt get the code tags to work for some reason.. sorry

[font="Consolas"][color="#0000ff"][font="Consolas"][color="#0000ff"][font="Consolas"][color="#0000ff"]if[/font][/font][/font][font="Consolas"][font="Consolas"](player.GetLoc().X < t.GetX() + t.GetWidth() && player.GetLoc().X + player.GetWidth() > t.GetX())

{

[/font][/font][font="Consolas"][color="#0000ff"][font="Consolas"][color="#0000ff"][font="Consolas"][color="#0000ff"]if[/font][/font][/font][font="Consolas"][font="Consolas"](player.GetLoc().Y > t.GetY() && player.GetLoc().Y < t.GetY() + t.GetHeight())

{



[/font][/font][font="Consolas"][color="#0000ff"][font="Consolas"][color="#0000ff"][font="Consolas"][color="#0000ff"]return[/font][/font][/font][font="Consolas"][font="Consolas"] [/font][/font][font="Consolas"][color="#0000ff"][font="Consolas"][color="#0000ff"][font="Consolas"][color="#0000ff"]true[/font][/font][/font][font="Consolas"][font="Consolas"];

}

}

[/font][/font]
Perhaps a little more information about what you are doing would be useful. I am assuming you are creating a 2D platforming game, and that your collisions are between 2D bounding boxes? From what I can see from the code and that information that i've assumed the collisions seem a bit sketchy at best. For example if you draw it out assuming that two boxes of equal size are positioned at the same Y position and are heading to collide in the X axis.

Your collision test (assuming that their position is based from their top left corner) will check to see if the players top left is less than an objects top right position, then check if the players top right is greater than an objects top left position. So if the collision is occouring so that the player is coming from left to right then the collision would work (all though you would want to change the < and > to <= and >= so that you catch it earlier.

So that would trigger the first line in that scenario but as I said if they are equal in the Y position then your second line will never trigger as you again use > and < instead of >= and <=. I dont have XNA so I cant run your demo but I would suggest looking at the actual values being compared within this statement you can clearly see that a collision is happening on screen in order to specificly decide whats going wrong.

As for a more robust technique, why not check to see if any of the four corners of the players tile is within an objects bounding box? That would give you a more accurate indication of when a collision might be happening, as currently if the player was coming from right to left I dont think your test would even trigger the first line (provided that the coordiantes are as I have assumed).

Hope that helps.
Sorry, I should have been more specific.. I don't really need collision from the left or right just from the top coming down onto the platform. the previous collision system worked but the player would get stuck in the middle of the tile. I changed it to allow a small threshold near the top so the player would not get hung up within the tile. I'm confused though as to why the previous system lagged so bad. Now I guess I can just move on. the next problem I will face though is finding some way to only check collision with the tiles on screen without causing a major performance hit..

Thanks for replying it sure is appreciated :)
This is a rather late reply, sorry. But as for more refined collisions sets, perhaps look into something like Quadtrees, or if you are making a 'screen' based platformer that in itself would act like a form of Quadtree.

...

I have been using console.writeline to debug logical errors.. will this cause a peformance hit???
...




I'll give you three guesses.

Do a search and replace, and replace all calls to Console.WriteLine with calls to Diagnostics.Debug.WriteLine. In non debug builds, this will be a no-op and you wont get a performance hit.

Anyway, when I ran your game myself, I didnt get any lag, but the little dude fell right through the ground. Perhaps you should do a bit more of the game before you start optimising it?
Don't thank me, thank the moon's gravitation pull! Post in My Journal and help me to not procrastinate!

This topic is closed to new replies.

Advertisement