mirror of
https://github.com/Relintai/sfw.git
synced 2024-12-20 21:06:49 +01:00
Fixed TileMap.
This commit is contained in:
parent
d9c286e1fe
commit
9af2c28ac7
@ -105,7 +105,7 @@ void GameScene::render() {
|
|||||||
|
|
||||||
camera->bind();
|
camera->bind();
|
||||||
|
|
||||||
//tile_map->render();
|
|
||||||
//sprite->render();
|
//sprite->render();
|
||||||
//material->bind();
|
//material->bind();
|
||||||
//color_material->bind();
|
//color_material->bind();
|
||||||
@ -118,6 +118,7 @@ void GameScene::render() {
|
|||||||
|
|
||||||
camera_2d->bind();
|
camera_2d->bind();
|
||||||
sprite->render();
|
sprite->render();
|
||||||
|
tile_map->render();
|
||||||
}
|
}
|
||||||
|
|
||||||
GameScene::GameScene() {
|
GameScene::GameScene() {
|
||||||
@ -153,11 +154,11 @@ GameScene::GameScene() {
|
|||||||
//sprite->region_width = 1.0 / 16.0;
|
//sprite->region_width = 1.0 / 16.0;
|
||||||
//sprite->region_height = 1.0 / 16.0;
|
//sprite->region_height = 1.0 / 16.0;
|
||||||
sprite->update_mesh();
|
sprite->update_mesh();
|
||||||
/*
|
|
||||||
tile_map = new TileMap();
|
tile_map = new TileMap();
|
||||||
tile_map->material = material;
|
tile_map->material = material;
|
||||||
tile_map->atlas_size_x = 16;
|
tile_map->atlas_size_x = 2;
|
||||||
tile_map->atlas_size_y = 16;
|
tile_map->atlas_size_y = 2;
|
||||||
|
|
||||||
tile_map->allocate_data();
|
tile_map->allocate_data();
|
||||||
|
|
||||||
@ -172,7 +173,10 @@ GameScene::GameScene() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
tile_map->build_mesh();
|
tile_map->build_mesh();
|
||||||
*/
|
|
||||||
|
tile_map->transform.scale(Vector2(32, 32));
|
||||||
|
tile_map->transform.set_origin(Vector2(500, 500));
|
||||||
|
|
||||||
|
|
||||||
camera = new PerspectiveCamera();
|
camera = new PerspectiveCamera();
|
||||||
//camera->width = 2;
|
//camera->width = 2;
|
||||||
@ -243,17 +247,15 @@ GameScene::GameScene() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
GameScene::~GameScene() {
|
GameScene::~GameScene() {
|
||||||
/*
|
memdelete(tile_map);
|
||||||
delete tile_map;
|
|
||||||
*/
|
|
||||||
memdelete(camera);
|
|
||||||
//memdelete(texture);
|
|
||||||
//memdelete(material);
|
|
||||||
|
|
||||||
//memdelete(sprite);
|
memdelete(camera);
|
||||||
|
memdelete(texture);
|
||||||
|
|
||||||
|
memdelete(sprite);
|
||||||
|
|
||||||
memdelete(camera);
|
memdelete(camera);
|
||||||
memdelete(mesh);
|
memdelete(mesh);
|
||||||
//memdelete(material);
|
memdelete(material);
|
||||||
memdelete(color_material);
|
memdelete(color_material);
|
||||||
}
|
}
|
||||||
|
10
game_scene.h
10
game_scene.h
@ -3,15 +3,7 @@
|
|||||||
|
|
||||||
#include "scene.h"
|
#include "scene.h"
|
||||||
|
|
||||||
/*
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#include "texture.h"
|
|
||||||
#include "texture_material.h"
|
|
||||||
#include "tile_map.h"
|
#include "tile_map.h"
|
||||||
*/
|
|
||||||
|
|
||||||
#include "mesh_instance.h"
|
#include "mesh_instance.h"
|
||||||
#include "camera.h"
|
#include "camera.h"
|
||||||
#include "camera_2d.h"
|
#include "camera_2d.h"
|
||||||
@ -42,7 +34,7 @@ public:
|
|||||||
TextureMaterial2D *material;
|
TextureMaterial2D *material;
|
||||||
|
|
||||||
Camera2D *camera_2d;
|
Camera2D *camera_2d;
|
||||||
//TileMap *tile_map;
|
TileMap *tile_map;
|
||||||
Sprite *sprite;
|
Sprite *sprite;
|
||||||
|
|
||||||
Camera *camera;
|
Camera *camera;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#include "tile_map.h"
|
#include "tile_map.h"
|
||||||
|
|
||||||
#include "camera.h"
|
#include "camera_2d.h"
|
||||||
|
|
||||||
void TileMap::build_mesh() {
|
void TileMap::build_mesh() {
|
||||||
if (!mesh) {
|
if (!mesh) {
|
||||||
@ -98,26 +98,25 @@ void TileMap::set_data(const int x, const int y, const uint8_t value) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void TileMap::render() {
|
void TileMap::render() {
|
||||||
if (!mesh)
|
if (!mesh)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Transform mat_orig = Camera::current_camera->model_view_matrix;
|
Transform2D mat_orig = Camera2D::current_camera->model_view_matrix;
|
||||||
|
|
||||||
//Camera::current_camera->model_view_matrix = glm::translate(Camera::current_camera->model_view_matrix, glm::vec3(position.x, position.y, 0));
|
|
||||||
|
|
||||||
//Camera::current_camera->model_view_matrix = glm::rotate(Camera::current_camera->model_view_matrix, rotation, glm::vec3(0, 0, 1));
|
Camera2D::current_camera->model_view_matrix *= transform;
|
||||||
|
|
||||||
//Camera::current_camera->model_view_matrix = glm::scale(Camera::current_camera->model_view_matrix, glm::vec3(scale.x, scale.y, 0));
|
if (material) {
|
||||||
|
|
||||||
if (material)
|
|
||||||
material->bind();
|
material->bind();
|
||||||
|
}
|
||||||
|
|
||||||
mesh->render();
|
mesh->render();
|
||||||
|
|
||||||
Camera::current_camera->model_view_matrix = mat_orig;
|
Camera2D::current_camera->model_view_matrix = mat_orig;
|
||||||
}
|
}
|
||||||
|
|
||||||
TileMap::TileMap() : Object2D() {
|
TileMap::TileMap() :
|
||||||
|
Object2D() {
|
||||||
|
|
||||||
data = nullptr;
|
data = nullptr;
|
||||||
size_x = 16;
|
size_x = 16;
|
||||||
size_y = 16;
|
size_y = 16;
|
||||||
@ -129,6 +128,7 @@ TileMap::TileMap() : Object2D() {
|
|||||||
material = nullptr;
|
material = nullptr;
|
||||||
}
|
}
|
||||||
TileMap::~TileMap() {
|
TileMap::~TileMap() {
|
||||||
if (data)
|
if (data) {
|
||||||
delete[] data;
|
delete[] data;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user