Issues

Issue #571 wontfix

Add draw method for drawable types

Minh Ngo
created an issue

Image:draw(...), Canvas:draw(...), etc. Would be a nice option for object oriented people.

Comments (2)

  1. hahawoo
    image:draw(100, 100)
    love.graphics.draw(image, 100, 100)
    

    There's less text to read (assuming love.graphics.draw isn't shortened).

    Maybe it doesn't read so well in some ways though?

    love.graphics.setBackgroundColor(255, 255, 255)
    love.graphics.draw(img, 100, 100)
    height = img:getHeight()
    love.graphics.draw(image, 100, 100)
    love.graphics.draw(this_is_an_image, 100, 100)
    
    love.graphics.setBackgroundColor(255, 255, 255)
    img:draw(100, 100)
    height = img:getHeight()
    image:draw(100, 100)
    this_is_an_image:draw(100, 100)
    

    Or maybe it does.

    I'd say this is similar to using Source methods instead of functions: #483

    While I think there should be only one way to draw objects/play Sources, I'm not sure which way is best...

    A consistency could be made which says "functions which pertain to a single LÖVE object and don't affect the global state are methods". If Drawables had draw methods instead of love.graphics.draw, and Source control functions were removed, I think this might be true.

    Or maybe even "functions which pertain to a single LÖVE object are methods"...

    font = love.graphics.newFont('font.ttf', 12)
    font:set()
    

    Or maybe "functions which are conceptually about the object are methods"... maybe the screen is conceptually different from an Image, and whatever is playing through the speakers is conceptually different from a Source... this seems pretty clear for things like Image:getHeight, or ParticleSystem methods... maybe less clear for something like Font:getWrap...

    I have noooooo idea. :D

  2. Bart van Strien

    The problem though, is that the drawing depends on external state, most notably the color and render target/canvas, therefore the draw method wouldn't have consistent behaviour..

  3. Log in to comment