summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorStar Rauchenberger <fefferburbia@gmail.com>2021-07-05 10:07:32 -0400
committerStar Rauchenberger <fefferburbia@gmail.com>2021-07-05 10:07:32 -0400
commit132899d222f2c7d3542655b2332ed3574ffa9737 (patch)
tree4343a3bf439625767be6d61fe7b1282918f1b988 /src
parentcb32c362ce5db91e06dc8b281bcd02a4df2a1481 (diff)
downloadtanetane-132899d222f2c7d3542655b2332ed3574ffa9737.tar.gz
tanetane-132899d222f2c7d3542655b2332ed3574ffa9737.tar.bz2
tanetane-132899d222f2c7d3542655b2332ed3574ffa9737.zip
Added sprite opacity
Diffstat (limited to 'src')
-rw-r--r--src/renderer.cpp8
-rw-r--r--src/script_system.cpp3
-rw-r--r--src/sprite.h1
3 files changed, 9 insertions, 3 deletions
diff --git a/src/renderer.cpp b/src/renderer.cpp index b28e3cb..25c5669 100644 --- a/src/renderer.cpp +++ b/src/renderer.cpp
@@ -112,7 +112,9 @@ void Renderer::renderSprite(const Sprite& sprite) {
112 if (sprite.hasShadow) { 112 if (sprite.hasShadow) {
113 int shadowTexId = loadImageFromFile("../res/shadow.png"); 113 int shadowTexId = loadImageFromFile("../res/shadow.png");
114 const SDL_Rect shadowDest { sprite.loc.x() - 8, sprite.loc.y() - 8, 16, 8 }; 114 const SDL_Rect shadowDest { sprite.loc.x() - 8, sprite.loc.y() - 8, 16, 8 };
115 SDL_RenderCopy(ren_.get(), textures_.at(shadowTexId).get(), nullptr, &shadowDest); 115 SDL_Texture* shadowTex = textures_.at(shadowTexId).get();
116 SDL_SetTextureAlphaMod(shadowTex, sprite.opacity * 255);
117 SDL_RenderCopy(ren_.get(), shadowTex, nullptr, &shadowDest);
116 } 118 }
117 119
118 const SpriteFrame& frame = sprite.frames.at(sprite.animations.at(sprite.animationId).frameIndices.at(sprite.animationFrame)); 120 const SpriteFrame& frame = sprite.frames.at(sprite.animations.at(sprite.animationId).frameIndices.at(sprite.animationFrame));
@@ -121,7 +123,9 @@ void Renderer::renderSprite(const Sprite& sprite) {
121 if (sprite.bobbing) { 123 if (sprite.bobbing) {
122 dest.y -= sprite.bobAmount; 124 dest.y -= sprite.bobAmount;
123 } 125 }
124 SDL_RenderCopy(ren_.get(), textures_.at(loadImageFromFile(sprite.spritesheet)).get(), &src, &dest); 126 SDL_Texture* textureToRender = textures_.at(loadImageFromFile(sprite.spritesheet)).get();
127 SDL_SetTextureAlphaMod(textureToRender, sprite.opacity * 255);
128 SDL_RenderCopy(ren_.get(), textureToRender, &src, &dest);
125 } 129 }
126} 130}
127 131
diff --git a/src/script_system.cpp b/src/script_system.cpp index 7889148..56a6012 100644 --- a/src/script_system.cpp +++ b/src/script_system.cpp
@@ -55,7 +55,8 @@ ScriptSystem::ScriptSystem(Game& game) : game_(game) {
55 "solid", &Sprite::solid, 55 "solid", &Sprite::solid,
56 "behaviourType", &Sprite::behaviourType, 56 "behaviourType", &Sprite::behaviourType,
57 "followSpriteId", &Sprite::followSpriteId, 57 "followSpriteId", &Sprite::followSpriteId,
58 "interactionScript", &Sprite::interactionScript); 58 "interactionScript", &Sprite::interactionScript,
59 "opacity", &Sprite::opacity);
59 60
60 engine_.new_usertype<MessageSystem>( 61 engine_.new_usertype<MessageSystem>(
61 "message", 62 "message",
diff --git a/src/sprite.h b/src/sprite.h index 413c20d..782ae14 100644 --- a/src/sprite.h +++ b/src/sprite.h
@@ -100,6 +100,7 @@ public:
100 int bobAmount = 0; 100 int bobAmount = 0;
101 bool bobbingDown = false; 101 bool bobbingDown = false;
102 int animSlowdownProgress = 0; 102 int animSlowdownProgress = 0;
103 double opacity = 1.0;
103 104
104 // Animation (controls) 105 // Animation (controls)
105 bool normallyHasShadow = false; 106 bool normallyHasShadow = false;