Skip to main content
added 583 characters in body
Source Link
David Gouveia
  • 25k
  • 5
  • 88
  • 127

This will be hard to fix in so little time, especially since you're using such a peculiar structure, but well, let's give it a try. I'll post and edit as I notice the most glaring problems.

Step 1) Proper Camera Panning

The first thing that jumped out of your post like a madman was the part where you said:

So, instead of the character moving, everything else actually moves.

This is a complete NO! You don't need to move anything in the world to simulate a camera. The only thing you need to do is to pass a view matrix containing the camera translation to the SpriteBatch. This is literally, one line of code:

spriteBatch.Begin(SpriteSortMode.Deferred, null, null, null, null, null, Matrix.CreateTranslation(-cameraPosition));

Just this! Then all you have to do is change the cameraPosition value and everything will be panned for you at no performance cost. (By the way, notice the minus sign). Or better yet, since the camera will always be centered on the player:

  1. Unlock that player, lock the scenario! Let the player be the one that moves around (and in both axes).
  2. Instead of using some cameraPosition value, just use the playerPosition directly, minus half of the screen size just to make it centered (and don't forget to negate at the end too).

Step 2) Visibility Check

You don't mention anything about this (unless I missed it) but are you perhaps drawing all the tiles at once? If you're doing that, then it's obviously a major source of problems too. Your camera can only see a certain amount of tiles at once, so you only need to draw those tiles.

Step 3) "Too many monsters"

Actually, I doubt it. I've managed to draw thousands and thousands of sprites at once, and never did the application grind to 2 FPS. The amount of monsters you have does not seem like much of a problem. But just to be sure and to gain a little bit of performance, make sure you don't draw monsters that are outside of view.

Step 4) Disable panning on some elements

Is there a way to force some of these elements (such as the background image and the debug info) to stay instead of panning along with everything else?

Simple! Just draw those elements in a separate SpriteBatch block without passing the matrix. For instance:

spriteBatch.Begin();
// Draw background
spriteBatch.End();

spriteBatch.Begin(SpriteSortMode.Deferred, null, null, null, null, null, Matrix.CreateTranslation(-cameraPosition));
// Draw world
spriteBatch.End();

spriteBatch.Begin();
// Draw debug info
spriteBatch.End();

This will be hard to fix in so little time, especially since you're using such a peculiar structure, but well, let's give it a try. I'll post and edit as I notice the most glaring problems.

Step 1) Proper Camera Panning

The first thing that jumped out of your post like a madman was the part where you said:

So, instead of the character moving, everything else actually moves.

This is a complete NO! You don't need to move anything in the world to simulate a camera. The only thing you need to do is to pass a view matrix containing the camera translation to the SpriteBatch. This is literally, one line of code:

spriteBatch.Begin(SpriteSortMode.Deferred, null, null, null, null, null, Matrix.CreateTranslation(-cameraPosition));

Just this! Then all you have to do is change the cameraPosition value and everything will be panned for you at no performance cost. (By the way, notice the minus sign). Or better yet, since the camera will always be centered on the player:

  1. Unlock that player, lock the scenario! Let the player be the one that moves around (and in both axes).
  2. Instead of using some cameraPosition value, just use the playerPosition directly, minus half of the screen size just to make it centered (and don't forget to negate at the end too).

Step 2) Visibility Check

You don't mention anything about this (unless I missed it) but are you perhaps drawing all the tiles at once? If you're doing that, then it's obviously a major source of problems too. Your camera can only see a certain amount of tiles at once, so you only need to draw those tiles.

Step 3) "Too many monsters"

Actually, I doubt it. I've managed to draw thousands and thousands of sprites at once, and never did the application grind to 2 FPS. The amount of monsters you have does not seem like much of a problem. But just to be sure and to gain a little bit of performance, make sure you don't draw monsters that are outside of view.

This will be hard to fix in so little time, especially since you're using such a peculiar structure, but well, let's give it a try. I'll post and edit as I notice the most glaring problems.

Step 1) Proper Camera Panning

The first thing that jumped out of your post like a madman was the part where you said:

So, instead of the character moving, everything else actually moves.

This is a complete NO! You don't need to move anything in the world to simulate a camera. The only thing you need to do is to pass a view matrix containing the camera translation to the SpriteBatch. This is literally, one line of code:

spriteBatch.Begin(SpriteSortMode.Deferred, null, null, null, null, null, Matrix.CreateTranslation(-cameraPosition));

