WiLD Designs
WiLD Designs

Reputation: 21

How to scale only certain objects LOVE2D

This is a problem for the Lua LOVE2D framework.

Whenever I try to set propreties to objects such as color or scaling , it ends up affecting every object in the scene.

For example,

    for i,enemy  in ipairs(enemies) do 
    love.graphics.scale(0.2,0.2)
   love.graphics.draw(enemyImg,enemy.x,enemy.y)

   end  

This scales down not only the enemy object but also all the other objects, anyone know any fix to this?

Upvotes: 2

Views: 615

Answers (2)

Spencer
Spencer

Reputation: 4158

As rpattiso noted in their answer, love.graphics.draw excepts two optional parameters sx and sy that set a specific object's scale factors.

The entire function parameters are:

love.graphics.draw(drawable, x, y, r, sx, sy, ox, oy, kx, ky)

r is the object's rotation, so if you aren't rotating your object just set it to 0.

As for color, love2d will use the last setColor for drawing. So you would need to change the color for each object that needs a new color.

Upvotes: 0

ryanpattison
ryanpattison

Reputation: 6251

The easiest way in your case would be to make use of the optional parameters to draw.

 for _, enemy in ipairs(enemies) do
    love.graphics.draw(enemyImg, enemy.x, enemy.y, 0, --rotation
           enemy.scale)
 end

that way the scale is unique to each enemy.

Upvotes: 1

Related Questions