## HUMP - yet another set of helpers

vrld
Party member
Posts: 917
Joined: Sun Apr 04, 2010 9:14 pm
Location: Germany
Contact:

### Re: HUMP - yet another set of helpers

Rishavs wrote:I need some help with camera coordinates.
I didn't go too deep into you code, but you shouldn't need to transform the coordinates for drawing; just draw the sprite at object.x, object.y.

camera:worldCoords() is only needed to figure out where some point on the screen (between 0,0 and width/height of the window) is in the game world. It is used, for example, to figure out where the mouse pointer points to in the game world.

Conversly, camera:cameraCoords() maps a point in the game world to coordinate in the game window.

Kibita wrote:I dont know what's going on with my Timer, it should make my obstacles doing a smooth oscillation in the X axis, but they go crazy, oscillating very fast gradually.
Looks like you execute Timer.script every frame (if you don't, please post the whole file). You need to call it only once, which defines the script. The script is updated every time you call Timer.update().
I have come here to chew bubblegum and kick ass... and I'm all out of bubblegum.

hump | HC | SUIT | moonshine

Kibita
Prole
Posts: 31
Joined: Tue Dec 29, 2015 7:46 pm

### Re: HUMP - yet another set of helpers

vrld wrote:
Kibita wrote:I dont know what's going on with my Timer, it should make my obstacles doing a smooth oscillation in the X axis, but they go crazy, oscillating very fast gradually.
Looks like you execute Timer.script every frame (if you don't, please post the whole file). You need to call it only once, which defines the script. The script is updated every time you call Timer.update().
Actually, I created the Timer.script() inside the Obstacle.new() method, so it should run one time, I guess. But I "solved" the problem doing this:

Code: Select all

local function updateTweenScript(obj)
if obj.type == "oscillator-x" then
obstacleTimer.tween(10, obj, {distFromMid = obj.radius}, "in-linear", function()
obstacleTimer.tween(10, obj, {distFromMid = const.gameWidth / 2}, "in-linear", function()
updateTweenScript(obj)
end)
end)
end
end

The function call itself.

Rishavs
Party member
Posts: 103
Joined: Sat Oct 17, 2009 5:29 am
Contact:

### Re: HUMP - yet another set of helpers

vrld wrote: I didn't go too deep into you code, but you shouldn't need to transform the coordinates for drawing; just draw the sprite at object.x, object.y.

camera:worldCoords() is only needed to figure out where some point on the screen (between 0,0 and width/height of the window) is in the game world. It is used, for example, to figure out where the mouse pointer points to in the game world.

Conversly, camera:cameraCoords() maps a point in the game world to coordinate in the game window.
Hi Vrld

strangely its not working out for me.
I want to render a sprite at the coordinates coming from Tiled map object.
The object has coords of 320, 2880.

When i put that coord as the coords for the sprite, it doesnt spawns where it needs to. I tried every permutation of coordinate change but i cant get the sprite to render at the Tiled object coordinate. The sprite is positioned at the proper position when i manually put the coords as 708, 1602.

vrld
Party member
Posts: 917
Joined: Sun Apr 04, 2010 9:14 pm
Location: Germany
Contact:

### Re: HUMP - yet another set of helpers

Kibita wrote:Actually, I created the Timer.script() inside the Obstacle.new() method, so it should run one time, I guess.
Sorry for answering so late, but better late than never:

The actual problem with the origin script

Code: Select all

obstacleTimer.script(function(wait)
while true do
obstacleTimer.tween(7, self, {distFromMid = 100}, "in-linear", function()
obstacleTimer.tween(7, self, {distFromMid = 400}, "in-linear") -- const.gameWidth / 2
wait(1)
end
end)
is that you start a tween that takes 14 seconds (7 in + 7 out), but only wait one second before starting a new tween. In hump, tweens can overlay each other. So after two seconds, you have two tweens at the same time, after three seconds there are three, etc.
Waiting 14 seconds should work. Better yet, Timer.script() gets rid of the callback style:

Code: Select all

obstacleTimer.script(function(wait)
while true do
obstacleTimer.tween(7, self, {distFromMid = 100}, "in-linear")
wait(7)
obstacleTimer.tween(7, self, {distFromMid = 400}, "in-linear")
wait(7)
end
end)

Rishavs wrote:When i put that coord as the coords for the sprite, it doesnt spawns where it needs to. I tried every permutation of coordinate change but i cant get the sprite to render at the Tiled object coordinate. The sprite is positioned at the proper position when i manually put the coords as 708, 1602.
Can you upload a (minimal) .love so I can have a look at the problem?
I have come here to chew bubblegum and kick ass... and I'm all out of bubblegum.

hump | HC | SUIT | moonshine

Kibita
Prole
Posts: 31
Joined: Tue Dec 29, 2015 7:46 pm

### Re: HUMP - yet another set of helpers

The actual problem with the origin script is that you start a tween that takes 14 seconds (7 in + 7 out), but only wait one second before starting a new tween. In hump, tweens can overlay each other. So after two seconds, you have two tweens at the same time, after three seconds there are three, etc.
Yes! I discovered this doing some test in a test project. Thank you.

Viomi
Prole
Posts: 11
Joined: Thu Mar 03, 2016 5:13 am

### Re: HUMP - yet another set of helpers

I've come here for help with HUMP because I'm thoroughly confused as to what I'm doing wrong.

Example code:

Code: Select all

Button = Class{}

function Button:init(x, y, width, height)
self.x = x
self.y = y
self.width = width
self.height = height
end

function Button:clickedOn(self, x, y)
if (x >= self.x) and (x <= self.x + self.width) and (y >= self.y) and (y <= self.y + self.height) then
return true
else
return false
end
end

local game = {}

Gamestate.registerEvents()
end

start = Button('fill', 10, 10, 50, 50)
end

if button == 1 then
if start.clickedOn(x, y) then
Gamestate.switch(game)
end
end
end
Gives me an error from clickedOn:
'Error: attempt to index local 'self' (a nil value)

What have I done wrong this time?

Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

### Re: HUMP - yet another set of helpers

Button:clickedOn is defined with ":" but has self in the arguments. Remove the "self" from there, I guess
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
li = love.image
lg = love.graphics

Viomi
Prole
Posts: 11
Joined: Thu Mar 03, 2016 5:13 am

### Re: HUMP - yet another set of helpers

Nixola wrote:Button:clickedOn is defined with ":" but has self in the arguments. Remove the "self" from there, I guess
Oh, woops.

That was rather stupid of me.

Removed self from the arguments, and called it with start:clickedOn instead of start.clickedOn.

Thanks Nixola

Jack Dandy
Prole
Posts: 49
Joined: Mon Sep 08, 2014 4:26 pm

### Re: HUMP - yet another set of helpers

Hey, I have a question about the Hump.timer's "every" function.

Let's say I have this piece of code:

Code: Select all

if key == 's' then
Timer_enemyturn:every(1, gamefuncs.activateAI())
end
But, when I push 's', it only activates the enemy's AI once. How come? I thought it should make the enemy's AI activate every second.

I even checked it, and when I replaced the "activateAI" function with a simple print-to-console function, it only called it once.