-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fade effect, fixing a minor physics bug
- Loading branch information
Showing
6 changed files
with
95 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
require("sprite") | ||
|
||
local TEXTURE_PATH_FADE = "res/fader.png" | ||
local FADE_TIME = 0.75 | ||
|
||
FadeEffect = Sprite:new({ | ||
reversed = false, | ||
enabled = false, | ||
startTime = nil, | ||
}) | ||
|
||
function FadeEffect.preload() | ||
FadeEffect:loadTexture(TEXTURE_PATH_FADE) | ||
end | ||
|
||
function FadeEffect.free() | ||
FadeEffect.texture = nil | ||
end | ||
|
||
function FadeEffect:new(o, reversed) | ||
o = o or Sprite:new(o) | ||
setmetatable(o, self) | ||
self.__index = self | ||
|
||
o.reversed = reversed or false | ||
return o | ||
end | ||
|
||
function FadeEffect:draw() | ||
if self.enabled then | ||
-- Fade sprite | ||
local progress = math.min(1, (love.timer.getTime() - self.startTime) / FADE_TIME) | ||
|
||
if self.reversed then progress = 1 - progress end | ||
|
||
self.screenPos.x = progress * (800 + self.spriteSize.w) - self.spriteSize.w | ||
Sprite.draw(self) | ||
|
||
love.graphics.setColor(0,0,0) | ||
love.graphics.rectangle("fill", 0, 0, self.screenPos.x, 600) | ||
end | ||
end | ||
|
||
function FadeEffect:update() | ||
Sprite.update(self) | ||
end | ||
|
||
function FadeEffect:start() | ||
self.enabled = true | ||
self.startTime = love.timer.getTime() | ||
end | ||
|
||
function FadeEffect:reset() | ||
self.enabled = false | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters