Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
Any chance of a setWidth and setHeight for bitmaps? — Gideros Forum

Any chance of a setWidth and setHeight for bitmaps?

mykyl66mykyl66 Member
edited November 2011 in Announcements
I can see there is a getWidth and getHeight for bitmaps but no set equivalent. This would enable us to do everything, set up images and physics objects, all in one line of code, which we have got working except for the scaling of the images. Basically we want to pass in one size and the body and image would match which having a setWidth etc would allow us to do.

Cheers

Mike
What would you do for your other half?

http://www.sharksoupstudios.com

Comments

  • atilimatilim Maintainer
    edited November 2011
    Hi,

    You can use setScale:
    local originalWidth = bitmap:getWidth()
    local originalHeight = bitmap:getHeight()
    bitmap:setScale(newWidth / originalWidth, newHeight / originalHeight)
  • atilimatilim Maintainer
    edited November 2011
    Also if you're planning to use this frequently, you can add a custom function to Sprite class:

    1. Create init.lua
    2. Implement Sprite:setSize function as:
    function Sprite:setSize(newWidth, newHeight)
      self:setScale(1, 1)  -- to get original width and height without scaling
      local originalWidth = self:getWidth()
      local originalHeight = self:getHeight()
      self:setScale(newWidth / originalWidth, newHeight / originalHeight)
    end
    (side note: the files init.lua and main.lua have special meaning. init.lua is executed first and main.lua is executed last)

    Likes: misterhup

    +1 -1 (+1 / -0 )Share on Facebook
  • Actually after asking this question I figured it out.

    Thanks

    Mike
    What would you do for your other half?

    http://www.sharksoupstudios.com
Sign In or Register to comment.