mirror of
https://github.com/Nimac0/SDL_Minigame
synced 2026-01-12 09:03:42 +00:00
added new Map for tile-textures as they wont work with our current enum-class maps.
This commit is contained in:
parent
1a8a196e95
commit
ac217e931b
@ -23,7 +23,11 @@ class TextureManager
|
|||||||
SDL_Texture* loadTexture(Textures texture);
|
SDL_Texture* loadTexture(Textures texture);
|
||||||
static std::vector<SDL_Rect> splitSpriteSheet(SDL_Texture* spriteSheet, int width, int height, int spritesOnSheet);
|
static std::vector<SDL_Rect> splitSpriteSheet(SDL_Texture* spriteSheet, int width, int height, int spritesOnSheet);
|
||||||
static void draw(SDL_Renderer* renderer, SDL_Texture* texture, SDL_Rect src, SDL_Rect dest, bool flipped = false);
|
static void draw(SDL_Renderer* renderer, SDL_Texture* texture, SDL_Rect src, SDL_Rect dest, bool flipped = false);
|
||||||
|
|
||||||
|
SDL_Texture* loadMapTileTexture(const char* path);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Manager* manager;
|
Manager* manager;
|
||||||
std::map<Textures, SDL_Texture*> texture_cache;
|
std::map<Textures, SDL_Texture*> texture_cache;
|
||||||
|
std::map<std::string, SDL_Texture*> mapTile_texture_cache;
|
||||||
};
|
};
|
||||||
@ -104,7 +104,7 @@ void Map::loadTileLayer(const tmx::TileLayer& layer)
|
|||||||
|
|
||||||
tmx::Vector2i textureSize;
|
tmx::Vector2i textureSize;
|
||||||
SDL_QueryTexture(
|
SDL_QueryTexture(
|
||||||
VEGO_Game().textureManager->loadTexture(texturePath),
|
VEGO_Game().textureManager->loadMapTileTexture(texturePath),
|
||||||
nullptr,
|
nullptr,
|
||||||
nullptr,
|
nullptr,
|
||||||
&(textureSize.x),
|
&(textureSize.x),
|
||||||
@ -170,6 +170,7 @@ void Map::addTile(float x, float y, const tmx::Vector2u& mapTileSize, int u, int
|
|||||||
|
|
||||||
tile.addComponent<TransformComponent>(x, y, mapTileSize.x, mapTileSize.y, 1);
|
tile.addComponent<TransformComponent>(x, y, mapTileSize.x, mapTileSize.y, 1);
|
||||||
tile.addComponent<SpriteComponent>(texturePath.c_str(), v, u, zIndex); // why does uv need to be reversed?
|
tile.addComponent<SpriteComponent>(texturePath.c_str(), v, u, zIndex); // why does uv need to be reversed?
|
||||||
|
//TODO: also implement updated map stuff for this
|
||||||
|
|
||||||
if (hasCollision) {
|
if (hasCollision) {
|
||||||
// tag currently does not have a clear purposes, TODO: figure out appropriate tag name
|
// tag currently does not have a clear purposes, TODO: figure out appropriate tag name
|
||||||
|
|||||||
@ -3,12 +3,14 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <VEGO.h>
|
||||||
|
#include <linux/soundcard.h>
|
||||||
|
|
||||||
#include "GameInternal.h"
|
#include "GameInternal.h"
|
||||||
|
|
||||||
|
|
||||||
void TextureManager::addSingleTexture(Textures texture, const char* filePath) {
|
void TextureManager::addSingleTexture(Textures texture, const char* filePath) {
|
||||||
auto sdlTexture = IMG_LoadTexture(this->manager->getGame()->renderer, filePath);
|
auto sdlTexture = IMG_LoadTexture(VEGO_Game().renderer, filePath);
|
||||||
|
|
||||||
if (sdlTexture == nullptr)
|
if (sdlTexture == nullptr)
|
||||||
throw std::runtime_error(std::string("Couldn't load texture '") + filePath + "'");
|
throw std::runtime_error(std::string("Couldn't load texture '") + filePath + "'");
|
||||||
@ -38,4 +40,17 @@ void TextureManager::draw(SDL_Renderer* renderer, SDL_Texture* texture, SDL_Rect
|
|||||||
{
|
{
|
||||||
SDL_RendererFlip flip = flipped ? SDL_FLIP_HORIZONTAL : SDL_FLIP_NONE;
|
SDL_RendererFlip flip = flipped ? SDL_FLIP_HORIZONTAL : SDL_FLIP_NONE;
|
||||||
SDL_RenderCopyEx(renderer, texture, &src, &dest, 0, NULL, flip);
|
SDL_RenderCopyEx(renderer, texture, &src, &dest, 0, NULL, flip);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SDL_Texture* TextureManager::loadMapTileTexture(const char *path) {
|
||||||
|
|
||||||
|
//returns tile if it exists already
|
||||||
|
if(mapTile_texture_cache.contains(std::string(path)))
|
||||||
|
return mapTile_texture_cache.at(std::string(path));
|
||||||
|
|
||||||
|
auto newTexture = IMG_LoadTexture(VEGO_Game().renderer, path);
|
||||||
|
|
||||||
|
this->mapTile_texture_cache.emplace(std::string(path), newTexture);
|
||||||
|
|
||||||
|
return newTexture;
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user