Wouldn't it be lovely if display newText took the text colour as a parameter

Wouldn’t it be lovely if display.newText took the text colour as a parameter…

It’d reduce a lot of lines of code like this:

local myText = display.newText( “Hello World!”, 100, 200, native.systemFont, 16 )

myText:setFillColor( 1, 0, 0 )

Similarly newRect etc.

It’d be lovely wouldn’t it.

:slight_smile: Tom

Well, you could easily create a wrapper function that takes the usual arguments, plus optional colour, scale, reference point and anything else you can think of and returns the text object with everything nicely set up.

@tomprice

Agreed. Corona doesn’t need to do this. It is plenty flexible as is.

SSK2 Already Has It
SSK does this: https://roaminggamer.github.io/RGDocs/pages/SSK2/libraries/easy_interfaces/#quicklabel
 

ssk.easyIFC:quickLabel( group, text, x, y [, font [, size [, color [, anchorX [, anchorY]]]]] )

If you use SSK in your projects, you could just put this at the top of any file where you need it,

local easyIFC = ssk.easyIFC

Then do this anywhere below that:

quickLabel( nil, "Hello World!", 100, 200, native.systemFont, 16, { 1, 0, 0 } )

Or this to align text to upper-left corner

quickLabel( nil, "Hello World!", 100, 200, native.systemFont, 16, { 1, 0, 0 }, 0, 0 )

Object Factories Too
Likewise, SSK has super shorthand builders for circle, rect, imagerect, … way more powerful than what you’re imagining.

https://roaminggamer.github.io/RGDocs/pages/SSK2/libraries/display_standard/

Examples:
https://roaminggamer.github.io/RGDocs/pages/SSK2/libraries/display_samples/
 

Bouncing Block Physics Example:

sskversuspure.gif

newImageRect( group, centerX - 100 , centerY - 50, "images/kenney/physicsAssets/yellow\_round.png", { size = 40 }, { radius = 20, bounce = 1, gravityScale = 0.2 } ) newImageRect( group, centerX - 100, centerY + 100, "images/kenney/physicsAssets/stone/square2.png", { size = 40 }, { bodyType = "static" } ) 

Tip: If you want a feature, ask about it directly instead of passively implying Corona should up its game or something. :slight_smile:

Corona should do a better job of pushing libraries like SSK that are clearly of use to almost everyone, especially beginners.

When Unity come across a library that is in widespread use and clearly enhance the product, they bring it in-house. TextMeshPro, ProBuilder are two great libraries that started as 3rd party products but are now official Unity packages.

Thanks both!

I’ll look at SSK, roaminggamer - much appreciated.

For my reference, is there an easy way that I can extend display.newText so it can take that extra parameter?  Or do I need to create a new function that takes *all* the display.newText params and passes them all through, along with anything new ones I want to add?

You need to write a new function, but it’s very little code … simple example replacement

[lua]

do

    local newText = display.newText

    display.newText = function( txt, x, y, font, size, r, g, b, a )

        local myText = newText( txt, x, y, font, size )

        myText:setFillColor( r or 1, g or 1, b or 1, a or 1 )

        return myText

    end

end

[/lua]

It would be better to use the version that uses the table with the options but you used the one with the explicit parameters so I used the same.

Got it.  Thank you Michael

Touché, roaminggamer :slight_smile:

SSK looks excellent… I agree with Nick - I’ve been around here for a long time and didn’t know it existed…

Tip: If you wanted to take that one step further, you could extend/override display.newText() by executing this code once:

**UPDATE** I must have misread Michael’s post.  :wacko:**   He already did what I’m suggesting below with a slightly different signature.**

-- Execute this code once only before doing any work in your game/app local display\_newText = display.newText function display.newText( ..., color ) color = color or {1,1,1} local text = display\_newText( unpack( arg ) ) text:setFillColor( unpack( color ) ) return text end

Now you can use display.newText() like this if you want:

local myText = display.newText( "Hello World!", 100, 200, native.systemFont, 16, {1,0,0} )

SSK uses this and other extension techniques to extend certain key Corona libraries:

PS - I hope I wasn’t rude about the whole ‘passive’ thing.   I’ve had my coffee now. 

Ah yes, this is what I was meaning really… useful to know - thanks

Hehe, no, it was a fair point!  I run a software company so I ought to know!

fwiw, this type of override is “easier” if you abandon the legacy multi-argument format in favor of the current table-options format

just call your override with a few extra table parameters, pass the same table to the original newText (which will just ignore any unrecognized parameters), then parse your new parameters, fe:

display.oldText = display.newText function display.newText(options) local t = display.oldText(options) t:setFillColor(unpack(options.color)) return t end

Belatedly - many thanks Dave, that’s really helpful

Well, you could easily create a wrapper function that takes the usual arguments, plus optional colour, scale, reference point and anything else you can think of and returns the text object with everything nicely set up.

@tomprice

Agreed. Corona doesn’t need to do this. It is plenty flexible as is.

SSK2 Already Has It
SSK does this: https://roaminggamer.github.io/RGDocs/pages/SSK2/libraries/easy_interfaces/#quicklabel
 

ssk.easyIFC:quickLabel( group, text, x, y [, font [, size [, color [, anchorX [, anchorY]]]]] )

If you use SSK in your projects, you could just put this at the top of any file where you need it,

local easyIFC = ssk.easyIFC

Then do this anywhere below that:

quickLabel( nil, "Hello World!", 100, 200, native.systemFont, 16, { 1, 0, 0 } )

Or this to align text to upper-left corner

quickLabel( nil, "Hello World!", 100, 200, native.systemFont, 16, { 1, 0, 0 }, 0, 0 )

Object Factories Too
Likewise, SSK has super shorthand builders for circle, rect, imagerect, … way more powerful than what you’re imagining.

https://roaminggamer.github.io/RGDocs/pages/SSK2/libraries/display_standard/

Examples:
https://roaminggamer.github.io/RGDocs/pages/SSK2/libraries/display_samples/
 

Bouncing Block Physics Example:

sskversuspure.gif

newImageRect( group, centerX - 100 , centerY - 50, "images/kenney/physicsAssets/yellow\_round.png", { size = 40 }, { radius = 20, bounce = 1, gravityScale = 0.2 } ) newImageRect( group, centerX - 100, centerY + 100, "images/kenney/physicsAssets/stone/square2.png", { size = 40 }, { bodyType = "static" } ) 

Tip: If you want a feature, ask about it directly instead of passively implying Corona should up its game or something. :slight_smile:

Corona should do a better job of pushing libraries like SSK that are clearly of use to almost everyone, especially beginners.

When Unity come across a library that is in widespread use and clearly enhance the product, they bring it in-house. TextMeshPro, ProBuilder are two great libraries that started as 3rd party products but are now official Unity packages.

Thanks both!

I’ll look at SSK, roaminggamer - much appreciated.

For my reference, is there an easy way that I can extend display.newText so it can take that extra parameter?  Or do I need to create a new function that takes *all* the display.newText params and passes them all through, along with anything new ones I want to add?

You need to write a new function, but it’s very little code … simple example replacement

[lua]

do

    local newText = display.newText

    display.newText = function( txt, x, y, font, size, r, g, b, a )

        local myText = newText( txt, x, y, font, size )

        myText:setFillColor( r or 1, g or 1, b or 1, a or 1 )

        return myText

    end

end

[/lua]

It would be better to use the version that uses the table with the options but you used the one with the explicit parameters so I used the same.

Got it.  Thank you Michael

Touché, roaminggamer :slight_smile:

SSK looks excellent… I agree with Nick - I’ve been around here for a long time and didn’t know it existed…