how to get the block to spawn multiple times a second

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
eqnox
Prole
Posts: 44
Joined: Fri Jul 31, 2015 2:36 pm

how to get the block to spawn multiple times a second

Post by eqnox »

The title explains a lot. I want to be able to spawn the block below many times a second and they all be different blocks in the world, not just the same block. They will all have the same attributes of block1 but I want to be able to spawn in mass amounts of them, preferably a few a second whilst the left mouse button is held down.

Code: Select all

function love.load()
  love.physics.setMeter(64) 
  world = love.physics.newWorld(0, 9.81*64, true) 
 
  objects = {} 
 
  objects.ground = {}
  objects.ground.body = love.physics.newBody(world, 0, 400, "static") 
  objects.ground.shape = love.physics.newRectangleShape(500, 1) 
  objects.ground.fixture = love.physics.newFixture(objects.ground.body, objects.ground.shape); 
 
  
  objects.ball = {}
  objects.ball.body = love.physics.newBody(world, 50, 50, "dynamic") 
  objects.ball.shape = love.physics.newCircleShape(20) 
  objects.ball.fixture = love.physics.newFixture(objects.ball.body, objects.ball.shape, 3) 
  objects.ball.fixture:setRestitution(0.8) 



 
  objects.block1 = {}
  objects.block1.body = love.physics.newBody(world, 500, 1, "static")
  objects.block1.shape = love.physics.newRectangleShape(0, 0, 1, 1)
  objects.block1.fixture = love.physics.newFixture(objects.block1.body, objects.block1.shape, 2)

  love.graphics.setBackgroundColor(255, 255, 255) 
  love.window.setMode(500, 400) 
end
 
 
function love.update(dt)
  world:update(dt) 
  if love.mouse.isDown("l") then

end
 
function love.draw()
  love.graphics.setColor(193, 47, 14) 
  love.graphics.circle("fill", objects.ball.body:getX(), objects.ball.body:getY(), objects.ball.shape:getRadius())

  love.graphics.setColor(50, 50, 50)
  love.graphics.polygon("fill", objects.block1.body:getWorldPoints(objects.block1.shape:getPoints()))
end
User avatar
airstruck
Party member
Posts: 650
Joined: Thu Jun 04, 2015 7:11 pm
Location: Not being time thief.

Re: how to get the block to spawn multiple times a second

Post by airstruck »

I'd suggest trying the most obvious thing first, and if it doesn't give the behavior you expect, share what you tried, what you expected and what you observed. Showing the solutions you've attempted will give people context so they can help you more easily.

In this case, the most obvious thing might be writing a function that creates blocks and inserts them into an array, and iterating over that array in love.draw. Have you tried that?
User avatar
eqnox
Prole
Posts: 44
Joined: Fri Jul 31, 2015 2:36 pm

Re: how to get the block to spawn multiple times a second

Post by eqnox »

airstruck wrote:I'd suggest trying the most obvious thing first, and if it doesn't give the behavior you expect, share what you tried, what you expected and what you observed. Showing the solutions you've attempted will give people context so they can help you more easily.

In this case, the most obvious thing might be writing a function that creates blocks and inserts them into an array, and iterating over that array in love.draw. Have you tried that?
thats the part I need help with all the ways I've done it haven't worked yet and I can't find any good examples.
User avatar
MadByte
Party member
Posts: 533
Joined: Fri May 03, 2013 6:42 pm
Location: Braunschweig, Germany

Re: how to get the block to spawn multiple times a second

Post by MadByte »

This shouldn't be that hard.
spawningObjects.love
(487 Bytes) Downloaded 106 times
You should take a deeper look into the offical lua pil and first of learn some basics.
http://www.lua.org/pil/contents.html

And especially the part about tables:
http://www.lua.org/pil/2.5.html
User avatar
eqnox
Prole
Posts: 44
Joined: Fri Jul 31, 2015 2:36 pm

Re: how to get the block to spawn multiple times a second

Post by eqnox »

thanks
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 92 guests