Hi :D - How can I add textures to a 'body'?

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
JustaNewbie
Prole
Posts: 2
Joined: Wed Apr 16, 2014 5:39 am

Hi :D - How can I add textures to a 'body'?

Post by JustaNewbie »

Sup guys, hope youre doing great! <3

... sorry to bother here :v BUT

I have a question.

You know the 'Ball&Ground'(Box2d) Tutorial?.

How do you change the ball for an animated object?. Its the walk.love thing attached.
I can't think on anything :| Im blank after 32 hours not sleeping

This is what im using:
http://www.love2d.org/wiki/Tutorial:Physics
Attachments
walk.love
Thats the walk animation I would like to use instead of the red ball :|
(5.14 KiB) Downloaded 119 times
User avatar
Ranguna259
Party member
Posts: 911
Joined: Tue Jun 18, 2013 10:58 pm
Location: I'm right next to you

Re: Hi :D - How can I add textures to a 'body'?

Post by Ranguna259 »

All you need to do is to draw an image on top of the body, you can't actually "apply" a texture to it.
Load your image:

Code: Select all

image = love.graphics.newImage('image.png')
Create your circle body (as explained in the tutorial):

Code: Select all

  objects.ball = {}
  objects.ball.body = love.physics.newBody(world, 650/2, 650/2, "dynamic") --place the body in the center of the world and make it dynamic, so it can move around
  objects.ball.shape = love.physics.newCircleShape( 20) --the ball's shape has a radius of 20
  objects.ball.fixture = love.physics.newFixture(objects.ball.body, objects.ball.shape, 1) -- Attach fixture to body and give it a density of 1.
  objects.ball.fixture:setRestitution(0.9) --let the ball bounce
Draw the image using the circle coordinates in love.draw():

Code: Select all

love.graphics.draw(image, objects.ball.body:getX(),  objects.ball.body:getY(),0 ,1 ,1 , objects.ball.body:getRadius()/2, objects.ball.body:getRadius()/2)
Done, if there's anything you don't undertand just say and I'll try to explain.
LoveDebug- A library that will help you debug your game with an on-screen fully interactive lua console, you can even do code hotswapping :D

Check out my twitter.
JustaNewbie
Prole
Posts: 2
Joined: Wed Apr 16, 2014 5:39 am

Re: Hi :D - How can I add textures to a 'body'?

Post by JustaNewbie »

for some reason the first script i made stoped working... ... ... ... dunno how :l

.. so i started from scartch and;

OMG ! THANKS YOUUUUUUU <3 !

It worked. <3

now its time to get it to move :ultrahappy: :ultrahappy: :ultrahappy: :ultrahappy:
Post Reply

Who is online

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