Sign in to follow this  
CodyShort

XNA Platformer lagging really bad

Recommended Posts

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???

Share this post


Link to post
Share on other sites
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"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"]if[/color][/size][/font][/color][/size][/font][/color][/size][/font][font="Consolas"][size="2"][font="Consolas"][size="2"](player.GetLoc().X < t.GetX() + t.GetWidth() && player.GetLoc().X + player.GetWidth() > t.GetX())

{

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

{



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

}

}

[/size][/font][/size][/font]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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 :)

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
[quote name='Coder4Life95' timestamp='1311305698' post='4838763']
...

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


[/quote]

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?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this