modules/assets: add a basic texture object
This commit is contained in:
parent
aa8daedc82
commit
fa7b265618
2 changed files with 65 additions and 2 deletions
|
@ -26,6 +26,8 @@ local Assets = Object:extend()
|
||||||
|
|
||||||
local cwd = (...):gsub('%.init$', '') .. "."
|
local cwd = (...):gsub('%.init$', '') .. "."
|
||||||
|
|
||||||
|
local Texture = require(cwd .. "texture")
|
||||||
|
|
||||||
local Sprite = require(cwd .. "sprites")
|
local Sprite = require(cwd .. "sprites")
|
||||||
local Font = require(cwd .. "fonts")
|
local Font = require(cwd .. "fonts")
|
||||||
local ImageFont = require(cwd .. "imagefonts")
|
local ImageFont = require(cwd .. "imagefonts")
|
||||||
|
@ -123,11 +125,11 @@ end
|
||||||
-- Background --
|
-- Background --
|
||||||
|
|
||||||
function Assets:addImage(name, filename)
|
function Assets:addImage(name, filename)
|
||||||
self.images[name] = love.graphics.newImage(filename)
|
self.images[name] = Texture(filename)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Assets:drawImage(name, x, y, r, sx, sy, ox, oy, kx, ky)
|
function Assets:drawImage(name, x, y, r, sx, sy, ox, oy, kx, ky)
|
||||||
love.graphics.draw(self.images[name], x, y, r, sx, sy, ox, oy, kx, ky)
|
self.images[name]:draw(x, y, r, sx, sy, ox, oy, kx, ky)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Images --
|
-- Images --
|
||||||
|
|
61
gamecore/modules/assets/texture.lua
Normal file
61
gamecore/modules/assets/texture.lua
Normal file
|
@ -0,0 +1,61 @@
|
||||||
|
-- assets/texture :: the texture object, essentially used to be able to draw easily
|
||||||
|
-- the mask of the texture (used for stuff like flashing sprite, etc)
|
||||||
|
|
||||||
|
--[[
|
||||||
|
Copyright © 2019 Kazhnuz
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
|
the Software without restriction, including without limitation the rights to
|
||||||
|
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||||
|
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||||
|
subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||||
|
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||||
|
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||||
|
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||||
|
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
]]
|
||||||
|
|
||||||
|
|
||||||
|
local Texture = Object:extend()
|
||||||
|
|
||||||
|
local function getMask(x, y, r, g, b, a)
|
||||||
|
-- template for defining your own pixel mapping function
|
||||||
|
-- perform computations giving the new values for r, g, b and a
|
||||||
|
-- ...
|
||||||
|
return 1, 1, 1, a
|
||||||
|
end
|
||||||
|
|
||||||
|
function Texture:new(filename)
|
||||||
|
self.imageData = love.image.newImageData(filename)
|
||||||
|
|
||||||
|
local maskData = self.imageData:clone()
|
||||||
|
maskData:mapPixel( getMask )
|
||||||
|
|
||||||
|
self.image = love.graphics.newImage( self.imageData )
|
||||||
|
self.mask = love.graphics.newImage( maskData )
|
||||||
|
end
|
||||||
|
|
||||||
|
function Texture:draw(x, y, r, sx, sy, ox, oy, kx, ky)
|
||||||
|
love.graphics.draw(self.image, x, y, r, sx, sy, ox, oy, kx, ky)
|
||||||
|
end
|
||||||
|
|
||||||
|
function Texture:drawQuad(quad, x, y, r, sx, sy, ox, oy, kx, ky)
|
||||||
|
love.graphics.draw(self.image, quad, x, y, r, sx, sy, ox, oy, kx, ky)
|
||||||
|
end
|
||||||
|
|
||||||
|
function Texture:drawMask(x, y, r, sx, sy, ox, oy, kx, ky)
|
||||||
|
love.graphics.draw(self.mask, x, y, r, sx, sy, ox, oy, kx, ky)
|
||||||
|
end
|
||||||
|
|
||||||
|
function Texture:drawMaskQuad(quad, x, y, r, sx, sy, ox, oy, kx, ky)
|
||||||
|
love.graphics.draw(self.mask, quad, x, y, r, sx, sy, ox, oy, kx, ky)
|
||||||
|
end
|
||||||
|
|
||||||
|
return Texture
|
Loading…
Reference in a new issue