Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

print current object color
Started by cm2001m Apr 26 2016 11:56 PM

- - - - -
1 reply to this topic
color lua ios print function random math random

Best Answer torbenratzlaff , 27 April 2016 - 05:08 AM

Hey cm2001m,

 

why not save the created color in a variable before using it?

local color1, color2, color3 = ragdogLib.convertHexToRGB(randomcolor())
bombstartnew:setFillColor(color1, color2, color3);
print(color1, color2, color3)

Like this you are able to access the randomly choosen colors.

 

Or do you want to retrieve the color values outside of the creation functions?

If that's the case, you should store the values as a property of the object you used them for.

local color1, color2, color3 = ragdogLib.convertHexToRGB(randomcolor())
bombstartnew:setFillColor(color1, color2, color3);
bombstartnew.fillColor = {color1, color2, color3}

print(unpack(bombstartnew.fillColor))

Hope that helps :)

[TOPIC CONTROLS]
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

cm2001m

[GLOBAL: userInfoPane.html]
cm2001m
  • Enthusiast

  • 44 posts
  • Corona SDK

I have set color of object using hex converter how do i retrieve current color being used on the object.

 

 

 
function randomcolor()
local colors = {	"#e67e22","#e74c3c"	,"#f1c40f","#1abc9c","#8e44ad"	}
local finalcolor = colors[math.random(1, 5)]

 return finalcolor
end

local ragdogLib = require "ragdogLib";
local function addnewobject()
  
    local bombstartnew = display.newRect( startingpoint, -340, 50, 50)


bombstartnew:setFillColor(ragdogLib.convertHexToRGB(randomcolor()));


end

 



[TOPIC: post.html]
#2

torbenratzlaff

[GLOBAL: userInfoPane.html]
torbenratzlaff
  • Contributor

  • 404 posts
  • Corona SDK

  Best Answer

Hey cm2001m,

 

why not save the created color in a variable before using it?

local color1, color2, color3 = ragdogLib.convertHexToRGB(randomcolor())
bombstartnew:setFillColor(color1, color2, color3);
print(color1, color2, color3)

Like this you are able to access the randomly choosen colors.

 

Or do you want to retrieve the color values outside of the creation functions?

If that's the case, you should store the values as a property of the object you used them for.

local color1, color2, color3 = ragdogLib.convertHexToRGB(randomcolor())
bombstartnew:setFillColor(color1, color2, color3);
bombstartnew.fillColor = {color1, color2, color3}

print(unpack(bombstartnew.fillColor))

Hope that helps :)




[topic_controls]
[/topic_controls]