its acting like I am using..
love.graphics.draw( drawable, x, y, r, sx, sy, ox, oy, kx, ky )
instead of..
love.graphics.draw( texture, quad, x, y, r, sx, sy, ox, oy, kx, ky )
where it thinks i am passing y as r
here is my code.
Code: Select all
local gfx =
{
image = nil,
imageW = 0,
imageH = 0,
quad = nil,
quadW = 0,
quadH = 0
}
local palette =
{
{000, 000, 000}, {032, 051, 123}, {126, 037, 083}, {000, 131, 049},
{171, 082, 054}, {069, 069, 069}, {194, 195, 199}, {255, 241, 232},
{255, 000, 077}, {255, 163, 000}, {255, 231, 039}, {000, 226, 050},
{041, 173, 255}, {131, 118, 156}, {255, 119, 168}, {255, 204, 170}
}
local shader0 =
[[
extern vec4 oldColor;
extern vec4 newColor;
vec4 effect( vec4 color, Image texture, vec2 texture_coords, vec2 screen_coords ){
vec4 pixel = Texel(texture, texture_coords );//This is the current pixel color
if(pixel == oldColor) return newColor * oldColor;
return pixel * oldColor;
}
]]
function gfx:new(image)
self.image = love.graphics.newImage(image);
self.imageW = self.image:getWidth()
self.imageH = self.image:getHeight()
self.quad = love.graphics.newQuad(0,0,8,8,self.image:getDimensions())
self.quadW = 8
self.quadH = 8
self.image:setFilter("nearest", "nearest" )
end
function gfx:pal(oldColor, newColor)
local shader = love.graphics.newShader(shader0)
shader:sendColor("oldColor", unpack(palette[oldColor]))
shader:sendColor("newColor", unpack(palette[newColor]))
love.graphics.setShader(shader)
end
function gfx:pal()
love.graphics.setShader()
end
function gfx.clip(x, y, w, h)
love.graphics.setScissor(x, y, w, h)
end
function gfx.clip()
love.graphics.setScissor()
end
function gfx:tile(x,y,w,h,tile)
local rows = math.floor(self.imageW / self.quadW) -- rows the tileset has
for ly=0, h do
for lx=0, w do
local di = (tile + lx + (ly * rows)) -- draw index
local dx = (di % rows) * self.quadW -- draw x
local dy = (di / rows) * self.quadH -- draw y
self.quad:setViewport(dx,dy,8,8)
love.graphics.draw(self.image, self.quad, x+(lx*8), y+(ly*8))
end
end
end
function gfx:line(x1,y1,x2,y2,color)
love.graphics.setColor(palette[color])
love.graphics.line(x1,y1,x2,y2)
love.graphics.setColor()
end
function gfx:rect(x1,y1,x2,y2,color, fill)
love.graphics.setColor(palette[color])
love.graphics.rectangle(fill == true and "fill" or "line", x1, y1, x2, y2)
love.graphics.setColor()
end
function gfx:circ(x,y,xr,yr,color, fill)
love.graphics.setColor(palette[color])
love.graphics.ellipse(fill == true and "fill" or "line", x, y, xr, yr)
love.graphics.setColor()
end
return gfx
Code: Select all
local gfx = require("lib.gfx")
local canvas = love.graphics.newCanvas(128, 128);
local canvasScale = 4
canvas:setFilter("nearest", "nearest")
gfx:new("gfx/bank0.png")
function love.draw()
love.graphics.setCanvas(canvas)
gfx:tile(0,0,2,2,0)
love.graphics.setCanvas()
love.graphics.draw(canvas, 0, 0, 0, 4, 4)
end