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