2013-06-12 51 views
0

我在某些特定位置声明了图像。下拉水龙头图像的动画

local deselectButton = display.newImage ("images/nutritional info/deselectButton.png") 
deselectButton.x = display.contentWidth/2 - 15 
deselectButton.y = display.contentHeight/2 - 172 
deselectButton.id = "0" 
nutriinfo:insert(nutriNavBar) 

当我的形象一敲,我要显示另一幅图像。也就是说,每当我点击上面的图片时,第二张图片就会淡入淡出。

local dropDown1 = display.newImage ("images/nutritional info/dropDown.png") 
dropDown1.x = display.contentWidth/2 - 75 
dropDown1.y = display.contentHeight/2 - 65 
dropDown1:setReferencePoint(display.TopCenterReferencePoint) 
+0

请注明您需要“下拉”或“淡入淡出”或两者在同一时间.. –

+0

两个在同一时间..我已经回答你的答案在下面。 – Vikr

回答

2

你的代码后,只要做如下...这可能会帮助您:

local function addListener() 
    deselectButton:addEventListener("tap",clickFunction) 
end 

local clickCount = 0 
function clickFunction() 
    deselectButton:removeEventListener("tap",clickFunction) 
    clickCount = clickCount + 1 
    if(clickCount%2==1)then 
    -- show the image 
    transition.to(dropDown1,{time=200,x=dropDown1.x,y=dropDown1.y+100,alpha=1,onComplete=addListener}) -- or parameters as you like 
    else 
    -- hide the image 
    transition.to(dropDown1,{time=200,x=dropDown1.x,y=dropDown1.y-100,alpha=0,onComplete=addListener}) 
    end 
end 
deselectButton:addEventListener("tap",clickFunction) 

注:上面的代码为您提供了两个下拉以及淡入/淡出影响。但是,如果您只需淡入淡出效果,则可以从过渡中消除y参数,并且如果需要下拉式效果,则可以消除alpha参数。

保持编码............... :)

+0

krs,​​感谢您的帮助。代码正在工作,但有一个问题。当我点击第一个图像很快..第二个图像显示,它不会淡出/隐藏,当我再次点击第一个图像.. – Vikr

+0

@Vikr:我编辑了代码... –