Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Bitmap setTexture vs setTextureRegion — Gideros Forum

Bitmap setTexture vs setTextureRegion

amaximovamaximov Member
edited November 2013 in General questions
So I realize that there are Texture and TextureRegion classes the latter of which extracts subtextures from Texture. However I'm wondering if on the native side these are viewed as objects of the same class and if its ok to do Bitmap:setTextureRegion(Texture.new(....)) and Bitmap:setTexture(TextureRegion.new(...))

Comments

  • ar2rsawseenar2rsawseen Maintainer
    edited November 2013
    @amaximov unfortunately no, they are not the same.
    If you look at the docs, you will see that Texture is actually subclass of TextureBase
    And TexturePack is also subclass of TextureBase, so they can be counted as same.

    But TextureRegion is a superclass on its own, completely different. Thus there are two different methods (Bitmap:setTexture and Bitmap:setTextureRegion).

    What you could do is try to check instance of which type is passed to method, and then call corresponding sub method.

    Which I think could look like:
    Bitmap._setTexture = Bitmap.setTexture
     
    function Bitmap:setTexture(texture)
        if getmetatable(texture) == TextureRegion then
            self:setTextureRegion(texture)
        else
            self:_setTexture(texture)
        end
    end
  • @amaximov that was just form the top of my head, still you'd need to try if that works :)
Sign In or Register to comment.