Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

object:setStrokeColor but no object:getStrokeColor?
Started by prographodeveloper Dec 06 2018 03:15 PM

2 replies to this topic

Best Answer roaminggamer , 06 December 2018 - 03:42 PM

You can't get previously set colors.  

 

Also the technique you show won't always work for fills.

 

If you need that info, you need to store it aside when you set it.  

 

There are many ways to do this.  If you need it a lot, the easiest way is to override the core display object builder functions to provide the feature.

 

Ping back if you want to know how to do that.  Hint, see SSK 2 display object extensions as a starting point.

 

https://raw.githubusercontent.com/roaminggamer/SSK2/master/ssk2/core/extensions/display.lua

 

SSK 2 extends display.newContainer() and display.newGroup()  A similar thing can be done for display.newRect() etc...

 

Again, if you get stuck, post back.

[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

prographodeveloper

[GLOBAL: userInfoPane.html]
prographodeveloper
  • Contributor

  • 281 posts
  • Corona SDK

How do I get the stroke color? 

 

For fill color it's just;

 

local fc = object.fill



[TOPIC: post.html]
#2

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 7,380 posts
  • Corona SDK

  Best Answer

You can't get previously set colors.  

 

Also the technique you show won't always work for fills.

 

If you need that info, you need to store it aside when you set it.  

 

There are many ways to do this.  If you need it a lot, the easiest way is to override the core display object builder functions to provide the feature.

 

Ping back if you want to know how to do that.  Hint, see SSK 2 display object extensions as a starting point.

 

https://raw.githubusercontent.com/roaminggamer/SSK2/master/ssk2/core/extensions/display.lua

 

SSK 2 extends display.newContainer() and display.newGroup()  A similar thing can be done for display.newRect() etc...

 

Again, if you get stuck, post back.



[TOPIC: post.html]
#3

prographodeveloper

[GLOBAL: userInfoPane.html]
prographodeveloper
  • Contributor

  • 281 posts
  • Corona SDK

Hi thanks.

 

I overrided the newLine to add a function as below.

 

Interestingly I couldn't override setStrokeColor function itself - I did try - but it just wouldn't set it, so I made version 2.

 

seems to work

local _newLine = display.newLine

display.newLine = function( ... )

    local object = _newLine( unpack(arg) )
    
    object.setStrokeColor2 = function ( ... )
        
        object.strokeColor = { arg[2], arg[3], arg[4], arg[5] or 1 }
        
        object.setStrokeColor( unpack(arg) )
        
    end

    return object
end


  • roaminggamer likes this


[topic_controls]
[/topic_controls]