Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Display a Texture Pack as two separate objects — Gideros Forum

Display a Texture Pack as two separate objects

MillerszoneMillerszone Member
edited October 2011 in General questions
The game has two score digits, a left and right. With the code below, everything works ok,
but when I display the SAME digit number for left and right, the left number does not show.
Will I have to make two scoreDigits tables, a left and right?
local scorePack = TexturePack.new("images/scoreDigits.txt", "images/scoreDigits.png")
 
scoreDigits = { 
	Bitmap.new(scorePack:getTextureRegion("score00.png")),
	Bitmap.new(scorePack:getTextureRegion("score01.png")),
	Bitmap.new(scorePack:getTextureRegion("score02.png")),
	Bitmap.new(scorePack:getTextureRegion("score03.png")),
	Bitmap.new(scorePack:getTextureRegion("score04.png")),
	Bitmap.new(scorePack:getTextureRegion("score05.png")),
	Bitmap.new(scorePack:getTextureRegion("score06.png")),
	Bitmap.new(scorePack:getTextureRegion("score07.png")),
	Bitmap.new(scorePack:getTextureRegion("score08.png")),
	Bitmap.new(scorePack:getTextureRegion("score09.png")),
	Bitmap.new(scorePack:getTextureRegion("score10.png")),
	Bitmap.new(scorePack:getTextureRegion("score11.png")),
}
 
leftScoreDigits = {}
rightScoreDigits = {}
 
for i = 1, 12 do
	leftScoreDigits[i] = scoreDigits[i]
	rightScoreDigits[i] = scoreDigits[i]
end
 
-- I'm using the digit 12 for both, so the left score digit won't show.
-- Using different numbers, both score digits will show.
leftScoreDigits[12]:setPosition(165, 25)
stage:addChild(leftScoreDigits[12]) 
 
rightScoreDigits[12]:setPosition(265, 25)
stage:addChild(rightScoreDigits[12])

Comments

  • atilimatilim Maintainer
    Because a sprite can only have one parent. If you add a sprite that already has a different sprite as a parent, the sprite is removed from the child list of the other sprite. Therefore, you need to create different Bitmaps for left and right scores.
  • O.k, I kind of figured I might have to make to separate score tables.
    local scorePack = TexturePack.new("images/scoreDigits.txt", "images/scoreDigits.png")
     
    local leftScoreDigit = { 
    	Bitmap.new(scorePack:getTextureRegion("score00.png")),
    	Bitmap.new(scorePack:getTextureRegion("score01.png")),
    	Bitmap.new(scorePack:getTextureRegion("score02.png")),
    	Bitmap.new(scorePack:getTextureRegion("score03.png")),
    	Bitmap.new(scorePack:getTextureRegion("score04.png")),
    	Bitmap.new(scorePack:getTextureRegion("score05.png")),
    	Bitmap.new(scorePack:getTextureRegion("score06.png")),
    	Bitmap.new(scorePack:getTextureRegion("score07.png")),
    	Bitmap.new(scorePack:getTextureRegion("score08.png")),
    	Bitmap.new(scorePack:getTextureRegion("score09.png")),
    	Bitmap.new(scorePack:getTextureRegion("score10.png")),
    	Bitmap.new(scorePack:getTextureRegion("score11.png")),
    }
     
    local rightScoreDigit = { 
    	Bitmap.new(scorePack:getTextureRegion("score00.png")),
    	Bitmap.new(scorePack:getTextureRegion("score01.png")),
    	Bitmap.new(scorePack:getTextureRegion("score02.png")),
    	Bitmap.new(scorePack:getTextureRegion("score03.png")),
    	Bitmap.new(scorePack:getTextureRegion("score04.png")),
    	Bitmap.new(scorePack:getTextureRegion("score05.png")),
    	Bitmap.new(scorePack:getTextureRegion("score06.png")),
    	Bitmap.new(scorePack:getTextureRegion("score07.png")),
    	Bitmap.new(scorePack:getTextureRegion("score08.png")),
    	Bitmap.new(scorePack:getTextureRegion("score09.png")),
    	Bitmap.new(scorePack:getTextureRegion("score10.png")),
    	Bitmap.new(scorePack:getTextureRegion("score11.png")),
    }
     
    -- Display left and right score digit image
    leftScoreDigit[1]:setPosition(165, 25)
    stage:addChild(leftScoreDigit[1]) 
     
    rightScoreDigit[1]:setPosition(265, 25)
    stage:addChild(rightScoreDigit[1])
    Thanks for the Quick reply!
Sign In or Register to comment.