I am trying to create “radio buttons” with 2 images. What I am trying to do is make it so when you click a button it changes to a lighter image, and then when you click that lighter image it turns back to the darker image. I want this to happen an infinate amount of times so they could technically do it all day without restarting the app. Anyone know a simple solution to this.
local sunroof = display.newImageRect("images/sunroof.png", displayWidth, 60);
sunroof:setReferencePoint(display.CenterReferencePoint);
sunroof.x = displayWidth/2; sunroof.y = sunroof.height \* 2 + title.height \* 1.5 -50;
function rectlistener()
sunroof:removeSelf()
sunroof = display.newImageRect("images/sunroofClicked.png", displayWidth, 60);
sunroof:setReferencePoint(display.CenterReferencePoint);
sunroof.x = displayWidth/2; sunroof.y = sunroof.height \* 2 + title.height \* 1.5 -50;
sunroof:removeSelf()
sunroof = display.newImageRect("images/sunroof.png", displayWidth, 60);
sunroof:setReferencePoint(display.CenterReferencePoint);
sunroof.x = displayWidth/2; sunroof.y = sunroof.height \* 2 + title.height \* 1.5 -50;
end
This is so far my code but i have no clue on what to do now.
Thanks [import]uid: 153468 topic_id: 27777 reply_id: 327777[/import]
Danny
June 20, 2012, 8:57am
2
Sure, how about this (basic example, untested):
local sunroof = display.newImageRect("images/sunroof.png", displayWidth, 60);
sunroof:setReferencePoint(display.CenterReferencePoint);
sunroof.x = displayWidth/2; sunroof.y = sunroof.height \* 2 + title.height \* 1.5 -50;
local sunroofToggle = 0
local sunroofOver = display.newImageRect("images/sunroofClicked.png", displayWidth, 60);
sunroofOver:setReferencePoint(display.CenterReferencePoint);
sunroofOver.x = displayWidth/2; sunroofOver.y = sunroofOver.height \* 2 + title.height \* 1.5 -50;
sunroofOver.isVisible = false
local function toggleImage(event)
sunroofToggle = 1 - sunroofToggle
if sunroofToggle == 0 then
sunroof.isVisible = true
sunroofOver.isVisible = false
else
sunroof.isVisible = false
sunroofOver.isVisible = true
end
return true
end
sunroof:addEventListener("tap", toggleImage)
sunroofOver:addEventListener("tap", toggleImage)
Untested [import]uid: 84637 topic_id: 27777 reply_id: 112523[/import]
Thanks for getting back to me!!!
That looks great but when I put that into my code all it says is: “Assertion Failed!”
I am new to this language and I dont know what that means? Any ideas? [import]uid: 153468 topic_id: 27777 reply_id: 112529[/import]
Danny
June 20, 2012, 9:41am
4
Do you have those images with the exact same filename in the root directory of your project?
Can you post the entire log from the console?
Thanks [import]uid: 84637 topic_id: 27777 reply_id: 112533[/import]
Yes i have the images in the root folder but the console error is:
Director ERROR: Failed to execute new< params > function on ‘car_accessories’ - assertion failed! [import]uid: 153468 topic_id: 27777 reply_id: 112537[/import]
Danny
June 20, 2012, 9:51am
6
Ah ok. Can you post up the contents of that file? [import]uid: 84637 topic_id: 27777 reply_id: 112538[/import]
Of the director file? [import]uid: 153468 topic_id: 27777 reply_id: 112543[/import]
Danny
June 20, 2012, 10:07am
8
Whichever file is giving the error [import]uid: 84637 topic_id: 27777 reply_id: 112544[/import]
This is the part of the code that is getting the error.
[code]
for i = currentStage.numChildren, 1, -1 do
– Verify directorId
if type( currentStage[i].directorId ) == “nil” then
currentStage[i].directorId = newScene
end
– Insert into the NEXT group if it’s needed
if currentStage[i].directorId == newScene
and currentStage[i].directorId ~= “main” then
nextScreen:insert( currentStage[i] )
end
end
[/code] [import]uid: 153468 topic_id: 27777 reply_id: 112548[/import]
Well it looks like it is working great with the code you gave me!!! Thanks so much!!!
It still is saying assertion error when i start the page though. [import]uid: 153468 topic_id: 27777 reply_id: 112567[/import]
My mistake! I figured it out and it is working perfectly! Thanks so much! [import]uid: 153468 topic_id: 27777 reply_id: 112574[/import]
Danny
June 21, 2012, 1:54am
12
Your welcome [import]uid: 84637 topic_id: 27777 reply_id: 112625[/import]