How do I can program the bouncy material?

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.
Post Reply
User avatar
MD
Prole
Posts: 10
Joined: Sat Oct 31, 2009 2:56 am
Location: Spain
Contact:

How do I can program the bouncy material?

Post by MD »

Well, I testing and learn löve, and I try programe a two material (ball over the rectangle) and the bouncing, but only the ball don't bounce.

The sourcecode is:

Code: Select all

function load()
	world = love.physics.newWorld( 2000, 2000)
	world:setGravity(0, 50)
	love.graphics.setBackgroundColor( 255, 255, 255)
	ground = love.physics.newBody(world, 0, 0, 0) 
	
	ground_shape = love.physics.newRectangleShape(ground, 400, 500, 600, 10)
	body = love.physics.newBody(world, 400, 200, 9999)
	circle_shape = love.physics.newCircleShape(body, 50)
	
	font = love.graphics.newFont(love.default_font, 12)
	love.graphics.setFont(font)
end

function update(dt) 
	-- Update the world. 
	world:update(dt)

       --I search the "bounce" factor
	text = body:getAngularDamping() 
end 

function draw()
	love.graphics.setColor( 0, 0, 255) 
	love.graphics.polygon(love.draw_line, ground_shape:getPoints()) 
	love.graphics.setColor( 255, 0, 0) 
	love.graphics.circle( love.draw_fill, body:getX(), body:getY(), 50)

	love.graphics.draw(text, 100, 100)
end
Finnally, How do I make a best ball? Because the love.graphics.circle make a ball with corners.
User avatar
MD
Prole
Posts: 10
Joined: Sat Oct 31, 2009 2:56 am
Location: Spain
Contact:

Re: How do I can program the bouncy material?

Post by MD »

I found two method to bouncy ball:
by hand programming:

In another code add the collision callback

Code: Select all

function load()
...
world:setCallback(collision)
...
end

...

function collision(a, b, c)
	body:applyImpulse(0, -5000)
end
by physic löve api:

And after, I searched but I searched in deep in the documentation...and I found setRestitution() that it apply to shapes...in previous source code:

Code: Select all

function load()
...
	circle_shape:setRestitution(1)
...
end

...
And that's all. Now I try spin object and some other things.
Post Reply

Who is online

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