How to use bump.lua

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Bindie
Party member
Posts: 151
Joined: Fri Jan 23, 2015 1:29 pm

Re: How to use bump.lua

Post by Bindie »

I admire bump.lua, simple and super.

I have a little width and height trouble with my character. He is a box of 54x54 pixels, however there is a border in front of him and he can move into tiles, is there an easy way to correct this?

I have attached the character and main.lua. I know the character is not centered, I tried that yesterday and it didn't make any difference. Does it have anything with pseudo borders to do?

Edit: I think from looking at love.draw at the bottom of the code it has do to with offsetting half the width and height, but using full width and height to the item player in bump.
Attachments
main.lua
(29.85 KiB) Downloaded 148 times
1.png
1.png (3.09 KiB) Viewed 4295 times
Bindie
Party member
Posts: 151
Joined: Fri Jan 23, 2015 1:29 pm

Re: How to use bump.lua

Post by Bindie »

A bit more specific:

If I have offset when drawing my player character, do I have to take this into account when adding the tile to a world in bump.lua?

My character bumps nicely into positive x- and y-axis but when I go into the negative x- and y-axis the tile overlaps with the map-tiles. That's the issue.

Bindie
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: How to use bump.lua

Post by kikito »

I am sorry, I can't help you with what you gave me. I don't understand what you are trying to do and the code you gave me does not work on its own (it depends on lots of stuff that is missing, like missing tiles, fonts and sounds).

Please make a .love file with the missing assets, or at least give me a clean main.lua file, so that I can see what the problem is.
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

Post by Bindie »

Sure, It seems my character tile overlaps with all other tiles in the positive y axis and x axis.
Attachments
Room collision.love
(1.7 MiB) Downloaded 149 times
User avatar
s-ol
Party member
Posts: 1077
Joined: Mon Sep 15, 2014 7:41 pm
Location: Cologne, Germany
Contact:

Re: How to use bump.lua

Post by s-ol »

Bindie wrote:Sure, It seems my character tile overlaps with all other tiles in the positive y axis and x axis.
Just judging from what I understand you wrote in the posts: bump.lua x/y values are the top-left corner of the object, so you need to account for width/height when drawing something centered.

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

Post by Bindie »

So how do I account for width and height?

Say I draw with an offset to make character centered, how does this translate into bump and where should I put the new x and y values with offset?
User avatar
s-ol
Party member
Posts: 1077
Joined: Mon Sep 15, 2014 7:41 pm
Location: Cologne, Germany
Contact:

Re: How to use bump.lua

Post by s-ol »

Bindie wrote:So how do I account for width and height?

Say I draw with an offset to make character centered, how does this translate into bump and where should I put the new x and y values with offset?
That depends on how you draw your character. With a rectangle you don't have to do anything for drawing:

Code: Select all

player = {
  x = 100,
  y = 100,
  hw = 20,
  hh = 15
}

function love.draw()
  love.graphics.rectangle ("fill", player.y, player.y, player.hw*2, player.hh*2)
  
  -- image with rotation:
  love.graphics.draw(player.image, player.x+player.hw, player.y+player.hh, player.rot, 1, 1, player.wh, player.hh)
  -- (image, center x, center y, rotation, scale x, scale y, center offset x, center offset y)
end
With a circle just use the offset' position as the x and y.

If you measure a distance, shoot or spawn something else you always need to consider the player center (p.x+p.hw,p.y+p.hh).

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
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: How to use bump.lua

Post by kikito »

I have added the following lines to the end of your love.draw function:

Code: Select all

    love.graphics.setColor(255,0,0)
    love.graphics.rectangle('line', world:getRect(player))

They show the rectangle which the player is being represented by in bump. It is not aligned with the picture you show of him:
Screen Shot 2015-02-09 at 19.52.26 .png
Screen Shot 2015-02-09 at 19.52.26 .png (6.17 KiB) Viewed 4213 times
(I would have sent you a .love file, but you have named your folders and files with uppercase (assets/Player/Laser.png) while your code uses lowercase (assets/player/laser.png) so the .love can't be done without renaming, which I don't want to do myself).

I don't know how to fix this in your code because ... frankly, it is quite difficult to understand. I can give you some pointers though:
  • Intent it properly. It can look like a hassle, but it will save you some bugs later on.
  • Your code is mixing very different concerns in the same place. Variables which control the animation are mixed up with others related with scrolling. This makes it very difficult to understand for someone not familiar with it.
  • I recommend that you put your player's "head" centered in the image. Otherwise when he "turns around" he "moves in a weird way around the center of the image". Accounting for this will be difficult when you want to align the drawing with the physical rectangle.
PS: I've got a couple libraries which should help you with point number two. Check out anim8 for animations and gamera for handling the camera. They should allow you to keep the code a bit more uncoupled.
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

Post by Bindie »

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

Re: How to use bump.lua

Post by Bindie »

Hey, my player.x and player.y are in the middle of the player. So when I add the rectangle to bump.lua, it draws it from the middle instead from the top left corner of the image. Here comes the concrete question: Is it possible to use bump.lua and have a rectangle around the player while still rotating it from the center and moving the rectangle?

Do I have to offset every x and y value for the player so I can still have player.x and player.y in the center of the image and everything working properly or should I just add an extra player.x and player.y which already is offset?
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 18 guests