Only one of many objects is drawn
Posted: Sun Mar 10, 2013 1:57 pm
Hi guys,
I'm trying to program enemies, but i've run into a little problem. Right now, the object for the enemies is very basic - a body with some functions to get coordinates and sprite. Here is the code for the object
Then I spawn some of this objects with
I will probably use arrays later on but for now i use this for testing.
Here is where the problem appears, no matter how many of these objects i have spawned, only one thing will be drawn on the screen by using
Always, one of the objects is drawn, the other one behaves correctly with collision and other physics stuff, but it appears invisible.
Thanks and I hope that im not being annoying with my struggles.
I'm trying to program enemies, but i've run into a little problem. Right now, the object for the enemies is very basic - a body with some functions to get coordinates and sprite. Here is the code for the object
Code: Select all
function spawnEnemy(enemyx,enemyy)
enemy = {}
enemy.body = love.physics.newBody(world, enemyx, enemyy, "dynamic")
enemy.shape = love.physics.newCircleShape(15)
enemy.fixture = love.physics.newFixture(enemy.body, enemy.shape, 1)
enemy.fixture:setRestitution(0.3)
enemy.graphic = enemyr
function enemy.setImage(Image)
enemy.graphic = Image
end
function enemy.getImage()
return enemy.graphic
end
function enemy.getX()
return enemy.body:getX()
end
function enemy.getY()
return enemy.body:getY()
end
function enemy.getXY()
return enemy.body:getX() .. enemy.body:getY()
end
return enemy
end
Code: Select all
enemy1 = spawnEnemy(150,500)
enemy2 = spawnEnemy(500,500)
Here is where the problem appears, no matter how many of these objects i have spawned, only one thing will be drawn on the screen by using
Code: Select all
love.graphics.draw(enemy1:getImage(),enemy1:getX(),enemy1:getY())
love.graphics.draw(enemy2:getImage(),enemy2:getX(),enemy2:getY())
Thanks and I hope that im not being annoying with my struggles.