Level Select: Button Rectangles are Invisible

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]

What version of Corona SDK are you building with?

Your code seems to be missing a few things from the tutorial and there is one line that’s commented out that’s missing a “-” at the beginning that throws an error. 

Perhaps you should try the code directly from the tutorial.

Rob

Rob,

I haven’t yet tried to build this app. The filled rounded rectangles are missing from the simulator.

In the above code, I tried to simply paste directly from your blog, not from my code file. If there are any discrepancies, I must have created it after I pasted and then tried to add line breaks to make it readable.

For my program, I’ve worked around the issue by using an image for the button, instead of a dynamic shape. But I would still be interested in understanding what I’m missing by trying to create a widget button in this way.

Let me re-ask the question:  What version of Corona SDK are  you using?

Haha. I knew that. Sorry. It was really late when I posted that reply.

Right now, I’m using Starter Version 2014.2189

I’ll try to download the more current version to see if that makes a difference.

Thanks,

Jeff

Okay. That did fix the problem. They’re all showing up now.

Thanks a bunch!!

-Jeff

There rounded rect buttons were added after 2189, so you need the latest version to work.

Rob

What version of Corona SDK are you building with?

Your code seems to be missing a few things from the tutorial and there is one line that’s commented out that’s missing a “-” at the beginning that throws an error. 

Perhaps you should try the code directly from the tutorial.

Rob

Rob,

I haven’t yet tried to build this app. The filled rounded rectangles are missing from the simulator.

In the above code, I tried to simply paste directly from your blog, not from my code file. If there are any discrepancies, I must have created it after I pasted and then tried to add line breaks to make it readable.

For my program, I’ve worked around the issue by using an image for the button, instead of a dynamic shape. But I would still be interested in understanding what I’m missing by trying to create a widget button in this way.

Let me re-ask the question:  What version of Corona SDK are  you using?

Haha. I knew that. Sorry. It was really late when I posted that reply.

Right now, I’m using Starter Version 2014.2189

I’ll try to download the more current version to see if that makes a difference.

Thanks,

Jeff

Okay. That did fix the problem. They’re all showing up now.

Thanks a bunch!!

-Jeff

There rounded rect buttons were added after 2189, so you need the latest version to work.

Rob