Page 1 of 2
Problems with quads, and how they work...
Posted: Wed Aug 21, 2013 5:40 pm
by FatalMarshmallow
I've once again searched through tutorials and forums alike for an answer and my search has turned up blank. I'm trying to make this plane appear to rotate when a key is pressed, but not using orientation, as that doesn't give the desired effect.
I'm sure the answer lies with quads, I just don't know where.
Any help is appreciated.
Re: Problems with quads, and how they work...
Posted: Wed Aug 21, 2013 6:14 pm
by raidho36
Well first off your whole thing doesn't run. For so many reasons. First one is that you attempt to assign a table to a number constant, which is impossible operation. Read the Programming in Lua book for that (available online). Second, you apply arguments in wrong order. First two are X and Y, and rotation (R) would be third. Oh and drawq would accept a quad as a second argument (shifting all other arguments by one to the right). Refer to the LÖVE manual available at the wiki section.
Also, whereas you change X and Y by values amplified by DT, you don't do so for rotation. And, given that rotation angles are in radians rather than in degrees (1 rad ≈ 57.2°) your rotation will go really fast.
Code: Select all
local a1 = love.graphics.newQuad(0, 0, 32, 32, 160, 64)
local a2 = love.graphics.newQuad(32, 0, 32, 32, 160, 64)
local a3 = love.graphics.newQuad(64, 0, 32, 32, 160, 64)
local r, x, y, speed, Plane = 0, 0, 0, 0, 0
function love.load()
x = 50
y = 50
speed = 200
Plane = love.graphics.newImage("Plane.png")
end
function love.update(dt)
if love.keyboard.isDown("right") then
x = x + (speed * dt)
end
if love.keyboard.isDown("left") then
x = x - (speed * dt)
end
if love.keyboard.isDown("down") then
y = y + (speed * dt)
end
if love.keyboard.isDown("up") then
y = y - (speed * dt)
end
if love.keyboard.isDown("r") then
r = r + dt
end
end
function love.draw()
love.graphics.drawq(Plane, a1, x, y, r)
end
Re: Problems with quads, and how they work...
Posted: Wed Aug 21, 2013 6:17 pm
by vladgalay
Tried to fix your code. If something is wrong with my variant of code, feel free to tell =)
Code: Select all
a = { }
a[1] = love.graphics.newQuad(0, 0, 32, 32, 160, 64)
a[2] = love.graphics.newQuad(32, 0, 32, 32, 160, 64)
a[3] = love.graphics.newQuad(64, 0, 32, 32, 160, 64)
r = 1
function love.load()
x = 50
y = 50
speed = 200
Plane = love.graphics.newImage("Plane.png")
end
function love.update(dt)
if love.keyboard.isDown("right") then
x = x + (speed * dt)
end
if love.keyboard.isDown("left") then
x = x - (speed * dt)
end
if love.keyboard.isDown("down") then
y = y + (speed * dt)
end
if love.keyboard.isDown("up") then
y = y - (speed * dt)
end
if love.keyboard.isDown("r") then
r = r + 1
if r > 3 then
r = 1
end
end
end
function love.draw()
love.graphics.drawq(Plane, a[r], x, y)
end
Re: Problems with quads, and how they work...
Posted: Wed Aug 21, 2013 6:23 pm
by DaedalusYoung
I wouldn't use three different quads for this, you can just use one and then use
Quad:setViewport to change the sprite. In addition, use some timer variable, so the quad doesn't change every frame, which just makes the plane go crazy.
Re: Problems with quads, and how they work...
Posted: Wed Aug 21, 2013 6:33 pm
by FatalMarshmallow
Many thanks for all the help, however crazy the plane appears to be.
After I add a timer variable, it should be fine, I'll just have to find the magic number first.
Re: Problems with quads, and how they work...
Posted: Wed Aug 21, 2013 9:31 pm
by Ranguna259
Aren't quads gonna be romoved from löve ?
Re: Problems with quads, and how they work...
Posted: Wed Aug 21, 2013 10:04 pm
by slime
Yes, but they'll be replaced by
Geometry. Also love.graphics.newQuad will still exist, it'll just return a Geometry.
Re: Problems with quads, and how they work...
Posted: Thu Aug 22, 2013 12:11 am
by Ranguna259
Good to know that newQuad'll still work, that way people won't need to change their whole code
Re: Problems with quads, and how they work...
Posted: Thu Aug 22, 2013 1:16 am
by FatalMarshmallow
Does anyone have an idea of when we're expecting 0.9.0?
Re: Problems with quads, and how they work...
Posted: Thu Aug 22, 2013 1:57 pm
by Ranguna259
Soon