Problems with quads, and how they work...

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
FatalMarshmallow
Prole
Posts: 17
Joined: Mon Jul 30, 2012 9:15 pm

Problems with quads, and how they work...

Post 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.
Attachments
Plane.love
(9.32 KiB) Downloaded 206 times
User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: Problems with quads, and how they work...

Post 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
User avatar
vladgalay
Citizen
Posts: 60
Joined: Sun Jan 29, 2012 4:54 pm
Location: The Motherland

Re: Problems with quads, and how they work...

Post 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
User avatar
DaedalusYoung
Party member
Posts: 413
Joined: Sun Jul 14, 2013 8:04 pm

Re: Problems with quads, and how they work...

Post 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.
FatalMarshmallow
Prole
Posts: 17
Joined: Mon Jul 30, 2012 9:15 pm

Re: Problems with quads, and how they work...

Post by FatalMarshmallow »

Many thanks for all the help, however crazy the plane appears to be. :ultrahappy:
After I add a timer variable, it should be fine, I'll just have to find the magic number first.
User avatar
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...

Post by Ranguna259 »

Aren't quads gonna be romoved from löve ?
LoveDebug- A library that will help you debug your game with an on-screen fully interactive lua console, you can even do code hotswapping :D

Check out my twitter.
User avatar
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...

Post by slime »

Yes, but they'll be replaced by Geometry. Also love.graphics.newQuad will still exist, it'll just return a Geometry.
User avatar
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...

Post by Ranguna259 »

Good to know that newQuad'll still work, that way people won't need to change their whole code :megagrin:
LoveDebug- A library that will help you debug your game with an on-screen fully interactive lua console, you can even do code hotswapping :D

Check out my twitter.
FatalMarshmallow
Prole
Posts: 17
Joined: Mon Jul 30, 2012 9:15 pm

Re: Problems with quads, and how they work...

Post by FatalMarshmallow »

Does anyone have an idea of when we're expecting 0.9.0?
User avatar
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...

Post by Ranguna259 »

Soon
LoveDebug- A library that will help you debug your game with an on-screen fully interactive lua console, you can even do code hotswapping :D

Check out my twitter.
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 8 guests