Code: Select all
[Error] AnimatedSprite.lua:100: bad argument #2 to 'draw' (Quad expected, got nil)
Code: Select all
require "AnimatedSprite"
require "lovedebug"
love.graphics.setDefaultFilter("nearest", "nearest")
function testMap(x, y)
if map[(player.grid_y / 32) + y][(player.grid_x / 32) + x] == 1 then
return false
end
return true
end
function love.load()
archer_f = GetInstance("unit_scripts/archer_f_sprite.lua")
player = {
grid_x = 256,
grid_y = 256,
actual_x = 200,
actual_y = 200,
sprite = archer_f,
speed = 15,
idle_anim = 1,
horz_anim_l = 2,
horz_anim_r = 3,
down_anim = 4,
up_anim = 5,
select_anim = 6
}
map = {
{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
{ 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 },
{ 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1 },
{ 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1 },
{ 1, 1, 0, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1 },
{ 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 },
{ 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
{ 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
{ 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
{ 1, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 1 },
{ 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 },
{ 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 },
{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }
}
end
function love.update(dt)
player.actual_y = player.actual_y - ((player.actual_y - player.grid_y) * player.speed * dt)
player.actual_x = player.actual_x - ((player.actual_x - player.grid_x) * player.speed * dt)
UpdateInstance(player.sprite, dt)
end
function love.draw()
DrawInstance(player.sprite, player.actual_x, player.actual_y)
-- draws the wire map
for y=1, #map do
for x=1, #map[y] do
if map[y][x] == 1 then
love.graphics.rectangle("line", x * 32, y * 32, 32, 32)
end
end
end
end
function love.keypressed(key)
-- after each movement need to run timer and then switch to idle animation
if key == "up" then
if testMap(0, -1) then
player.grid_y = player.grid_y - 32
player.sprite.curr_anim = player.sprite.sprite.animations_names[player.up_anim]
end
elseif key == "down" then
if testMap(0, 1) then
player.grid_y = player.grid_y + 32
player.sprite.curr_anim = player.sprite.sprite.animations_names[player.down_anim]
end
elseif key == "left" then
if testMap(-1, 0) then
player.grid_x = player.grid_x - 32
player.sprite.curr_anim = player.sprite.sprite.animations_names[player.horz_anim_l]
end
elseif key == "right" then
if testMap(1, 0) then
player.grid_x = player.grid_x + 32
player.sprite.curr_anim = player.sprite.sprite.animations_names[player.horz_anim_r]
end
elseif key == "space" then
player.sprite.curr_anim = player.sprite.sprite.animations_names[player.select_anim]
end
end
Code: Select all
function DrawInstance(spr, x, y)
love.graphics.draw(
image_bank[spr.sprite.sprite_sheet],
spr.sprite.animations[spr.curr_anim][spr.curr_frame], -- this argument is failing sometimes
x,
y,
spr.rotation,
spr.size_scale,
spr.size_scale,
flip_h,
flip_v
)
end -- DrawInstance