Just this! Then all you have to do is change the cameraPosition value and everything will be panned for you at no performance cost. (By the way, notice the minus sign). Or better yet, since the camera will always be centered on the player:

  1. Unlock that player, lock the scenario! Let the player be the one that moves around (and in both axes).
  2. Instead of using some cameraPosition value, just use the playerPosition directly, minus half of the screen size just to make it centered (and don't forget to negate at the end too).

Step 2) Visibility Check

You don't mention anything about this (unless I missed it) but are you perhaps drawing all the tiles at once? If you're doing that, then it's obviously a major source of problems too. Your camera can only see a certain amount of tiles at once, so you only need to draw those tiles.

Step 3) "Too many monsters"

Actually, I doubt it. I've managed to draw thousands and thousands of sprites at once, and never did the application grind to 2 FPS. The amount of monsters you have does not seem like much of a problem. But just to be sure and to gain a little bit of performance, make sure you don't draw monsters that are outside of view.

Step 4) Disable panning on some elements

Is there a way to force some of these elements (such as the background image and the debug info) to stay instead of panning along with everything else?

Simple! Just draw those elements in a separate SpriteBatch block without passing the matrix. For instance:

spriteBatch.Begin();
// Draw background
spriteBatch.End();

spriteBatch.Begin(SpriteSortMode.Deferred, null, null, null, null, null, Matrix.CreateTranslation(-cameraPosition));
// Draw world
spriteBatch.End();

spriteBatch.Begin();
// Draw debug info
spriteBatch.End();
added 769 characters in body
Source Link
David Gouveia
  • 25k
  • 5
  • 88
  • 127

This will be hard to fix in so little time, especially since you're using such a peculiar structure, but well, let's give it a try. I'll post and edit as I notice the most glaring problems.

Step 1) Proper Camera Panning

The first thing that jumped out of your post like a madman was the part where you said:

So, instead of the character moving, everything else actually moves.

This is a complete NO! You don't need to move anything in the world to simulate a camera. The only thing you need to do is to pass a view matrix containing the camera translation to the SpriteBatch. This is literally, one line of code:

spriteBatch.Begin(SpriteSortMode.Deferred, null, null, null, null, null, Matrix.CreateTranslation(-cameraPosition));

Just this! Then all you have to do is change the cameraPosition value and everything will be panned for you at no performance cost. (By the way, notice the minus sign). Or better yet, since the camera will always be centered on the player:

  1. Unlock that player, lock the scenario! Let the player be the one that moves around (and in both axes).
  2. Instead of using some cameraPosition value, just use the playerPosition directly, minus half of the screen size just to make it centered (and don't forget to negate at the end too).

Step 2) Visibility Check

You don't mention anything about this (unless I missed it) but are you perhaps drawing all the tiles at once?

  If you're doing that, then it's obviously a major source of problems too. Your camera can only see a certain amount of tiles at once, so you only need to draw those tiles.

Step 3) "Too many monsters"

Actually, I doubt it. I've managed to draw thousands and thousands of sprites at once, and never did the application grind to 2 FPS. The amount of monsters you have does not seem like much of a problem. But just to be sure and to gain a little bit of performance, make sure you don't draw monsters that are outside of view.

This will be hard to fix in so little time, especially since you're using such a peculiar structure, but well, let's give it a try. I'll post and edit as I notice the most glaring problems.

Step 1) Proper Camera Panning

The first thing that jumped out of your post like a madman was the part where you said:

So, instead of the character moving, everything else actually moves.

This is a complete NO! You don't need to move anything in the world to simulate a camera. The only thing you need to do is to pass a view matrix containing the camera translation to the SpriteBatch. This is literally, one line of code:

spriteBatch.Begin(SpriteSortMode.Deferred, null, null, null, null, null, Matrix.CreateTranslation(-cameraPosition));

Just this! Then all you have to do is change the cameraPosition value and everything will be panned for you at no performance cost.

Step 2) Visibility Check

You don't mention anything about this (unless I missed it) but are you perhaps drawing all the tiles at once?

  If you're doing that, then it's obviously a major source of problems too. Your camera can only see a certain amount of tiles at once, so you only need to draw those tiles.

Step 3) "Too many monsters"

Actually, I doubt it. I've managed to draw thousands and thousands of sprites at once, and never did the application grind to 2 FPS. The amount of monsters you have does not seem like much of a problem. But just to be sure and to gain a little bit of performance, make sure you don't draw monsters that are outside of view.

This will be hard to fix in so little time, especially since you're using such a peculiar structure, but well, let's give it a try. I'll post and edit as I notice the most glaring problems.

Step 1) Proper Camera Panning

The first thing that jumped out of your post like a madman was the part where you said:

So, instead of the character moving, everything else actually moves.

