Hi all…
I’ve been working on my game for about 3000 hours now and I’m in the process of making it look more professional by making the graphics better.
So far I’ve only been using static images but I want to add some animation and I’ve got stuck on the first attempt.
I want to move spinning coins from the centre of the screen to the score graphic. You see them in lots of games.
I created 10 images of a coin in different aspects and iterate through them in a table which works great but moving that animated coin is another story.
I’ve discovered that using timer.perfromWithDelay is too slow even if you set the delay to 1/1000 of a second.
I’ve looked at sprites but I can’t find any tutorials on how to make sprite sheets, I don’t want to buy third party software if it all possible, I want to do it myself to save money because I don’t have much to spare.
Here’s my attempt at moving an animated coin, it moves at a snails pace and I want to have lots of coins.
Any ideas anyone?
Load the 10 coin graphics into a table…
**coinwidth[1] = 63; coinwidth[2] = 48; coinwidth[3] = 39; coinwidth[4] = 25; coinwidth[5] = 16
coinwidth[6] = 5; coinwidth[7] = 16; coinwidth[8] = 25; coinwidth[9] = 39; coinwidth[10] = 48
for i = 1, 10 do
coin[i] = display.newImageRect(“images/goldcoin”…i…".png", coinwidth[i], 66)
coin[i].x = (_W*0.5); coin[i].y = (_H*0.64)
coin[i].isVisible = false
end**
Create a table to hold 10 coins ( each has 10 images )…
**local coinVar = {}
for n = 1, 10 do
coinVar[n] = {}
for i = 1, 10 do
coinVar[n][i] = coin[i]
mainGroup:insert(coinVar[n][i])
end
end**
And make a function to iterate through the coin(s) so they appear to spin…
** local rotateCoins = function()
if i > 1 then
coinVar[m][i-1].isVisible = false
end
if i == 1 then
coinVar[m][10].isVisible = false
end
coinVar[m][i].isVisible = true
i = i + 1
if i == 11 then
i = 1
end
end**
And my attepmt at moving the animated coin(s) across the screen using another function…
l**ocal moveCoins = function()
coinVar[m][i].x = coinVar[m][i].x +1
coinVar[m][i].y = coinVar[m][i].y -1
end
local controlCoins = function()
myTimer = timer.performWithDelay( 5, rotateCoins , 1 )
myTimer = timer.performWithDelay( 5, moveCoins , 1 )
end
myTimer = timer.performWithDelay( 5, controlCoins , 400 )**
In the above code I have the possibilty to have 10 coins on the screen but I’m only moving one for now which moves really really slow across the screen. The spinning animation works great at any speed but it’s the movement that’s the problem.
Any help would be greatly appreciated.