Help with newChainShape()

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
User avatar
tavuntu
Citizen
Posts: 65
Joined: Mon Dec 24, 2012 6:56 am
Contact:

Help with newChainShape()

Post by tavuntu »

Hi everyone, I'm trying to make something like a tray to contain a bouncing ball (like a 'U' with the shape of a square) but I get the incorrect filling.

Code: Select all

function love.load()
  metro=100
  fuerza=600
  grv=9.81
  ancho=640
  alto=480
  rebote=0.8
  densidad=1
  gp=10 -- thickness of the walls and floor.
  love.physics.setMeter(metro) 
  world = love.physics.newWorld(0,grv*metro, true) 

  objects = {}
  --bola:
  objects.ball={}
  objects.ball.body = love.physics.newBody(world,ancho/2,alto/2,"dynamic") 
  objects.ball.shape = love.physics.newCircleShape(40) --Radio en pixeles
  objects.ball.fixture = love.physics.newFixture(objects.ball.body, objects.ball.shape,densidad) 
  objects.ball.fixture:setRestitution(rebote)
  --paredes:
  objects.paredes={}
  objects.paredes.cuerpo=love.physics.newBody(world,0,0)
  objects.paredes.forma=love.physics.newChainShape(true,0,0, gp,0, gp,alto-gp, ancho-gp,alto-gp, ancho-gp,0, ancho,0, ancho,alto, 0,alto)
  objects.paredes.fixture=love.physics.newFixture(objects.paredes.cuerpo,objects.paredes.forma)
  
  love.graphics.setBackgroundColor(0,0,0) 
  love.graphics.setMode(ancho,alto,false,true,0) 
end

function love.update(dt)
  world:update(dt) 
  if love.keyboard.isDown("right") then 
    objects.ball.body:applyForce(fuerza,0) end
  if love.keyboard.isDown("left") then 
    objects.ball.body:applyForce(-fuerza,0) end
  if love.keyboard.isDown("up") then 
    objects.ball.body:applyForce(0,-fuerza) end
  if love.keyboard.isDown("down") then 
    objects.ball.body:applyForce(0,fuerza) end
end

function love.draw()
  love.graphics.setColor(0,80,180)
  love.graphics.polygon("fill",objects.paredes.cuerpo:getWorldPoints(objects.paredes.forma:getPoints()))
  love.graphics.setColor(0,200,0)
  love.graphics.circle("fill", objects.ball.body:getX(), objects.ball.body:getY(), objects.ball.shape:getRadius())
end
And I want this: http://img204.imageshack.us/img204/5307/imgox.png

Thank you very much.
User avatar
Boolsheet
Inner party member
Posts: 780
Joined: Wed Dec 29, 2010 4:57 am
Location: Switzerland

Re: Help with newChainShape()

Post by Boolsheet »

From love.graphics.polygon:
Note: when in fill mode, the polygon must be convex and simple or rendering artifacts may occur.
Your polygon for the ChainShape is concave.
Shallow indentations.
User avatar
tavuntu
Citizen
Posts: 65
Joined: Mon Dec 24, 2012 6:56 am
Contact:

Re: Help with newChainShape()

Post by tavuntu »

OOOOOh I see, somthing like this: http://www.stanford.edu/~sorgera/cave.jpg

Thanks a lot :awesome:
Post Reply

Who is online

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