Page 3 of 6

Re: How to use bump.lua

Posted: Fri Feb 27, 2015 9:39 pm
by Bindie
I solved it. If I add half the width to every player.x and half the height to every player.y I can draw the player inside the rectangle while it can still rotate from the middle. Adding half the width and half the height to every player.x and every player.y, is it really necessary to do it so complicated?

Edit:

I think I finally found my clear question: I don't really know how to use world:move. Here is my super simple player collision code:

Code: Select all

	-- Player collision

	local newX, newY, cols, len = world:move(player, player.x, player.y)
	player.x, player.y = newX, newY
I guess this is what updates the bounding box (rectangle), and how would I add offset to newX and newY so I can trim the rectangle around the player?

Man do I love coming through blockages!

Re: How to use bump.lua

Posted: Fri Feb 27, 2015 10:17 pm
by kikito
Bindie wrote:I solved it. If I add half the width to every player.x and half the height to every player.y I can draw the player inside the rectangle while it can still rotate from the middle. Adding half the width and half the height to every player.x and every player.y, is it really necessary to do it so complicated?
It's difficult to understand what you are doing, but I will try to answer.

Normally it is the other way around - the variables you "carry on from frame to frame" should be as "close to the normal logic as possible". This means that your player.x and player.y should always be "whatever makes sense most of the time" (in your case, your player's "center").

If you need to use a different x and y for drawing, then, inside the draw routine, you calculate these other values you need for drawing. But you don't override player.x and player.y with those values that you only need for drawing. It becomes supercomplicated really fast, especially if you are mixing up scrolling etc in the same scope, as you were doing in your previous code.

Re: How to use bump.lua

Posted: Sat Feb 28, 2015 12:17 pm
by Bindie
You understand me clearly.

When I draw my player with offset x and y to be able to rotate it from the center (and using the collision code as it is):

Code: Select all

love.graphics.draw(player.img, player.x+player.w/2, player.y+player.h/2, player.angle,1,1,player.w/2,player.h/2)
However, when I draw it without the offset:

Code: Select all

love.graphics.draw(player.img, player.x, player.y, player.angle,1,1,player.w/2,player.h/2)
And remove this collision code:

Code: Select all

	local newX, newY, cols, len = world:move(player, player.x, player.y)
	player.x, player.y = newX, newY
Player is within the box:

Image

Link: http://oi61.tinypic.com/333dfuo.jpg

This is clearly showing me something, can someone do something with the collision code is there a solution?

Re: How to use bump.lua

Posted: Sat Feb 28, 2015 3:33 pm
by kikito
However, when I draw it without the offset:
Don't do that. Draw it with the offset. As I said before: do whatever calculations you need for drawing when you draw. Not more, but also not less.

Re: How to use bump.lua

Posted: Sat Feb 28, 2015 5:07 pm
by Bindie
I'll try. Thanks.

Edit: Almost ironic, nothing was wrong with the code in the first place, I just needed offset. Lol.

Re: How to use bump.lua

Posted: Sat Mar 21, 2015 8:36 pm
by Bindie
Hello, when checking all rectangles in a world, how would one get their x and y positions?

Re: How to use bump.lua

Posted: Sat Mar 21, 2015 9:16 pm
by s-ol
Bindie wrote:Hello, when checking all rectangles in a world, how would one get their x and y positions?
At bottom of the readme there are some more utility functions:

Code: Select all

local items, len = world:getItems()
local x,y,w,h = world:getRect(item)
You can combine these to get all positions.

Re: How to use bump.lua

Posted: Sat Mar 21, 2015 9:24 pm
by Bindie
Awesome. Thanks.

Re: How to use bump.lua

Posted: Sat Mar 21, 2015 9:29 pm
by Bindie
To take it further:

Assume we have a world full of items, if I do this:

Code: Select all

for i,v in ipairs(world) do
print(v)
end
Should v be anything?

Re: How to use bump.lua

Posted: Sat Mar 21, 2015 9:37 pm
by s-ol
Bindie wrote:To take it further:

Assume we have a world full of items, if I do this:

Code: Select all

for i,v in ipairs(world) do
print(v)
end
Should v be anything?
Of course not, world is a table and doesn't have any integer keys. There could be an iterator function, but it would look more like:

Code: Select all

for x,y,w,h in world.iterate do
  -- stuff
end