I found a great thread on this forum about how to use bump.lua. I was able to add it to my main.lua without an error. But when I move the player, the player is still going through the image of the desk. I put a square around the image and added a property called collideable and made it true as the tutorial states. I think I may have two problems:
1. I do not think I am referencing the player for the new world.
2. I don't have it on my map correctly.
Here is the code and two images showing what I did. Hopefully this helps. Thank you for any assistance.
-- Include Simple Tiled Implementation into project
sti = require "sti"
bump = require "bump"
function love.load()
-- Load map file
map = sti("map.lua")
local world = bump.newWorld()
local map = sti('map.lua', {"bump"}) -- This loads the map file, and loads the bump plugin for STI
map:bump_init(world) -- This initializes the bump plugin, and loads all of your collidable tiles
-- Create new dynamic data layer called "Sprites" as the 3rd layer
local layer = map:addCustomLayer("Sprites", 3)
-- Get player spawn object
local player
for k, object in pairs(map.objects) do
if object.name == "Player" then
player = object
break
end
end
-- Create player object
local sprite = love.graphics.newImage("sprite.png")
img = love.graphics.newQuad(0, 0, 32, 64, sprite:getDimensions())
layer.player = {
sprite = sprite,
x = player.x,
y = player.y,
ox = sprite:getWidth() / 2,
oy = sprite:getHeight() / 1.35
}
-- Add controls to player
layer.update = function(self, dt)
-- 96 pixels per second
local speed = 96
-- Move player up
if love.keyboard.isDown("w") or love.keyboard.isDown("up") then
self.player.y = self.player.y - speed * dt
end
-- Move player down
if love.keyboard.isDown("s") or love.keyboard.isDown("down") then
self.player.y = self.player.y + speed * dt
end
-- Move player left
if love.keyboard.isDown("a") or love.keyboard.isDown("left") then
self.player.x = self.player.x - speed * dt
end
-- Move player right
if love.keyboard.isDown("d") or love.keyboard.isDown("right") then
self.player.x = self.player.x + speed * dt
end
end
-- Draw player
layer.draw = function(self)
love.graphics.draw(
self.player.sprite,
math.floor(self.player.x),
math.floor(self.player.y),
0,
1,
1,
self.player.ox,
self.player.oy
)
end
-- Remove unneeded object layer
map:removeLayer("Spawn Point")
function love.update(dt)
-- Update world
map:update(dt)
end
function love.draw()
-- Scale world
local scale = 2
local screen_width = love.graphics.getWidth() / scale
local screen_height = love.graphics.getHeight() / scale
map:draw()
end
end[attachment=1]imageCollider.png[/attachment]
2lostsouls wrote: ↑Wed Jun 19, 2019 1:54 pm
1. Do I put the sprite image on an image layer on the map after making the collidable tiles, or on an object layer?
I'm not sure, but I think the image layer and the object layer are identical, only one is dedicated to images.
STI admits both layers.
Ok, I really want to learn this but it is getting very frustrating. I cannot get the collision to work. I cannot find a tutorial that really shows me how to do the collision. The picture shows my character but he is going right through the object that I want him not to go through. Is there any one that can look at the code and see if there is something I should be adding. I am showing some pics on how my tileset looks and my map as well as my Main.lua. Thank you.
-- Include Simple Tiled Implementation into project
sti = require "sti"
bump = require "bump"
function love.load()
-- Load map file
map = sti("map.lua")
local world = bump.newWorld()
local map = sti('map.lua', {"bump"}) -- This loads the map file, and loads the bump plugin for STI
map:bump_init(world) -- This initializes the bump plugin, and loads all of your collidable tiles
-- Create new dynamic data layer called "Sprites" as the 3rd layer
local layer = map:addCustomLayer("Sprites", 3)
-- Get player spawn object
local player
for k, object in pairs(map.objects) do
if object.name == "Player" then
player = object
break
end
end
-- Create player object
local sprite = love.graphics.newImage("sprite.png")
img = love.graphics.newQuad(0, 0, 32, 64, sprite:getDimensions())
layer.player = {
sprite = sprite,
x = player.x,
y = player.y,
ox = sprite:getWidth() / 2,
oy = sprite:getHeight() / 1.35
}
-- Add controls to player
layer.update = function(self, dt)
-- 96 pixels per second
local speed = 96
-- Move player up
if love.keyboard.isDown("w") or love.keyboard.isDown("up") then
self.player.y = self.player.y - speed * dt
end
-- Move player down
if love.keyboard.isDown("s") or love.keyboard.isDown("down") then
self.player.y = self.player.y + speed * dt
end
-- Move player left
if love.keyboard.isDown("a") or love.keyboard.isDown("left") then
self.player.x = self.player.x - speed * dt
end
-- Move player right
if love.keyboard.isDown("d") or love.keyboard.isDown("right") then
self.player.x = self.player.x + speed * dt
end
end
-- Draw player
layer.draw = function(self)
love.graphics.draw(
self.player.sprite,
math.floor(self.player.x),
math.floor(self.player.y),
0,
1,
1,
self.player.ox,
self.player.oy
)
end
-- Remove unneeded object layer
map:removeLayer("Spawn Point")
function love.update(dt)
-- Update world
map:update(dt)
end
function love.draw()
-- Scale world
local scale = 2
local screen_width = love.graphics.getWidth() / scale
local screen_height = love.graphics.getHeight() / scale
map:draw()
end
end
2lostsouls wrote: ↑Fri Jun 21, 2019 1:39 am
Ok, I really want to learn this but it is getting very frustrating. I cannot get the collision to work. I cannot find a tutorial that really shows me how to do the collision. The picture shows my character but he is going right through the object that I want him not to go through. Is there any one that can look at the code and see if there is something I should be adding. I am showing some pics on how my tileset looks and my map as well as my Main.lua. Thank you.
-- Include Simple Tiled Implementation into project
sti = require "sti"
bump = require "bump"
function love.load()
-- Load map file
map = sti("map.lua")
local world = bump.newWorld()
local map = sti('map.lua', {"bump"}) -- This loads the map file, and loads the bump plugin for STI
map:bump_init(world) -- This initializes the bump plugin, and loads all of your collidable tiles
-- Create new dynamic data layer called "Sprites" as the 3rd layer
local layer = map:addCustomLayer("Sprites", 3)
-- Get player spawn object
local player
for k, object in pairs(map.objects) do
if object.name == "Player" then
player = object
break
end
end
-- Create player object
local sprite = love.graphics.newImage("sprite.png")
img = love.graphics.newQuad(0, 0, 32, 64, sprite:getDimensions())
layer.player = {
sprite = sprite,
x = player.x,
y = player.y,
ox = sprite:getWidth() / 2,
oy = sprite:getHeight() / 1.35
}
-- Add controls to player
layer.update = function(self, dt)
-- 96 pixels per second
local speed = 96
-- Move player up
if love.keyboard.isDown("w") or love.keyboard.isDown("up") then
self.player.y = self.player.y - speed * dt
end
-- Move player down
if love.keyboard.isDown("s") or love.keyboard.isDown("down") then
self.player.y = self.player.y + speed * dt
end
-- Move player left
if love.keyboard.isDown("a") or love.keyboard.isDown("left") then
self.player.x = self.player.x - speed * dt
end
-- Move player right
if love.keyboard.isDown("d") or love.keyboard.isDown("right") then
self.player.x = self.player.x + speed * dt
end
end
-- Draw player
layer.draw = function(self)
love.graphics.draw(
self.player.sprite,
math.floor(self.player.x),
math.floor(self.player.y),
0,
1,
1,
self.player.ox,
self.player.oy
)
end
-- Remove unneeded object layer
map:removeLayer("Spawn Point")
function love.update(dt)
-- Update world
map:update(dt)
end
function love.draw()
-- Scale world
local scale = 2
local screen_width = love.graphics.getWidth() / scale
local screen_height = love.graphics.getHeight() / scale
map:draw()
end
end
2lostsouls wrote: ↑Fri Jun 21, 2019 1:39 am
Ok, I really want to learn this but it is getting very frustrating. I cannot get the collision to work. I cannot find a tutorial that really shows me how to do the collision. The picture shows my character but he is going right through the object that I want him not to go through. Is there any one that can look at the code and see if there is something I should be adding. I am showing some pics on how my tileset looks and my map as well as my Main.lua. Thank you.
-- Include Simple Tiled Implementation into project
sti = require "sti"
bump = require "bump"
function love.load()
-- Load map file
map = sti("map.lua")
local world = bump.newWorld()
local map = sti('map.lua', {"bump"}) -- This loads the map file, and loads the bump plugin for STI
map:bump_init(world) -- This initializes the bump plugin, and loads all of your collidable tiles
-- Create new dynamic data layer called "Sprites" as the 3rd layer
local layer = map:addCustomLayer("Sprites", 3)
-- Get player spawn object
local player
for k, object in pairs(map.objects) do
if object.name == "Player" then
player = object
break
end
end
-- Create player object
local sprite = love.graphics.newImage("sprite.png")
img = love.graphics.newQuad(0, 0, 32, 64, sprite:getDimensions())
layer.player = {
sprite = sprite,
x = player.x,
y = player.y,
ox = sprite:getWidth() / 2,
oy = sprite:getHeight() / 1.35
}
-- Add controls to player
layer.update = function(self, dt)
-- 96 pixels per second
local speed = 96
-- Move player up
if love.keyboard.isDown("w") or love.keyboard.isDown("up") then
self.player.y = self.player.y - speed * dt
end
-- Move player down
if love.keyboard.isDown("s") or love.keyboard.isDown("down") then
self.player.y = self.player.y + speed * dt
end
-- Move player left
if love.keyboard.isDown("a") or love.keyboard.isDown("left") then
self.player.x = self.player.x - speed * dt
end
-- Move player right
if love.keyboard.isDown("d") or love.keyboard.isDown("right") then
self.player.x = self.player.x + speed * dt
end
end
-- Draw player
layer.draw = function(self)
love.graphics.draw(
self.player.sprite,
math.floor(self.player.x),
math.floor(self.player.y),
0,
1,
1,
self.player.ox,
self.player.oy
)
end
-- Remove unneeded object layer
map:removeLayer("Spawn Point")
function love.update(dt)
-- Update world
map:update(dt)
end
function love.draw()
-- Scale world
local scale = 2
local screen_width = love.graphics.getWidth() / scale
local screen_height = love.graphics.getHeight() / scale
map:draw()
end
end
I think you need to register the position of you shape in bump word. And check if you can move it.
if love.keyboard.isDown("w") or love.keyboard.isDown("up") then
self.player.y = self.player.y - speed * dt
end
The way bump works is by telling it "hey I want to move this object from where it is to *{x,y}*". Then bump "processes the attempt" and gives you a new x and y ("ok, this is where your object ended up when attempting to move to {x,y}") and a list of collisions ("and this is the list of objects it collided with"). This is done with the *world:move* method. See this link: