Hi all,
I have a game I’ve made in Engine001, and I’m trying to make it an app. I just modified “Rolling the Dice” as best I could, but for some reason only die 1 is different from the others; 2, 3, 4, and 5 always come out the same even though I’ve changed up the cycling time (195, 210, etc.) for each . Would someone be able to help?
Thanks,
Lionel
[lua]module(…, package.seeall)
require “sprite”
function new()
local localGroup = display.newGroup()
dieSound = audio.loadSound(“dice.mp3”)
local diceSheet = sprite.newSpriteSheet( “dice.png”, 64, 64)
local diceSet = sprite.newSpriteSet( diceSheet, 1, 6 )
sprite.add( diceSet, “dice”, 1, 6, 195, 0)
sprite.add( diceSet, “dice2”, 1, 6, 210, 0)
sprite.add( diceSet, “dice3”, 1, 6, 80, 0)
sprite.add( diceSet, “dice4”, 1, 6, 50, 0) --(Tried changing these third numbers with little luck).
sprite.add( diceSet, “dice5”, 1, 6, 120, 0)
–First Die
local dice = sprite.newSprite( diceSet )
dice.x = 50
dice.y = 50
dice:prepare(“dice”)
–Second Die
local dice2 = sprite.newSprite( diceSet )
dice2.x = 50
dice2.y = 130
dice2:prepare(“dice2”)
–Third Die
local dice3 = sprite.newSprite( diceSet )
dice3.x = 50
dice3.y = 210
dice3:prepare(“dice3”)
–Fourth Die
local dice4 = sprite.newSprite( diceSet )
dice4.x = 50
dice4.y = 290
dice4:prepare(“dice4”)
local dice5 = sprite.newSprite( diceSet )
dice5.x = 50
dice5.y = 370
dice5:prepare(“dice5”)
local canRoll = true
local rollbutton = display.newImage (“roll.png”)
rollbutton.x = 160
rollbutton.y = 150
localGroup:insert(rollbutton)
local function endRoll()
dice:pause()
dice2:pause()
dice3:pause()
dice4:pause()
dice5:pause()
diceTotal = dice4.currentFrame + dice5.currentFrame
print(diceTotal) --Print the result in the terminal
canRoll = true --Allow the dice to be rolled again
end
local function dieRoll (event)
if canRoll == true then
canRoll = false
dieChannel = audio.play( dieSound )
dice:play()
dice2:play()
dice3:play()
dice4:play()
dice5:play()
randomTime = math.random(1500, 3500)
timer.performWithDelay(randomTime, endRoll, 1)
end
end
rollbutton:addEventListener (“touch”, dieRoll)
return localGroup
end[/lua] [import]uid: 144359 topic_id: 25489 reply_id: 325489[/import]
It’s freshly discovered, so it should be a loop, but it works now: