commit d758429d
Improved SagoSprite to respect originx and originy
Changed files
| M | src/sago/SagoSprite.cpp before |
| M | src/saland.cpp before |
| M | src/saland/Game.cpp before |
| M | src/saland/model/placeables.hpp before |
diff --git a/src/sago/SagoSprite.cpp b/src/sago/SagoSprite.cpp
index a4070a7..5456ca4 100644
--- a/src/sago/SagoSprite.cpp
+++ b/src/sago/SagoSprite.cpp
@@ -71,8 +71,8 @@ void SagoSprite::DrawScaled(SDL_Renderer* target, Sint32 frameTime, int x, int y
SDL_Rect rect = data->imgCord;
rect.x+=rect.w*((frameTime/data->aniFrameTime)%data->aniFrames);
SDL_Rect pos = rect;
- pos.x = x;
- pos.y = y;
+ pos.x = x - this->data->origin.x;
+ pos.y = y - this->data->origin.y;
if (w > 0) {
pos.w = w;
}
@@ -90,8 +90,8 @@ void SagoSprite::Draw(SDL_Renderer* target, Sint32 frameTime, int x, int y, cons
rect.w = part.w;
rect.h = part.h;
SDL_Rect pos = rect;
- pos.x = x;
- pos.y = y;
+ pos.x = x - this->data->origin.x;
+ pos.y = y - this->data->origin.y;
SDL_RenderCopy(target, data->tex.get(), &rect, &pos);
}
diff --git a/src/saland.cpp b/src/saland.cpp
index 7467398..fe4c6b7 100644
--- a/src/saland.cpp
+++ b/src/saland.cpp
@@ -106,7 +106,7 @@ void runGame() {
TTF_Init();
Mix_Init(MIX_INIT_OGG);
- win = SDL_CreateWindow("Hello World", posX, posY, width, height, 0);
+ win = SDL_CreateWindow("Saland Adventures", posX, posY, width, height, 0);
globalData.screen = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED);
sago::SagoDataHolder holder(globalData.screen);
globalData.spriteHolder.reset(new sago::SagoSpriteHolder(holder));
diff --git a/src/saland/Game.cpp b/src/saland/Game.cpp
index c81bbe8..ca7eaf2 100644
--- a/src/saland/Game.cpp
+++ b/src/saland/Game.cpp
@@ -79,11 +79,15 @@ static void DrawHumanEntity(SDL_Renderer* target, sago::SagoSpriteHolder* sHolde
relativeAnimation = true;
relativeAnimationState = 1.0f-(entity->castTimeRemaining/entity->castTime);
}
- /*if (drawCollision) {
- sf::CircleShape circle(entity->Radius);
+ if (drawCollision || true) {
+ circleRGBA(target,
+ entity->X-offsetX, entity->Y-offsetY, entity->Radius,
+ 255, 255, 0, 255);
+ /*sf::CircleShape circle(entity->Radius);
circle.setPosition(entity->X-offsetX-16, entity->Y-offsetY-16);
target.draw(circle);
- }*/
+ * */
+ }
const sago::SagoSprite &mySprite = sHolder->GetSprite(entity->race + "_"+animation+"_"+std::string(1,entity->direction));
if (relativeAnimation) {
mySprite.DrawProgressive(target, relativeAnimationState, std::round(entity->X)-offsetX, std::round(entity->Y)-offsetY);
diff --git a/src/saland/model/placeables.hpp b/src/saland/model/placeables.hpp
index 5489e5e..76e064a 100644
--- a/src/saland/model/placeables.hpp
+++ b/src/saland/model/placeables.hpp
@@ -7,7 +7,7 @@ class Placeable {
public:
float X = 20.0;
float Y = 20.0;
- float Radius = 0.0;
+ float Radius = 16.0;
virtual bool isStatic() {return true; }
};