fixed sprite loading
This commit is contained in:
+4
-4
@@ -25,12 +25,12 @@ int main() {
|
|||||||
|
|
||||||
SetTargetFPS(60);
|
SetTargetFPS(60);
|
||||||
|
|
||||||
GenDefaultTexture();
|
Texture Texturemissing = GenDefaultTexture();
|
||||||
|
|
||||||
raylib::Rectangle playerrect{screenWidth / 2.0f, screenHeight / 2.0f,64,64};
|
raylib::Rectangle playerrect{screenWidth / 2.0f, screenHeight / 2.0f,64,64};
|
||||||
Entity player{1, playerrect, "MainPlayer", 100, 100};
|
Entity player{1, playerrect, "MainPlayer", 100, 100};
|
||||||
player.controller = PlayerController;
|
player.controller = PlayerController;
|
||||||
player.spriteid = 1;
|
player.spriteid = 0;
|
||||||
|
|
||||||
entityTextures.LoadImage("./src/assets/playersprite.png");
|
entityTextures.LoadImage("./src/assets/playersprite.png");
|
||||||
tileTextures.LoadImage("./src/assets/BasicTile.png");
|
tileTextures.LoadImage("./src/assets/BasicTile.png");
|
||||||
@@ -52,13 +52,13 @@ int main() {
|
|||||||
|
|
||||||
BeginMode2D(camera);
|
BeginMode2D(camera);
|
||||||
|
|
||||||
camera.target = { player.rect.x, player.rect.y };
|
camera.target = { player.rect.x + player.rect.width / 2.0f, player.rect.y + player.rect.height / 2.0f};
|
||||||
|
|
||||||
if (IsKeyDown(KEY_Q)) camera.zoom += 0.1f;
|
if (IsKeyDown(KEY_Q)) camera.zoom += 0.1f;
|
||||||
|
|
||||||
DrawText("Middle", 190, 200, 20, WHITE);
|
DrawText("Middle", 190, 200, 20, WHITE);
|
||||||
|
|
||||||
Texture bg = tileTextures.GetTexture(1);
|
Texture bg = tileTextures.GetTexture(0);
|
||||||
|
|
||||||
// Infinite Background
|
// Infinite Background
|
||||||
int bh = bg.height;
|
int bh = bg.height;
|
||||||
|
|||||||
@@ -6,14 +6,15 @@ using namespace std;
|
|||||||
|
|
||||||
typedef int ID;
|
typedef int ID;
|
||||||
|
|
||||||
|
Texture defaultTexture;
|
||||||
|
|
||||||
TextureAtlas::TextureAtlas (){
|
TextureAtlas::TextureAtlas (){
|
||||||
atlas.clear();
|
atlas.clear();
|
||||||
atlas.push_back(defaultTexture);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Texture TextureAtlas::GetTexture(ID id) {
|
Texture TextureAtlas::GetTexture(ID id) {
|
||||||
if (atlas.size() <= id) {
|
if (atlas.size() <= id) {
|
||||||
return atlas[0];
|
return defaultTexture;
|
||||||
}
|
}
|
||||||
return atlas[id];
|
return atlas[id];
|
||||||
}
|
}
|
||||||
@@ -26,15 +27,15 @@ void TextureAtlas::AddTexture(Texture texture){
|
|||||||
atlas.push_back(texture);
|
atlas.push_back(texture);
|
||||||
}
|
}
|
||||||
|
|
||||||
Texture defaultTexture;
|
|
||||||
TextureAtlas entityTextures;
|
TextureAtlas entityTextures;
|
||||||
TextureAtlas backgroundTextures;
|
TextureAtlas backgroundTextures;
|
||||||
TextureAtlas tileTextures;
|
TextureAtlas tileTextures;
|
||||||
|
|
||||||
|
|
||||||
void GenDefaultTexture(){
|
Texture GenDefaultTexture(){
|
||||||
Image img = GenImageChecked(64, 64, 16, 16, PURPLE, BLACK);
|
Image img = GenImageChecked(64, 64, 32, 32, PURPLE, BLACK);
|
||||||
defaultTexture = LoadTextureFromImage(img);
|
defaultTexture = LoadTextureFromImage(img);
|
||||||
UnloadImage(img);
|
UnloadImage(img);
|
||||||
|
return defaultTexture;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,6 +22,6 @@ extern TextureAtlas entityTextures;
|
|||||||
extern TextureAtlas backgroundTextures;
|
extern TextureAtlas backgroundTextures;
|
||||||
extern TextureAtlas tileTextures;
|
extern TextureAtlas tileTextures;
|
||||||
|
|
||||||
void GenDefaultTexture();
|
Texture GenDefaultTexture();
|
||||||
|
|
||||||
#endif // !TEXTURES_HPP
|
#endif // !TEXTURES_HPP
|
||||||
|
|||||||
Reference in New Issue
Block a user