## How to use bump.lua

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Bindie
Party member
Posts: 151
Joined: Fri Jan 23, 2015 1:29 pm

### Re: How to use bump.lua

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!

kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Contact:

### Re: How to use bump.lua

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.
When I write def I mean function.

Bindie
Party member
Posts: 151
Joined: Fri Jan 23, 2015 1:29 pm

### Re: How to use bump.lua

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:

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

kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Contact:

### Re: How to use bump.lua

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.
When I write def I mean function.

Bindie
Party member
Posts: 151
Joined: Fri Jan 23, 2015 1:29 pm

### Re: How to use bump.lua

I'll try. Thanks.

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

Bindie
Party member
Posts: 151
Joined: Fri Jan 23, 2015 1:29 pm

### Re: How to use bump.lua

Hello, when checking all rectangles in a world, how would one get their x and y positions?

s-ol
Party member
Posts: 1077
Joined: Mon Sep 15, 2014 7:41 pm
Location: Cologne, Germany
Contact:

### Re: How to use bump.lua

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.

s-ol.nu /blog  -  p.s-ol.be /st8.lua  -  g.s-ol.be /gtglg /curcur

Code: Select all

print( type(love) )
if false then
baby:hurt(me)
end

Bindie
Party member
Posts: 151
Joined: Fri Jan 23, 2015 1:29 pm

### Re: How to use bump.lua

Awesome. Thanks.

Bindie
Party member
Posts: 151
Joined: Fri Jan 23, 2015 1:29 pm

### Re: How to use bump.lua

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?

s-ol
Party member
Posts: 1077
Joined: Mon Sep 15, 2014 7:41 pm
Location: Cologne, Germany
Contact:

### Re: How to use bump.lua

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

s-ol.nu /blog  -  p.s-ol.be /st8.lua  -  g.s-ol.be /gtglg /curcur

Code: Select all

print( type(love) )
if false then
baby:hurt(me)
end

### Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 56 guests