Only render objects on screen
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
#include "entity_factory.h"
|
||||
#include "game_state.h"
|
||||
#include "map_layers.h"
|
||||
#include "utils.h"
|
||||
|
||||
bool initGameObjectsLayer(BzTileMap *map, BzTileObjectGroup *objectGroup) {
|
||||
Game *game = ecs_singleton_get_mut(ECS, Game);
|
||||
@@ -186,6 +187,10 @@ void terrainRender(BzTileMap *map, BzTileLayer *layer) {
|
||||
static f32 elapsed = 0.0f;
|
||||
elapsed += GetFrameTime();
|
||||
|
||||
const Game *game = ecs_singleton_get(ECS, Game);
|
||||
Camera2D camera = game->camera;
|
||||
Rectangle camBounds = getCameraBounds(camera);
|
||||
|
||||
for (i32 y = 0; y < layer->height; y++) {
|
||||
for (i32 x = 0; x < layer->width; x++) {
|
||||
BzTile tile = bzTileLayerGetTile(layer, x, y);
|
||||
@@ -198,7 +203,14 @@ void terrainRender(BzTileMap *map, BzTileLayer *layer) {
|
||||
tile = terrainGetAnimationFrame(tile, frameIdx).frame;
|
||||
}
|
||||
Rectangle rec = bzTilesetGetTileRegion(tileset, tile);
|
||||
DrawTextureRec(tileset->tiles, rec, drawPos, WHITE);
|
||||
Rectangle bounds = {
|
||||
drawPos.x,
|
||||
drawPos.y,
|
||||
tileset->tileWidth,
|
||||
tileset->tileHeight
|
||||
};
|
||||
if (CheckCollisionRecs(camBounds, bounds))
|
||||
DrawTextureRec(tileset->tiles, rec, drawPos, WHITE);
|
||||
}
|
||||
drawPos.x += (float) tileset->tileWidth;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user