HUMP - yet another set of helpers

Showcase your libraries, tools and other projects that help your fellow love users.
Post Reply
User avatar
vrld
Party member
Posts: 917
Joined: Sun Apr 04, 2010 9:14 pm
Location: Germany
Contact:

Re: HUMP - yet another set of helpers

Post by vrld »

Minor tweak in hump.timer:

You can now stop the execution of periodic timers by returning false from the function, e.g.

Code: Select all

-- spawn a new enemy every 5 seconds or until the hive is destroyed
Timer.addPeriodic(5, function()
    if not hive or hive.life <= 0 then return false end
    hive:spawnZombieClown()
end)
I have come here to chew bubblegum and kick ass... and I'm all out of bubblegum.

hump | HC | SUIT | moonshine
Gnx
Prole
Posts: 40
Joined: Sun Nov 09, 2008 6:38 am

Re: HUMP - yet another set of helpers

Post by Gnx »

vrld wrote:Minor tweak in hump.timer:

You can now stop the execution of periodic timers by returning false from the function, e.g.

Code: Select all

-- spawn a new enemy every 5 seconds or until the hive is destroyed
Timer.addPeriodic(5, function()
    if not hive or hive.life <= 0 then return false end
    hive:spawnZombieClown()
end)
Thats actually very useful :)
Patooty
Prole
Posts: 5
Joined: Wed Jan 18, 2012 5:26 pm

Re: HUMP - yet another set of helpers

Post by Patooty »

Apologies if I missed it, but I wasn't able to find any talk on the camera module in this thread. Do you know of a working example somewhere? I'm having some problems getting it to work, and not sure if I'm just doing something stupid / overlooking something.

I'm able to create a camera object by doing like so:

Code: Select all

Vector = require 'library/hump/vector.lua'
Camera = require 'library/hump/camera.lua'

Code: Select all

mainCamera = Camera:new()
But when I try to call mainCamera:attach() I get the following error:

http://imgur.com/a5eOz


But if I instead initialize the camera like so:

Code: Select all

mainCamera = Camera:new(Vector(100,100), 2, math.pi/2)
then the error I get is:

http://imgur.com/fNhID


Edit: I had initially assumed that the vector was being incorrectly read as not-a-vector, but upon further investigation... In the camera class I decided to check why exactly the assert was failing:

Code: Select all

local typeStr = string.format("zoom is of type: %s", type(self.zoom))
	assert(type(self.zoom) == "number", typeStr)
yields:

Code: Select all

zoom is of type: table
It seems that the camera's fields are incorrect, though I'm still unsure what correct solution would be.
User avatar
tentus
Inner party member
Posts: 1060
Joined: Sun Oct 31, 2010 7:56 pm
Location: Appalachia
Contact:

Re: HUMP - yet another set of helpers

Post by tentus »

Have you seen the documentation at http://vrld.github.com/hump/#Camera?
Kurosuke needs beta testers
Patooty
Prole
Posts: 5
Joined: Wed Jan 18, 2012 5:26 pm

Re: HUMP - yet another set of helpers

Post by Patooty »

Yeah, my second attempt to initialize the camera actually came directly from that page. I have no other camera code besides initializing it (in an init function) and trying to attach/detach the camera (within a draw function). I feel like I'm having problems because of my inexperience with Lua. I don't see how the camera.zoom could be reporting that it's a table type. Here's the init function for the camera in camera.lua for easy reference:

Code: Select all

local function new(pos, zoom, rot)
	local pos  = pos or vector(love.graphics.getWidth(), love.graphics.getHeight()) / 2
	local zoom = zoom or 1
	local rot  = rot or 0
	return setmetatable({pos = pos, zoom = zoom, rot = rot}, camera)
end
User avatar
vrld
Party member
Posts: 917
Joined: Sun Apr 04, 2010 9:14 pm
Location: Germany
Contact:

Re: HUMP - yet another set of helpers

Post by vrld »

You need to replace the ":" with a "."
The : is a lua shortcut to set the first function argument to the thing before colon, so this

Code: Select all

Camera:new(Vector(100,100), 2, math.pi/2)
is equivalent to:

Code: Select all

Camera.new(Camera, Vector(100,100), 2, math.pi/2)
Calling it like so will work:

Code: Select all

Camera.new(Vector(100,100), 2, math.pi/2)
Or use the preferred way:

Code: Select all

Camera(Vector(100,100), 2, math.pi/2)
You can see a working camera example here, especially in this file and in this file. Note that this uses an outdated hump version, where attach()/detach() were named predraw()/postdraw().
I have come here to chew bubblegum and kick ass... and I'm all out of bubblegum.

hump | HC | SUIT | moonshine
Patooty
Prole
Posts: 5
Joined: Wed Jan 18, 2012 5:26 pm

Re: HUMP - yet another set of helpers

Post by Patooty »

Seems like I had a pretty warped understanding (or misunderstanding) of how the ':' worked.

Thanks very much for your help :awesome:
User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: HUMP - yet another set of helpers

Post by Nixola »

I didn't know it at all ^^'
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
User avatar
MarekkPie
Inner party member
Posts: 587
Joined: Wed Dec 28, 2011 4:48 pm
Contact:

Re: HUMP - yet another set of helpers

Post by MarekkPie »

The : operator is simply syntactic sugar.

Code: Select all

obj:foo(x)
-- is equivalent to
obj.foo(self, x)
So that can be a way of helping you understand when you use the . operator and when you use the : operator. If you haven't created an object of that classes type, then use the . operator, since you have no self yet. If you are operating on an already created object, then you use the : operator, so that you can use any variables stored within that object.
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: HUMP - yet another set of helpers

Post by kikito »

MarekkPie wrote:The : operator is simply syntactic sugar.

Code: Select all

obj:foo(x)
-- is equivalent to
obj.foo(self, x)
MarekkPie means this:

Code: Select all

obj:foo(x)
-- is equivalent to
obj.foo(obj, x)
When I write def I mean function.
Post Reply

Who is online

Users browsing this forum: No registered users and 61 guests