Code: Select all
function Animation:draw(image, x, y, r, sx, sy, ox, oy, ...)
local frame = self.frames[self.position]
if self.flippedH or self.flippedV then
r,sx,sy,ox,oy = r or 0, sx or 1, sy or 1, ox or 0, oy or 0
local _,_,w,h = frame:getViewport()
if self.flippedH then
sx = sx * -1
ox = w - ox
end
if self.flippedV then
sy = sy * -1
oy = h - oy
end
end
love.graphics.drawq(sheet1, frame, x, y, r, sx, sy, ox, oy, kx, ky ) --Line 273
end
-----------------------------------------------------------
local anim8 = {
newGrid = newGrid,
newAnimation = newAnimation
}
return anim8
Code: Select all
local anim8 = require 'anim8'
local image, animation
function love.load()
love.physics.setMeter(60)
world = love.physics.newWorld(0, 9.81*64, true)
image = love.graphics.newImage("sheet1.png")
local g = anim8.newGrid(32, 32, image:getWidth(), image: getHeight())
animation = anim8.newAnimation('loop', g('1,1-8'), 0.1)
animation:draw(sheet1, 100, 200)
objects = {} --Creates table "objects"
--The ground
objects.ground = {}
objects.ground.body = love.physics.newBody(world, 650/2, 650-50/2) --2nd & 3rd parameter are used to anchor object.ground to fit in correct place
objects.ground.shape = love.physics.newRectangleShape(650, 50) --Width = 650, Height = 50
objects.ground.fixture = love.physics.newFixture(objects.ground.body, objects.ground.shape) --attach shape to body
--Ball
objects.ball = {}
objects.ball.body = love.physics.newBody(world, 650/2, 650/2, "dynamic") -- Centering of the ball, made to be dynamic to move.
objects.ball.shape = love.physics.newCircleShape(20) -- Radius = 20
objects.ball.fixture = love.physics.newFixture(objects.ball.body, objects.ball.shape, 1)
objects.ball.fixture:setRestitution(0.9) --Adds le bounce
--Blocks
objects.block1 = {}
objects.block1.body = love.physics.newBody(world, 200, 550, "dynamic")
objects.block1.shape = love.physics.newRectangleShape(0, 0, 50, 100)
objects.block1.fixture = love.physics.newFixture(objects.block1.body, objects.block1.shape, 5)
objects.block2 = {}
objects.block2.body = love.physics.newBody(world, 200, 400, "dynamic")
objects.block2.shape = love.physics.newRectangleShape(0, 0, 100, 50)
objects.block2.fixture = love.physics.newFixture(objects.block2.body, objects.block2.shape, 2)
love.graphics.setBackgroundColor(101, 64, 251) --Blue background!
love.graphics.setMode(650, 650, false, true, 0) --set the window dimensions to 650 by 650 with no fullscreen, vsync on, and no antialiasing
end
function love.update(dt)
animation:update(dt) -- enables anim8
world:update(dt) --this puts the world into motion
if love.keyboard.isDown("right") then --press the right arrow key to push the ball to the right
objects.ball.body:applyForce(400, 0)
elseif love.keyboard.isDown("left") then --press the left arrow key to push the ball to the left
objects.ball.body:applyForce(-400, 0)
elseif love.keyboard.isDown("up") then --press the up arrow key to set the ball in the air
objects.ball.body:setPosition(650/2, 650/2)
end
end
function love.draw()
love.graphics.setCaption("Mars")
love.graphics.setColor(72, 160, 14) -- set the drawing color to green for the ground
love.graphics.polygon("fill", objects.ground.body:getWorldPoints(objects.ground.shape:getPoints())) -- draw a "filled in" polygon using the ground's coordinates
love.graphics.setColor(193, 47, 14) --set the drawing color to red for the ball
love.graphics.circle("fill", objects.ball.body:getX(), objects.ball.body:getY(), objects.ball.shape:getRadius())
love.graphics.setColor(50, 50, 50) -- set the drawing color to grey for the blocks
love.graphics.polygon("fill", objects.block1.body:getWorldPoints(objects.block1.shape:getPoints()))
love.graphics.polygon("fill", objects.block2.body:getWorldPoints(objects.block2.shape:getPoints()))
end
Error
anim8.lua:273: incorrect parameter type: expected userdata.
Traceback
[C]: in function 'drawq'
anim8.lua:273:in function 'draw'
main.lua.11: in function 'load
[C]: in function 'xpcall'