Would either of you like a quick contract to build that imageSheet for me (since I keep spinning my wheels)? I’ve built the radio buttons and checkbox (as well as slider and buttons), but this one has got me. Let me know how much and where to send (paypal or CC in advance is fine), and I’ll email you what I’ve done, which will give you the colors and general idea.
Are your assets arranged as discrete images? I’m asking because I’d like to see them as discrete images before saying whether I can help on this. i.e. I’d like to experiment with them first before committing.
Can you make a small sample, zip it up, and share it with us so we can see what you’re doing? This is the easiest way to get a fix/help.
(Use the full editor when posting and you’ll have the option to attach a zip file.)
2. Your post is a bit hard to read. I’m seeing what looks like at least two questions in there. You might want to consider bullet lists and clear numbered questions in the future. (Lazy folk like myself give up when the post starts to wander or look like a run-on.)
A great format for posts like this is:
What I did.
What I saw.
What I expected to see.
Why I think it is wrong.
What I did to debug it.
( Tip: Provide links; Don’t assume we know what features you’re talking about)
My interpretation of your post:
What you did - You made toggle and radio buttons using image sheets and the widget.* newSwitch() function (always provide links so we can be sure we understand what you mean and are referring to).
You then tried to pre-toggle the state using the setState() function.
What you saw - The state toggled when you called setState(), but when you later clicked the button… something went wrong. This is where I’m unclear.
Yea, I thought so too. However, the sample code is so small, I see nothing that’s out of line. It is literally a side-by-side. It’s easy to see the image sheet one not move on the first tap, while the onRelease function reporting the event.
Also on startup, you easily see the std shows false, and the image sheet shows on.
I’m having trouble getting this to show up consistently.
Note: I further reduced and modified your code (not a fan of introducing extra elements like composer.* and more code; Also like to be able to see all code in one place for debug.)
main.lua
local widget = require("widget") -- local w = display.contentWidth;local h = display.contentHeight local fullW = display.actualContentWidth;local fullH = display.actualContentHeight local unusedWidth = fullW - w;local unusedHeight = fullH - h \_L = math.floor(0 - (unusedWidth \* 0.5));\_T = math.floor(0 - (unusedHeight \* 0.5)) \_R = math.floor(w + (unusedWidth \* 0.5));\_B = math.floor(h + (unusedHeight \* 0.5)) \_CW = \_R;\_CH = \_B;\_FullHeight = \_B;\_CX = math.floor(\_CW \* 0.5);\_CY = math.floor(\_CH \* 0.5) -- local widgetTheme = require("widgetTheme\_green\_sheet") local sdzImageSheet = graphics.newImageSheet( "images/widgetTheme.png", widgetTheme:getSheet() ) -- ============================================================== -- local function onSwitchPress(event) local switch = event.target local id = switch.id local onState = (switch.isOn) and "ON" or "OFF" -- print( "\nSwitch with ID '" .. id .. "' is: " .. onState .. " @ " .. system.getTimer() ) end -- local function dummySetState( button, on ) local switch = button local id = switch.id local onState0 = (switch.isOn) and "ON" or "OFF" local function onComplete() local onState1 = (switch.isOn) and "ON" or "OFF" -- print( "\nBefore - Switch with ID '" .. id .. "' is: " .. onState0 .. " @ " .. system.getTimer() ) print( "After - Switch with ID '" .. id .. "' is: " .. onState1 .. " @ " .. system.getTimer() ) end -- switch:setState( { isOn = on, isAnimated = true, onComplete = onComplete } ) end -- ============================================================== local switch1 = widget.newSwitch( { x = 100, y = 100, style = "onOff", id = "switch1", onRelease = onSwitchPress, initialSwitchState = false, }) -- local switch2 = widget.newSwitch( { x = 200, y = 100, style = "onOff", id = "switch2", onRelease = onSwitchPress, initialSwitchState = false, sheet = sdzImageSheet, onOffBackgroundFrame = 60, onOffBackgroundWidth = 165, onOffBackgroundHeight = 30, onOffMask = "images/widgetTheme\_onOff\_mask.png", onOffHandleDefaultFrame = 63, -- 63, onOffHandleOverFrame = 63, --64, onOffOverlayFrame = 65, onOffOverlayWidth = 84, onOffOverlayHeight = 32, --offDirection = "left" }) -- timer.performWithDelay(1500, function() dummySetState( switch1, true ) end, 1) timer.performWithDelay(1500, function() dummySetState( switch2, true ) end, 1)
I’m using the onRelease method, which means that I’m supposed to be getting the isOn value after it has been changed.
the best thing to do is to actually watch the control move, via the timer, and then tap the control. Have adb running and it reports what the sample app is doing - and you can see the event generated without the tab moving.
Also on startup, you can see how the control doesnt show the initial state correctly. The std does, the imageSheet doesnt. When the timer fires, both controls switch - std reporting correctly, imageSheet incorrectly. Tap the std and it moves, and reports the change correctlty. Tap the imageSheet and it reports the change, but doesnt move. tap it a second time and it reports the change and moves - now matching the proper state.
Thank. I appreciate your looking at it. It works perfectly in the simulator. I built it and pushed it to a device. Same problem as before.
I also tried it with the halo dark theme and got exactly the same results. Fine in the simulator and broken on the device. I know it’s crazy because I suspect that corona uses the halo theme as a default for android.
What was wrong with the mask? This was from a pack purchased from the marketplace.
Sorry to correct you but masks do not need to be divisible by 4 anymore.
I create all my masks at 1x size and with 4px of solid black around. I reduce these to 2 bit but you can use 8 bit if you want semi-transparent masking.
So for a 100x100px image (200x200px @2x and 400x400px @4x) I will create a single mask of 104x104px.