Hooking into loves events

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.
Post Reply
JayKyburz
Prole
Posts: 9
Joined: Wed May 19, 2021 10:47 pm

Hooking into loves events

Post by JayKyburz »

Hey all, I've just started playing with Love and have been reading the forums and tutorials for a while. I don't have any blocking issues but just to ask some questions here on the forums in case I missed a few things on the way.

At the moment I have an update function in my main.lua file that then calls an update function in all the child game objects. Same for draw and even load. I was about to start pushing other events down to all my objects so they can handle input.

Is it possible to automatically resister all my update functions to be called when the love.update event is called?
User avatar
zorg
Party member
Posts: 3449
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Hooking into loves events

Post by zorg »

there's a gamestate library that gives you that kind of functionality as an option: https://hump.readthedocs.io/en/latest/gamestate.html
Although i'm not sure if i would treat game objects as gamestates... semantically i mean; i'd probably do something like this:

Code: Select all

function love.update(dt)
  yourupdatefunc()
end

local function yourupdatefunc()
  -- your game objects being in one table is the assumption:
  for i,v in ipairs(gameobjects) do
    v:update()
  end
end
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
JayKyburz
Prole
Posts: 9
Joined: Wed May 19, 2021 10:47 pm

Re: Hooking into loves events

Post by JayKyburz »

Thanks zorg. Thats pretty much what I am doing now.
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 1 guest