Hey,
I'm developing a sort of framework for my 2D games with SFML .NET. I would like it to be more of a generic framework. I am, however, running into a few performance issues. Here are some methods I am using which I am concerned with:
Collisions: Every frame I loop through each object to see if it collides with any other object in the scene (2 loops) and I do a bounding-box-type test (and then enter into pixel-perfect). Recently I implemented a "hascollisions" property that filters out all objects in the first loop that don't have anything to do when they collide with something, which has greatly improved my performance. Is there another way?
Drawing:
Every new object has its own image (stores its own sprite). This gets complicated when i have 100+ objects on screen. Would it make more sense to have 1 sprite and move it around to each object's position, load in the object's image, and draw it instead of drawing individual sprites?
I also try to implement a sort of "culling". If objects are outside of the screen, they are not drawn. However, I feel like the way I am doing it may be inefficient:
drawSpr = (Sprite)objList[i].resources["imgmain"];
collider = new SFML.Graphics.FloatRect((float)drawSpr.Position.X, (float)drawSpr.Position.Y, (float)drawSpr.Position.X + (float)drawSpr.Width, (float)drawSpr.Position.Y + (float)drawSpr.Height);
if (SFML_WINDOW.GetView().Viewport.Intersects(collider))
{
SFML_WINDOW.Draw(drawSpr);
}
^This runs every frame. I am not very familiar with SFML so I don't know if there is a better way.
These are a few of my main concerns.
Are there any articles or projects that you would recommend I take a look at in order to better-aquatint myself with common practice?
Thanks,
Lox