Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

change alpha property value of image from event function
Started by aonyn Jan 24 2010 09:12 AM

- - - - -
2 replies to this topic
[TOPIC CONTROLS]
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

aonyn

[GLOBAL: userInfoPane.html]
aonyn
  • Observer

  • 23 posts
  • Guests

Hi,

I just encountered something which may be a bug, but I am not sure.
I need to change the alpha property of an image using a slider control.

I have tried several different things, all of which work on the simulator, none of which will work on the iphone device.
I have had it so the alpha changes in realtime as the slider moves, so that it changes instantly when the touch event ends, and also as a transition when the touch event ends.

Here is some sample code of what I am trying to do.
If someone can help, I would appreciate, unless perhaps I indeed have found a bug, in which case hopefully it can be fixed.

-- Begin Code
centerX = display.stageWidth * 0.5

local function dragSlide(event)
local stage = display.getCurrentStage()
local img2 = stage[2]
local slide = event.target
local phase = event.phase
if phase == "moved" then
if event.x >= 40 and event.x <= 280 then
slide.x = event.x
end
elseif phase == "ended" then
local picAlpha = (slide.x - 40) * 0.004167
if picAlpha > 1.0 then
picAlpha = 1.0
elseif picAlpha < 0.0 then
picAlpha = 0.0
end
--img2.alpha = picAlpha
transition.to(img2, {time=1000, alpha=picAlpha})
end
return true
end

local img1 = display.newImage("img1.jpg", 0, 0)
local img2 = display.newImage("img2.jpg", 0, 0)
img2.alpha = 0.5

local slide = display.newRect(0, 0, 20, 40)
slide:setFillColor(255, 255, 255)
slide.x = centerX
slide.y = 440
slide:addEventListener("touch", dragSlide)
-- End Code

Thanks,
Dave
uid: 3948 topic_id: 411 reply_id: 300411


[TOPIC: post.html]
#2

carlos m. icaza

[GLOBAL: userInfoPane.html]
carlos m. icaza
  • Corona Geek

  • 2,992 posts
  • Alumni

I have the same issue you are having when i test on my iphone

will give you an update soon as to what we will do next

carlos
uid: 24 topic_id: 411 reply_id: 753


[TOPIC: post.html]
#3

aonyn

[GLOBAL: userInfoPane.html]
aonyn
  • Observer

  • 23 posts
  • Guests

Thanks again Carlos.

regards,
Dave
uid: 3948 topic_id: 411 reply_id: 758



[topic_controls]
[/topic_controls]