Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
What's the proper code for adding and centering two or more bitmaps in the same sprite? — Gideros Forum

What's the proper code for adding and centering two or more bitmaps in the same sprite?

I thought this would've been straightforward to so but unfortunately I can't seem to get it to work. I'm adding two or more bitmaps to one sprite like the code below. But only the first gets centered properly. Not the subsequent ones. Why is that. What am I missing here?

Why isn't the lock bitmap centered like the btn Bitmap is?


local Button1 = Sprite.new()

local btn_p = mydata.Base:getTextureRegion("Level_Btn.png")
local btn = Bitmap.new(btn_p)
btn:setColorTransform(129/255,129/255,129/255)
Button1:addChild(btn)

local lock = mydata.Base:getTextureRegion("gameBLock.png") ,
local lock = Bitmap.new(lock)
lock:setColorTransform(255/255,129/255,129/255)
Button1:addChild(lock)


<span class="sy0"><</span>img src<span class="sy0">=</span><span class="st0">"http://forum.giderosmobile.com/uploads/editor/1m/gwjsu82y515o.png"</span> alt<span class="sy0">=</span><span class="st0">""</span> <span class="sy0">/></span>

Comments

  • MoKaLuxMoKaLux Member
    edited May 2019
    hello there,

    Your code is a little messy, for example :

    local lock = mydata.Base:getTextureRegion("gameBLock.png") ,
    local lock = Bitmap.new(lock)
    You are using the same name for the variable! + there is a comma at the end of the line!

    To center both images you can try the setAnchorPoint(0.5, 0.5) for both your buttons.

    Some sample code:
    local Button1 = Sprite.new()
     
    local btn_p = Texture.new("gfx/button01.png")
    local btn = Bitmap.new(btn_p)
    btn:setColorTransform(129/255,129/255,129/255)	
    btn:setAnchorPoint(0.5, 0.5)
    Button1:addChild(btn)
     
    local lock_p = Texture.new("gfx/enemy01.png")
    local lock = Bitmap.new(lock_p)
    lock:setColorTransform(255/255,129/255,129/255)
    lock:setAnchorPoint(0.5, 0.5)
    Button1:addChild(lock)
     
    Button1:setPosition(200, 200)
    stage:addChild(Button1)
    Hope that help!

    Peace.



    image.png
    154 x 72 - 3K
    my growING GIDEROS github repositories: https://github.com/mokalux?tab=repositories
  • pm1891pm1891 Member
    Thank you so much for solving this problem so quickly. I feel like a complete idiot but you're awesome. Thank you.

    Likes: MoKaLux, antix

    +1 -1 (+2 / -0 )Share on Facebook
Sign In or Register to comment.