如何使按钮保持使用电晕pressed [英] How to make buttons stay pressed using corona

查看:208
本文介绍了如何使按钮保持使用电晕pressed的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让我的按钮留pressed一旦它被释放。现在我使用电晕改进的按键模块和我有默认的图像是寻找未pressed按钮,过图像被看起来pressed图像所取代。

I am trying to get my buttons to stay "pressed" once it is released. Right now I am using the improved Buttons Module for corona and I have the default image being the button looking unpressed, and the over image being replaced by an image that looks pressed.

我所试图做的是,一旦该按钮是pressed,它停留过的图像上。这里是我的code是如何设置的,我在测试它的按钮。

What I am trying to do is once the button is pressed, it stays on the over image. Here is how my code is set up for the button I am testing it on.

local digButton = buttons.newButton{
    default = "digButton.png",
    over = "digButtonPressed.png",
    onEvent = digButtonFunction,
    id = "dig"
    }
    digButton:setReferencePoint(display.CenterReferencePoint)
    digButton.x = display.contentWidth/5
    digButton.y = display.contentHeight/1.9

另外,我有一个函数(digButtonFunction),设置该按钮的ID给一个变量被用于运行,如果当用户下这一个按下按钮的声明。

Also, I have a function (digButtonFunction) that sets the id of this button to a variable to be used to run an if statement for when the user pushes a button following this one.

推荐答案

这听起来像你对我真正想要的是一个开关。按钮是不是真的从UI设计的角度来做到这一点。向下状态是那里只是为了反馈给一些动作发生的用户。

This sounds to me like what you really want is a switch. Buttons are not really designed from a UI perspective to do that. The down-state is there just to give feedback to the user that some action happened.

如果是我的话,我倒是不使用按钮位可言,但使用display.newImageRect(加载到图像)和先画出唐斯泰特,那么北部。建立在每一个,将隐藏一个或其他的触摸事件侦听器。我为我的ON / OFF按钮的声音做这在我的游戏。

If it were me, I'd not use the button bit at all, but load in to images using display.newImageRect() and draw the downstate first, then the upstate. Built a touch event listener on each one that will hide one or the other. I do this in my games for my sound on/off buttons.

local soundOn = true 
local soundOnBtn, soundOffBtn

local function soundToggle(event)
    if soundOn then
        soundOn = false
        soundOnBtn.isVisible = false
        soundOffBtn.isVisible = true
    else
        soundOn = true
        soundOnBtn.isVisible = true
        soundOffBtn.isVisible = false
    end
    return true
end
soundOnBtn = display.newImageRect("images/switch_on.png", 46, 36)
soundOnBtn.x = display.contentWidth / 2 + 25
soundOnBtn.y = display.contentHeight / 2 - 15
group:insert(soundOnBtn)
soundOnBtn:addEventListener("tap", soundToggle)

soundOffBtn = display.newImageRect("images/switch_off.png", 46, 36)
soundOffBtn.x = display.contentWidth / 2 + 25
soundOffBtn.y = display.contentHeight / 2 - 15
group:insert(soundOffBtn)
soundOffBtn:addEventListener("tap", soundToggle)


soundOffBtn.isVisible = false

这篇关于如何使按钮保持使用电晕pressed的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