I have one rectangle as the floor in my place. When I make another, your guy can go straight through it.. Why?
Rectangles
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Rectangles
moar tacos = better life
u liek?
u liek?
- Jasoco
- Inner party member
- Posts: 3726
- Joined: Mon Jun 22, 2009 9:35 am
- Location: Pennsylvania, USA
- Contact:
Re: Rectangles
We're gonna need your code, bro.
Re: Rectangles
Code: Select all
function love.load()
World = love.physics.newWorld(-8000, -8000, 8000, 8000)
World:setGravity(3, 300)
World:setMeter(64)
Bodies = {}
Shapes = {}
Bodies[0] = love.physics.newBody(World, 900/2.2, 625, 0, 0)
Shapes[0] = love.physics.newRectangleShape(Bodies[0], 0, 0, 750, 50, 0)
Bodies[1] = love.physics.newBody(World, 650/2, 650/2, 15, 0)
Shapes[1] = love.physics.newCircleShape(Bodies[1], 0, 0, 40)
Shapes[2] = love.physics.newCircleShape(Bodies[1], 0, 0, 5)
Shapes[3] = love.physics.newCircleShape(Bodies[1], 0, 0, 5)
Shapes[4] = love.physics.newRectangleShape(Bodies[0], 0, 0, 750, 50, 0)
love.graphics.setBackgroundColor(104, 136, 248)
love.graphics.setMode(1280, 1048, false, true, 0)
end
function love.update(dt)
World:update(dt)
if love.keyboard.isDown("right") then
Bodies[1]:applyForce(400, 0)
elseif love.keyboard.isDown("left") then
Bodies[1]:applyForce(-400, 0)
elseif love.keyboard.isDown("up") then
Bodies[1]:getPosition()
xPos, yPos = Bodies[1]:getPosition(x, y)
Bodies[1]:setPosition(xPos, yPos - 10)
elseif love.keyboard.isDown("escape") then
love.event.push('q')
end
end
function love.draw()
local x1, y1, x2, y2, x3, y3, x4, y4 = Shapes[0]:getBoundingBox()
local boxwidth = x3 - x2
local boxheight = y2 - y1
love.graphics.setColor(72, 160, 14)
love.graphics.rectangle("fill", Bodies[0]:getX() - boxwidth/2, Bodies[0]:getY() - boxheight/2, boxwidth, boxheight)
love.graphics.setColor(123, 77, 64)
love.graphics.circle("fill", Bodies[1]:getX(), Bodies[1]:getY(), Shapes[1]:getRadius(), 20)
love.graphics.setColor(0, 0, 0)
love.graphics.circle("fill", Bodies[1]:getX(), Bodies[1]:getY() + boxheight/4, Shapes[2]:getRadius(), 20)
love.graphics.setColor(0, 0, 0)
love.graphics.circle("fill", Bodies[1]:getX() + boxwidth/25, Bodies[1]:getY() + boxheight/4, Shapes[3]:getRadius(), 20)
love.graphics.setColor(72, 160, 14)
love.graphics.rectangle("fill", Bodies[0]:getX() - boxwidth/44, Bodies[0]:getY() - boxheight/8, boxwidth, boxheight)
end
moar tacos = better life
u liek?
u liek?
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: Rectangles
It would be nice if you did.Forum rules wrote:Before you make a thread asking for help, read this.
Help us help you: attach a .love.
- tentus
- Inner party member
- Posts: 1060
- Joined: Sun Oct 31, 2010 7:56 pm
- Location: Appalachia
- Contact:
Re: Rectangles
Both rectangles are in the same place.Scriptoar wrote:Sorry about the length.Code: Select all
function love.load() World = love.physics.newWorld(-8000, -8000, 8000, 8000) World:setGravity(3, 300) World:setMeter(64) Bodies = {} Shapes = {} Bodies[0] = love.physics.newBody(World, 900/2.2, 625, 0, 0) Shapes[0] = love.physics.newRectangleShape(Bodies[0], 0, 0, 750, 50, 0) Bodies[1] = love.physics.newBody(World, 650/2, 650/2, 15, 0) Shapes[1] = love.physics.newCircleShape(Bodies[1], 0, 0, 40) Shapes[2] = love.physics.newCircleShape(Bodies[1], 0, 0, 5) Shapes[3] = love.physics.newCircleShape(Bodies[1], 0, 0, 5) Shapes[4] = love.physics.newRectangleShape(Bodies[0], 0, 0, 750, 50, 0) love.graphics.setBackgroundColor(104, 136, 248) love.graphics.setMode(1280, 1048, false, true, 0) end function love.update(dt) World:update(dt) if love.keyboard.isDown("right") then Bodies[1]:applyForce(400, 0) elseif love.keyboard.isDown("left") then Bodies[1]:applyForce(-400, 0) elseif love.keyboard.isDown("up") then Bodies[1]:getPosition() xPos, yPos = Bodies[1]:getPosition(x, y) Bodies[1]:setPosition(xPos, yPos - 10) elseif love.keyboard.isDown("escape") then love.event.push('q') end end function love.draw() local x1, y1, x2, y2, x3, y3, x4, y4 = Shapes[0]:getBoundingBox() local boxwidth = x3 - x2 local boxheight = y2 - y1 love.graphics.setColor(72, 160, 14) love.graphics.rectangle("fill", Bodies[0]:getX() - boxwidth/2, Bodies[0]:getY() - boxheight/2, boxwidth, boxheight) love.graphics.setColor(123, 77, 64) love.graphics.circle("fill", Bodies[1]:getX(), Bodies[1]:getY(), Shapes[1]:getRadius(), 20) love.graphics.setColor(0, 0, 0) love.graphics.circle("fill", Bodies[1]:getX(), Bodies[1]:getY() + boxheight/4, Shapes[2]:getRadius(), 20) love.graphics.setColor(0, 0, 0) love.graphics.circle("fill", Bodies[1]:getX() + boxwidth/25, Bodies[1]:getY() + boxheight/4, Shapes[3]:getRadius(), 20) love.graphics.setColor(72, 160, 14) love.graphics.rectangle("fill", Bodies[0]:getX() - boxwidth/44, Bodies[0]:getY() - boxheight/8, boxwidth, boxheight) end
Code: Select all
Shapes[0] = love.physics.newRectangleShape(Bodies[0], 0, 0, 750, 50, 0)
...
Shapes[4] = love.physics.newRectangleShape(Bodies[0], 0, 0, 750, 50, 0)
Also, requiring fullscreen = bad. I almost didn't look into your problem because of that.
Kurosuke needs beta testers
- BlackBulletIV
- Inner party member
- Posts: 1261
- Joined: Wed Dec 29, 2010 8:19 pm
- Location: Queensland, Australia
- Contact:
Re: Rectangles
With physical rectangles, one of the best ways to draw shapes exactly how they are is by using PolygonShape:getPoints:tentus wrote:I really recommend tying your drawing code to the actual location of shapes/bodies, rather than hardcoding them where you expect them to be.
Code: Select all
love.graphics.polygon("fill", shape:getPoints())
Who is online
Users browsing this forum: Bing [Bot], Google [Bot] and 10 guests