Hi there. I've been trying out Love2D in the past few days and Loving it. But I have a few questions about Love usage / Lua:
Inheritance
How does class inheritance work in Lua? I come from an Actionscript background if that helps.
Shaders in 0.9.0
There are a lot of Shader tutorials written in 0.8.0 but they went through a big change in 0.9.0 and I can't seem to get them working in 0.9.0.
Joysticks
Similarly to Shaders, joysticks changed a bit in the update and I cannot get them to work.
Sorry if I'm being a bother and thank you for Helping!
Help with Inheritance, Shaders and Joysticks
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
-
- Prole
- Posts: 4
- Joined: Wed Apr 16, 2014 3:16 pm
Re: Help with Inheritance, Shaders and Joysticks
For inheritance, there are plenty of class libraries available for you to use to mimic classes and inheritance.
The shader language is GLSL, and most shaders made outside of LOVE can be adapted as pixel / vertex shaders inside of love, except instead of setting gl_FragColor or the like, you'd return it.
For joysticks, what problems are you having with them specifically? Maybe show us your code?
The shader language is GLSL, and most shaders made outside of LOVE can be adapted as pixel / vertex shaders inside of love, except instead of setting gl_FragColor or the like, you'd return it.
For joysticks, what problems are you having with them specifically? Maybe show us your code?
-
- Prole
- Posts: 4
- Joined: Wed Apr 16, 2014 3:16 pm
Re: Help with Inheritance, Shaders and Joysticks
Thanks for the help, Kingdaro!
This is a simple example of the kind of thing I want to achieve. Love just gives me an error saying "attempt to index global "Joystick" (a nil value)" I'm trying to get button input and movement via joystick axis.
Code: Select all
function love.load( ... )
-- body
px = 100
py = 100
end
function love.draw( ... )
-- body
love.graphics.rectangle("fill", px, py, 100, 100)
end
function love.update( ... )
-- body
if Joystick:isDown(0,0) then
px = px + 1
end
end
Re: Help with Inheritance, Shaders and Joysticks
That's because you need to get a joystick object first, as "Joystick" isn't defined. A 'nil value' is an undefined variable, and indexing is trying to call a function from it, hence the message "attempt to index a nil value".
What you'll want to do is use love.joystick.getJoysticks() to get all of the connected joysticks, and use the first one for your operations.
https://www.love2d.org/wiki/love.joystick.getJoysticks
What you'll want to do is use love.joystick.getJoysticks() to get all of the connected joysticks, and use the first one for your operations.
Code: Select all
function love.update(dt)
local joysticks = love.joystick.getJoysticks()
local joystick = joysticks[1]
if joystick:isDown(1) then
px = px + 100 * dt
end
end
-
- Prole
- Posts: 4
- Joined: Wed Apr 16, 2014 3:16 pm
Re: Help with Inheritance, Shaders and Joysticks
Thanks for that! The Joysticks are working now. Do you know where I can find some examples of shaders in love2d?
Also, I have this new thing I need some help with. I'm trying to find a way that I could add multiple classes to the game. I mean, say I have a platformer, I can add a player, but how do I add multiple walls and floors?
Main.lua
Wall.lua
Also, I have this new thing I need some help with. I'm trying to find a way that I could add multiple classes to the game. I mean, say I have a platformer, I can add a player, but how do I add multiple walls and floors?
Main.lua
Code: Select all
require "player"
require "wall"
function love.load()
player:Init()
--I'd like to use this to add multiple walls
--[[for i=1, 10 do
wall:Init(i * 32, 200)
end]]
--Adds 1 wall
wall:Init(100, 300)
end
function love.draw()
--Draws player
player:Draw()
--Draws wall
wall:Draw()
love.graphics.setColor(255, 255, 255, 255)
end
function love.update(dt)
player:Update(dt)
end
Code: Select all
require "class"
wall = class:new()
function wall:Init(x, y)
self.x = x
self.y = y
self.width = 32
self.height = 32
end
function wall:Draw()
love.graphics.setColor(255, 0, 0)
love.graphics.rectangle("fill", self.x, self.y, self.width, self.height)
end
Who is online
Users browsing this forum: Google [Bot] and 2 guests