I'm building a board game and i need to load the same image several times:
I have my images in a table like
--images on a table
Lateral = {Bitmap.new(Texture.new("images/ima1.jpg")),Bitmap.new(Texture.new("images/iman.jpg"))}
--wanna add images to a position where that image is needed
Lateral[1]:setPosition(40,40)
stage:addChild(Lateral[1])
--at this point no problem
The problem is that i need the same image to be in another position at the same time. The same image is needed in different places on my board game. I created a table because I need to keep track of all the images.
There is a way to load my images
Comments
You use a Texture to make a reference to an instance of an image in memory and a Bitmap to make a reference to an object that represents that image (or part of it) when it's drawn on the screen.
As ar2rsawseen's example shows you can have many different bitmaps all being created using the same texture - it just means they all "reference" the same image, so a Texture can be used by many different Bitmaps but each Bitmap can only reference one texture (at a time).
Hope this helps
Jon...
#MakeABetterGame! "Never give up, Never NEVER give up!" - Winston Churchill
http://www.giderosmobile.com/forum/uploads/FileUpload/16/59b5b1bf1f96f28d40f6fd66c79f56.rar
For checkers I use table of sprites. Every sprite in table have self Bitmap. Usage of Sprites is more flexible than Bitmap. You may create your own functions for sprites. In this example is function Chckr:rotate(cent_x, cent_y, my_angle) which rotate checker around point (cent_x, cent_y) by an angle my_angle. It's like OOP.
Sprite may contain some Bitmaps, make animation or show defined image depending of sprite state, etc.
In this code I use only checkers type A. It may be another table for chekers type B with another bitmaps.
Maybe it helps you.
Likes: atilim, chipster123
AlexRu pretty good example, thanks.
My board game is a version of Mankala. My hole animation is based on loading images on the screen.
Likes: gorkem
Label2[1]:setText("".. Comp_Seeds) ---label to show computer seeds
Label2[1]:setPosition(40, 48)
stage:addChild(Label2[1])
if (pedras_Comp>22) then
Lateral22 = Bitmap.new(Lateral[23]) --load the texture with the image 22 seeds
Lateral22:setPosition(10,50)
stage:addChild(Lateral22)
else
Lateral22 = Bitmap.new(Lateral[pedras_Comp + 1]) --find the number of seed to load
Lateral22:setPosition(10,50)
stage:addChild(Lateral22)
end
Label2[2]:setText("".. Player_Seeds) --label to show player seeds
Label2[2]:setPosition(570,210)
stage:addChild(Label2[2])
if (pedras_Jog>22) then
Lateral22j = Bitmap.new(Lateral[23])
Lateral22j:setPosition(535,50)
stage:addChild(Lateral22j)
else
Lateral22j = Bitmap.new(Lateral[pedras_Jog + 1])
Lateral22j:setPosition(535,50)
stage:addChild(Lateral22j)
end
Label[1]:setText("".. boardInicial[1]) --first hole for the player side. I have a table
and a image to load acording to the number of seeds
Label[1]:setPosition(120,210)
stage:addChild(Label[1])
if (boardInicial[1]>12) then
Hole1 = Bitmap.new(hole[12])
Hole1:setPosition(85,125)
stage:addChild(Hole1)
else
Hole1 = Bitmap.new(Hole[boardInicial[1]+1])
Hole1:setPosition(85,125)
stage:addChild(Hole1)
end
.
.
.
I guess I have to make it sprites instead of just just Bitmap. What you guys think.
1. Hole_Sprite and Seed_Sprite.
2. Two tables 1..6 of Player_1 and Player_2 Hole_Sprites. Maybe one table 1..12 if information about whom this hole will be in Hole_Sprites.
3. Table 1..36 of Seed_Sprites. Seed_Sprites may have different images.
4. Animation is Seed_Sprites moving.
It's for Kalah. Good game
Just wondered if specifying the texture once is better than doing it twice as in the following where someimg.jpg is the same image:
Thanks
Pete
Likes: ar2rsawseen