Hello all,
I recently cut and pasted some code from Rob Miracle’s Blog about creating a level selection screen.
The site is here:
http://coronalabs.com/blog/2014/08/12/tutorial-building-a-level-selection-scene/
My problem is that none of the buttons are showing their fill area or outline stroke. They are white on a white background, no matter what I set the fillColor parameters to. I’ve tried changing to color of the background, but that only changes the area behind the scrollview. I’ve also tried to borrow the code for buttons within my main game module, and I’m getting the same result, even though there is no scrollview in that module.
This is my first attempted use of the button widget. Any ideas?
Thanks,
Jeff
Specifically, the button code is:
[lua]
for i = 1, myData.maxLevels do
– Create a button
buttons[i] = widget.newButton({
label = tostring( i ),
id = tostring( i ),
onEvent = handleLevelSelect,
emboss = false,
shape=“roundedRect”,
width = 48,
height = 32,
font = native.systemFontBold,
fontSize = 18,
labelColor = { default = { 1, 1, 1 }, over = { 0.5, 0.5, 0.5 } },
cornerRadius = 8,
labelYOffset = -6,
fillColor = { default={ 0, 0.5, 1, 1 }, over={ 0.5, 0.75, 1, 1 } },
strokeColor = { default={ 0, 0, 1, 1 }, over={ 0.333, 0.667, 1, 1 } },
strokeWidth = 2 })
– Position the button in the grid and add it to the scrollView
buttons[i].x = xOffset
buttons[i].y = yOffset
levelSelectGroup:insert( buttons[i] )
– Check to see if the player has achieved (completed) this level.
– The ‘.unlockedLevels’ value tracks the maximum unlocked level.
– First, however, check to make sure that this value has been set.
– If not set (new user), this value should be 1.
– If the level is locked, disable the button and fade it out.
if ( myData.settings.unlockedLevels == nil ) then
myData.settings.unlockedLevels = 1
end
if ( i <= myData.settings.unlockedLevels ) then
buttons[i]:setEnabled( true ) buttons[i].alpha = 1.0
else
buttons[i]:setEnabled( false ) buttons[i].alpha = 0.5
end
– Generate stars earned for each level, but only if:
– a. The ‘levels’ table exists
– b. There is a ‘stars’ value inside of the ‘levels’ table
- c. The number of stars is greater than 0 (no need to draw zero stars).
local star = {}
if ( myData.settings.levels[i] and myData.settings.levels[i].stars and myData.settings.levels[i].stars > 0 ) then
for j = 1, myData.settings.levels[i].stars do
star[j] = display.newPolygon( 0, 0, starVertices )
star[j]:setFillColor( 1, 0.9, 0 )
star[j].strokeWidth = 1
star[j]:setStrokeColor( 1, 0.8, 0 )
star[j].x = buttons[i].x + (j * 16) - 32
star[j].y = buttons[i].y + 8
levelSelectGroup:insert( star[j] )
end
end[/lua]