diff options
author | Star Rauchenberger <fefferburbia@gmail.com> | 2021-07-05 10:07:32 -0400 |
---|---|---|
committer | Star Rauchenberger <fefferburbia@gmail.com> | 2021-07-05 10:07:32 -0400 |
commit | 132899d222f2c7d3542655b2332ed3574ffa9737 (patch) | |
tree | 4343a3bf439625767be6d61fe7b1282918f1b988 | |
parent | cb32c362ce5db91e06dc8b281bcd02a4df2a1481 (diff) | |
download | tanetane-132899d222f2c7d3542655b2332ed3574ffa9737.tar.gz tanetane-132899d222f2c7d3542655b2332ed3574ffa9737.tar.bz2 tanetane-132899d222f2c7d3542655b2332ed3574ffa9737.zip |
Added sprite opacity
-rw-r--r-- | res/scripts/common.lua | 9 | ||||
-rw-r--r-- | src/renderer.cpp | 8 | ||||
-rw-r--r-- | src/script_system.cpp | 3 | ||||
-rw-r--r-- | src/sprite.h | 1 |
4 files changed, 18 insertions, 3 deletions
diff --git a/res/scripts/common.lua b/res/scripts/common.lua index 1d4879f..e355a32 100644 --- a/res/scripts/common.lua +++ b/res/scripts/common.lua | |||
@@ -414,6 +414,15 @@ function SetAnimationSlowdown(spriteName, amount) | |||
414 | sprite.animSlowdown = amount | 414 | sprite.animSlowdown = amount |
415 | end | 415 | end |
416 | 416 | ||
417 | --- Sets the opacity of the sprite when it is rendered. | ||
418 | -- @param spriteName the alias of the sprite to modify | ||
419 | -- @param amount a value from 0.0 to 1.0 | ||
420 | function SetOpacity(spriteName, amount) | ||
421 | local spriteId = getSpriteByAlias(spriteName) | ||
422 | local sprite = getSprite(spriteId) | ||
423 | sprite.opacity = amount | ||
424 | end | ||
425 | |||
417 | --- Sets the enclosure zone for a sprite. | 426 | --- Sets the enclosure zone for a sprite. |
418 | -- The sprite will be prevented from exiting the area defined by that zone. | 427 | -- The sprite will be prevented from exiting the area defined by that zone. |
419 | function AddEnclosureZone(spriteName, zone) | 428 | function AddEnclosureZone(spriteName, zone) |
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; |