![Smile :)](./images/smilies/ms-smile.png)
SOLVED Moving 32 to pixels and stopping
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
SOLVED Moving 32 to pixels and stopping
So I've tried figuring out viewtopic.php?t=76983 STI Which I don't get at all! I was wondering if there is a way to make a map that goes along the lines of 32 x 32 pixel squares, and every arrow key you hit you move in that direction once then you release and hit it again. The farthest I got on this was it either not working or my image just going off the screen. As I said I can't figure out STI so a tutorial on how to use it with tiled would be great, Also the website it has explaining it just don't make no sense to me. ![Smile :)](./images/smilies/ms-smile.png)
![Smile :)](./images/smilies/ms-smile.png)
Last edited by luaiscool on Sat May 03, 2014 12:33 am, edited 1 time in total.
http://xkcd.com/979/
Code: Select all
if signature = true then
print(signaturetext)
else
print("Error: Signature Not Found")
end
Re: Moving 32 to pixels and stopping
I have attached a .love with a simple way to do it (you can extract it by first changing it's extension from .love to .zip)
I am bad at explaining things so i'll let someone else explain STI. Please note that I didn't implement collision detection i'll leave that one to you
(Hint: I recommend HardonCollider for collsion also check out the drawCollsionMap function at the map.lua file inside the sti folder)
Anyway:
main.lua
level.lua
EDIT:
Also read the STI documentation http://karai17.github.io/Simple-Tiled-I ... llisionMap it helps
I am bad at explaining things so i'll let someone else explain STI. Please note that I didn't implement collision detection i'll leave that one to you
![Wink ;)](./images/smilies/ms-wink.png)
Anyway:
main.lua
Code: Select all
sti = require "sti"
require "level"
function love.load()
playerX = 0
playerY = 0
playerW = 25 -- Player Width and Height
playerH = 25
level.load()
end
function love.update(dt)
level.update(dt)
end
function love.draw()
level.draw()
love.graphics.print("playerX = " .. playerX, 10, 10) -- print the player X and Y coordinates
love.graphics.print("playerY = " .. playerY, 10, 20)
love.graphics.setColor(0,255,0) -- Set color to green
love.graphics.rectangle("fill", playerX, playerY, playerW, playerH) -- Draw a rectangle
love.graphics.setColor(255,255,255) -- Set color to white
end
function love.keypressed(key)
if key == "left" then
playerX = playerX - 32
elseif key == "right" then
playerX = playerX + 32
elseif key == "up" then
playerY = playerY - 32
elseif key == "down" then
playerY = playerY + 32
end
end
Code: Select all
level = {}
function level.load()
-- Grab window size
windowWidth = love.graphics.getWidth()
windowHeight = love.graphics.getHeight()
-- Load a map exported to Lua from Tiled
map = sti.new("map")
Col = map:getCollisionMap("Col")
end
function level.update(dt)
map:update(dt)
end
function level.draw()
local tx = -0
local ty = -7
local w = windowWidth
local h = windowHeight
-- Move the top-left-most x/y position by tx/ty, respectively
love.graphics.translate(tx, ty)
-- Draw only the tiles on screen
map:setDrawRange(tx, ty, w, h)
map:draw()
map:drawCollisionMap(Col)
end
Also read the STI documentation http://karai17.github.io/Simple-Tiled-I ... llisionMap it helps
- Attachments
-
main.love
- Sorry it is called main.love I just moved all the files to a zip and changed to .love I didn't notice the name
- (13.31 KiB) Downloaded 73 times
My devlog: http://lalorobot.tumblr.com/
Bitbucket: https://lalorobot@bitbucket.org/lalorob ... -indev.git
Bitbucket: https://lalorobot@bitbucket.org/lalorob ... -indev.git
Who is online
Users browsing this forum: Ahrefs [Bot] and 3 guests