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.
Problems with quads, and how they work...
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
-
- Prole
- Posts: 17
- Joined: Mon Jul 30, 2012 9:15 pm
Problems with quads, and how they work...
- Attachments
-
- Plane.love
- (9.32 KiB) Downloaded 206 times
Re: Problems with quads, and how they work...
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.
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...
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
- DaedalusYoung
- Party member
- Posts: 413
- Joined: Sun Jul 14, 2013 8:04 pm
Re: Problems with quads, and how they work...
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.
-
- Prole
- Posts: 17
- Joined: Mon Jul 30, 2012 9:15 pm
Re: Problems with quads, and how they work...
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.
After I add a timer variable, it should be fine, I'll just have to find the magic number first.
- Ranguna259
- Party member
- Posts: 911
- Joined: Tue Jun 18, 2013 10:58 pm
- Location: I'm right next to you
Re: Problems with quads, and how they work...
Aren't quads gonna be romoved from löve ?
- slime
- Solid Snayke
- Posts: 3162
- Joined: Mon Aug 23, 2010 6:45 am
- Location: Nova Scotia, Canada
- Contact:
Re: Problems with quads, and how they work...
Yes, but they'll be replaced by Geometry. Also love.graphics.newQuad will still exist, it'll just return a Geometry.
- Ranguna259
- Party member
- Posts: 911
- Joined: Tue Jun 18, 2013 10:58 pm
- Location: I'm right next to you
Re: Problems with quads, and how they work...
Good to know that newQuad'll still work, that way people won't need to change their whole code
-
- Prole
- Posts: 17
- Joined: Mon Jul 30, 2012 9:15 pm
Re: Problems with quads, and how they work...
Does anyone have an idea of when we're expecting 0.9.0?
- Ranguna259
- Party member
- Posts: 911
- Joined: Tue Jun 18, 2013 10:58 pm
- Location: I'm right next to you
Who is online
Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google [Bot] and 5 guests