This is a complete NO! You don't need to move anything in the world to simulate a camera. The only thing you need to do is to pass a view matrix containing the camera translation to the SpriteBatch. This is literally, one line of code:

spriteBatch.Begin(SpriteSortMode.Deferred, null, null, null, null, null, Matrix.CreateTranslation(-cameraPosition));

Just this! Then all you have to do is change the cameraPosition value and everything will be panned for you at no performance cost. (By the way, notice the minus sign). Or better yet, since the camera will always be centered on the player:

  1. Unlock that player, lock the scenario! Let the player be the one that moves around (and in both axes).
  2. Instead of using some cameraPosition value, just use the playerPosition directly, minus half of the screen size just to make it centered (and don't forget to negate at the end too).

Step 2) Visibility Check

You don't mention anything about this (unless I missed it) but are you perhaps drawing all the tiles at once? If you're doing that, then it's obviously a major source of problems too. Your camera can only see a certain amount of tiles at once, so you only need to draw those tiles.

Step 3) "Too many monsters"

Actually, I doubt it. I've managed to draw thousands and thousands of sprites at once, and never did the application grind to 2 FPS. The amount of monsters you have does not seem like much of a problem. But just to be sure and to gain a little bit of performance, make sure you don't draw monsters that are outside of view.

added 769 characters in body
Source Link
David Gouveia
  • 25k
  • 5
  • 88
  • 127

This will be hard to fix in so little time, especially since you're using such a peculiar structure, but well, let's give it a try. I'll post and edit as I notice the most glaring problems.

First Fix -Step 1) Proper Camera Panning

The first thing that jumped out of your post like a madman was the part where you said:

So, instead of the character moving, everything else actually moves.

This is a complete NO! You don't need to move anything in the world to simulate a camera. The only thing you need to do is to pass a view matrix containing the camera translation to the SpriteBatch. This is as simple as doingliterally, one line of code:

spriteBatch.Begin(SpriteSortMode.Deferred, null, null, null, null, null, Matrix.CreateTranslation(-cameraPosition));

Just this! Then all you have to do is change the cameraPosition value and everything will be panned for you at no performance cost.

Step 2) Visibility Check

You don't mention anything about this (unless I missed it) but are you perhaps drawing all the tiles at once?

If you're doing that, then it's obviously a major source of problems too. Your camera can only see a certain amount of tiles at once, so you only need to draw those tiles.

Step 3) "Too many monsters"

Actually, I doubt it. I've managed to draw thousands and thousands of sprites at once, and never did the application grind to 2 FPS. The amount of monsters you have does not seem like much of a problem. But just to be sure and to gain a little bit of performance, make sure you don't draw monsters that are outside of view.

This will be hard to fix in so little time, but let's try. I'll post and edit as I notice the most glaring problems.

First Fix - Camera Panning

The first thing that jumped out of your post like a madman was the part where you said:

So, instead of the character moving, everything else actually moves.

This is a complete NO! You don't need to move anything in the world to simulate a camera. The only thing you need to do is to pass a view matrix to the SpriteBatch. This is as simple as doing:

spriteBatch.Begin(SpriteSortMode.Deferred, null, null, null, null, null, Matrix.CreateTranslation(-cameraPosition));

Just this! Then all you have to do is change the cameraPosition value and everything will be panned for you at no performance cost.

This will be hard to fix in so little time, especially since you're using such a peculiar structure, but well, let's give it a try. I'll post and edit as I notice the most glaring problems.

Step 1) Proper Camera Panning

The first thing that jumped out of your post like a madman was the part where you said:

So, instead of the character moving, everything else actually moves.

This is a complete NO! You don't need to move anything in the world to simulate a camera. The only thing you need to do is to pass a view matrix containing the camera translation to the SpriteBatch. This is literally, one line of code:

spriteBatch.Begin(SpriteSortMode.Deferred, null, null, null, null, null, Matrix.CreateTranslation(-cameraPosition));

Just this! Then all you have to do is change the cameraPosition value and everything will be panned for you at no performance cost.

Step 2) Visibility Check

You don't mention anything about this (unless I missed it) but are you perhaps drawing all the tiles at once?

If you're doing that, then it's obviously a major source of problems too. Your camera can only see a certain amount of tiles at once, so you only need to draw those tiles.

Step 3) "Too many monsters"

Actually, I doubt it. I've managed to draw thousands and thousands of sprites at once, and never did the application grind to 2 FPS. The amount of monsters you have does not seem like much of a problem. But just to be sure and to gain a little bit of performance, make sure you don't draw monsters that are outside of view.

Source Link
David Gouveia
  • 25k
  • 5
  • 88
  • 127
Loading