Skip to main content
added 14 characters in body; edited tags; edited title
Source Link
user1430
user1430

Fast determination of How can I quickly determine whether objects are onscreen in 2D?

So currentlyCurrently, I have this in each object's renderer's update method:

 float a = transform.position.x * Main.scale; float b = transform.position.y * Main.scale; float c = Camera.main.transform.position.x * Main.scale; float d = Camera.main.transform.position.y * Main.scale; onscreen = a + width - c > 0 && a - c < GameView.width && b + height - d > 0 && b - d < GameView.height; 

transform.position is a 2D vector containing the game engine's definition of where the object is - this. This is then multiplied by Main.scale to translate that coordinate into actual screen space Similarly.

Similarly, Camera.main.transform.position is the in-engine representation of where the main camera is, and this is also multiplied by MainMain.scale.scale

The problem is, as my game is tile-based, thousands of these updates get called every frame, just to determine whether or not each object should be drawn - how. How can I improvedo this more efficiently, please?

Fast determination of whether objects are onscreen in 2D

So currently, I have this in each object's renderer's update method:

 float a = transform.position.x * Main.scale; float b = transform.position.y * Main.scale; float c = Camera.main.transform.position.x * Main.scale; float d = Camera.main.transform.position.y * Main.scale; onscreen = a + width - c > 0 && a - c < GameView.width && b + height - d > 0 && b - d < GameView.height; 

transform.position is a 2D vector containing the game engine's definition of where the object is - this is then multiplied by Main.scale to translate that coordinate into actual screen space Similarly, Camera.main.transform.position is the in-engine representation of where the main camera is, and this is also multiplied by Main.scale

The problem is, as my game is tile-based, thousands of these updates get called every frame, just to determine whether or not each object should be drawn - how can I improve this please?

How can I quickly determine whether objects are onscreen in 2D?

Currently, I have this in each object's renderer's update method:

 float a = transform.position.x * Main.scale; float b = transform.position.y * Main.scale; float c = Camera.main.transform.position.x * Main.scale; float d = Camera.main.transform.position.y * Main.scale; onscreen = a + width - c > 0 && a - c < GameView.width && b + height - d > 0 && b - d < GameView.height; 

transform.position is a 2D vector containing the game engine's definition of where the object is. This is then multiplied by Main.scale to translate that coordinate into actual screen space.

Similarly, Camera.main.transform.position is the in-engine representation of where the main camera is, and this is also multiplied by Main.scale.

The problem is, as my game is tile-based, thousands of these updates get called every frame, just to determine whether or not each object should be drawn. How can I do this more efficiently, please?

Tweeted twitter.com/#!/StackGameDev/status/502812635562516482
Source Link

Fast determination of whether objects are onscreen in 2D

So currently, I have this in each object's renderer's update method:

 float a = transform.position.x * Main.scale; float b = transform.position.y * Main.scale; float c = Camera.main.transform.position.x * Main.scale; float d = Camera.main.transform.position.y * Main.scale; onscreen = a + width - c > 0 && a - c < GameView.width && b + height - d > 0 && b - d < GameView.height; 

transform.position is a 2D vector containing the game engine's definition of where the object is - this is then multiplied by Main.scale to translate that coordinate into actual screen space Similarly, Camera.main.transform.position is the in-engine representation of where the main camera is, and this is also multiplied by Main.scale

The problem is, as my game is tile-based, thousands of these updates get called every frame, just to determine whether or not each object should be drawn - how can I improve this please?