Page 14 of 15

Re: HUMP - yet another set of helpers

Posted: Sun Apr 24, 2016 3:13 pm
by vrld
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().

Re: HUMP - yet another set of helpers

Posted: Sun Apr 24, 2016 10:55 pm
by Kibita
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.

Re: HUMP - yet another set of helpers

Posted: Mon Apr 25, 2016 8:27 am
by Rishavs
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.

Re: HUMP - yet another set of helpers

Posted: Sat Apr 30, 2016 9:16 am
by vrld
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
        end) -- self.radius
        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?

Re: HUMP - yet another set of helpers

Posted: Sun May 01, 2016 3:25 am
by Kibita
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.

Re: HUMP - yet another set of helpers

Posted: Thu Jun 16, 2016 4:24 am
by Viomi
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 mainmenu = {}
local game = {}

function love.load()
	Gamestate.registerEvents()
	Gamestate.switch(mainmenu)
end

function mainmenu:init()
	start = Button('fill', 10, 10, 50, 50)
end

function mainmenu:mousereleased(x, y, button, istouch)
	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? :?

Re: HUMP - yet another set of helpers

Posted: Thu Jun 16, 2016 9:16 am
by Nixola
Button:clickedOn is defined with ":" but has self in the arguments. Remove the "self" from there, I guess

Re: HUMP - yet another set of helpers

Posted: Thu Jun 16, 2016 10:24 am
by Viomi
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. :shock:

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

Thanks Nixola ;)

Re: HUMP - yet another set of helpers

Posted: Sat Oct 08, 2016 3:59 pm
by Jack Dandy
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.

Re: HUMP - yet another set of helpers

Posted: Sat Oct 08, 2016 4:05 pm
by MadByte
You should provide a code example for that, otherwise I just can guess what might be wrong.
Make sure that you're updating the timer in your update callback.