Hey guys,
I can’t work this one out and man have I tried. If the argument is true then I want the attackButton to be the only thing the user can select. They have to hold it down otherwise the attack finishes. It semi-works but only if the user keeps their finger directly over the button when they release or presses the button then lets their finger roam bringing it back to rest directly over attack button then release. Also my joystick is still selectable the whole time. Not good, I want the joystick disabled.
Any help would be greatly appreciated
Here I create the attackButton
[lua]—Create Attack Button
attackButton = ui.newButton{
defaultSrc = “AttackButton.png”,
defaultX = 51,
defaultY = 51,
overSrc = “Attack-Button-Pressed.png”,
overX = 51,
overY = 51,
onEvent = attackButtonHandler,
id = “attackButton”,
text = “”,
font = “Helvetica”,
textColor = { 255, 255, 255, 255 },
size = “”,
emboss = false
}
attackButton.x = 420; attackButton.y = 250;
hudGroup:insert(attackButton)[/lua]
Here is it onEvent Function
[lua]function attackButtonHandler(event)
if event.phase == “press” and smallShip1HitPossible == true and attackPossible == true then
local attackButton = event.target
player.isVisible = false
player.isActive = false
smallShip1.isVisible = false
display.getCurrentStage():setFocus( attackButton, event.id )
local reducesmallShip1Health = function()
if smallShip1HitPossible == true and smallShip1Health >= 1 then
smallShip1Health = smallShip1Health -10
elseif smallShip1HitPossible == true and smallShip1Health <= 1 then
timer.cancel(smallShip1CollisionTimer)
player.isVisible = true
attacksheet:dispose()
smallShip1:removeSelf()
timer.cancel(playerCollisionTimer)
attackPossible = false
smallShip1HitPossible = false
end
end
smallShip1CollisionTimer = timer.performWithDelay(500, reducesmallShip1Health,0)
attacksheet = sprite.newSpriteSheet(“attack.png”, 55, 169)
attackset = sprite.newSpriteSet (attacksheet, 1, 2)
sprite.add (attackset, “grab”, 1, 2, 300, 0)
sprite.add (attackset, “attack”, 2, 2, 300, 0)
newAttack = sprite.newSprite (attackset)
newAttack.x = smallShip1.x
newAttack.y = smallShip1.y
newAttack:prepare(“grab”)
newAttack:play(“attack”)
camera:insert(newAttack)
elseif event.phase == “release” and attackPossible == true then
display.getCurrentStage():setFocus(attackButton, nil)
smallShip1HitPossible=false
if smallShip1HitPossible==false then
if(smallShip1CollisionTimer~=nil) then – just to be safe
timer.cancel(smallShip1CollisionTimer)
end
end
player.isVisible = true
smallShip1.isVisible = true
attacksheet:dispose()
end [/lua] [import]uid: 26289 topic_id: 13631 reply_id: 313631[/import]
[import]uid: 3826 topic_id: 13631 reply_id: 50056[/import]