Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
setTexture and SetTextureRegion incompatibility — Gideros Forum

setTexture and SetTextureRegion incompatibility

I have a bitmap where I want to used both Texture or TextureRegion depending on the state of the game.

But this is the problem:
1. setTexture( put texture region as parameter) = error :(
2. setTextureRegion(put texture as parameter) = error :(

How to fix this? Thanks.
Tagged:

Comments

  • MoKaLuxMoKaLux Member
    edited August 2022
    some sample code please with the setTexture so we can test on our side? o:)
    my growING GIDEROS github repositories: https://github.com/mokalux?tab=repositories
  • @MoKaLux Thanks for the feedback :) Here is the code
    -- for example 1 bitmap and 2 textures (I name it texture_1 and texture_2
     
    texture_1  = Texture.new('images/button.png')
    texture_2  = TextureRegion.new(Texture.new('images/button.png'), 0, 0, 50, 50)
     
    bmp = Bitmap.new(texture_1)
     
    -- then I want to update bmp texture anytime in the game
     
    function update_image(texture_name)
    	bmp:setTexture(texture_name)
    	-- bmp:setTextureRegion() 
    end
     
    update_image(texture_1) --> this works
    update_image(texture_2) --> this is an error. So I need to use bmp:setTextureRegion()
     
    --[[ Is there a way to feed both normal texture  and textureRegion to a Bitmap in a single function?
       Why I need this? :
       My graphics assets are composed of texture atlas and single frame images. Sometimes I need to use the single
      frame image and sometimes I need to use the atlas for a single Bitmap.  
    ]]
  • hgy29hgy29 Maintainer
    Accepted Answer
    No, you can't use the same function for both object types, but you can call the right function according to your parameter:
    function update_image(texture_name)
    	--bmp:setTexture(texture_name)
    	-- bmp:setTextureRegion() 
    	bmp["set"..texture_name:getClass()](bmp,texture_name)
    end
    +1 -1 (+4 / -0 )Share on Facebook
  • Thanks!

    Likes: MoKaLux

    +1 -1 (+1 / -0 )Share on Facebook
  • @hgy29 nice trick, didn't think of that - the beauty of Luau...
    Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!).
    https://deluxepixel.com
Sign In or Register to comment.