Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sprite Size Aspect Ratio By Height

edited March 2016 in Suggestions Posts: 18

It would be nice if the function sprite also scale in aspect ratio by height. Currently it's only possible by width.
sprite("image", 0, 0, width) -- without arg height it will be calculated automatically
I want: sprite("image", 0, 0, nil, height) -- error: number expected
It's nice to have. Of course, I also could calculate the ratio size by my own. But is more comfortable to use api.

Comments

  • edited March 2016 Posts: 2,020

    You can override the API if you wish, just make sure you save a reference to whatever you override. eg:

    _sprite = sprite --save the sprite command before overwriting it
    
    function sprite(image, x,y,w,h) -- your new version
      --your code to calculate aspect ratio based on height goes here
      _sprite(image,x,y,w,h) --draw the sprite
    end
    
  • edited March 2016 Posts: 18

    Good idea. Here's my code. It works.

    -- sprite(image, x, y, w, h)
    -- usage: sprite("Documents:mySprite", WIDTH/2, HEIGHT/2, nil, HEIGHT)
    _sprite = sprite
    function sprite(image, x, y, w, h)        
        if w == nil and h ~= nil then
            local sw, sh = spriteSize(image)
            _sprite(image, x, y, (sw / sh) * h, h)
        elseif w ~= nil and h == nil then
            local sw, sh = spriteSize(image)
            _sprite(image, x, y, w, (sh / sw) * w)
        elseif w == nil and h == nil then
            _sprite(image, x, y)
        else
            _sprite(image, x, y, w, h)
        end
    end
    

    But anyway, it should moved to low-level (framework api). :)
    It's not a most important feature. But nice to have. In current version it works only when height is not set.

Sign In or Register to comment.