Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Another use of RenderTarget — Gideros Forum

Another use of RenderTarget

chuz0chuz0 Member
edited July 2016 in General questions
Hello,
Besides the obvious use, it can also be used for buttons with odd shapes.
See the code below:
inicio = Core.class(Sprite)
 
function inicio:init()
	wi = application:getContentWidth()
	he = application:getContentHeight()
 
	local source = Bitmap.new(Texture.new("US_map_blank.jpg", true)) -- blank map
 
	local colormap = Bitmap.new(Texture.new("US_map_colors.jpg",true)) -- coloured map
 
	rt = RenderTarget.new(wi,he)
	rt:draw(colormap)
	local bmp = Bitmap.new(rt)
	bmp:setPosition(0, 0)
	self:addChild(bmp)
 
	self:addChild(source)
 
	self:addEventListener(Event.MOUSE_UP, self.onMouseUp, self)
 
end
 
function inicio:onMouseUp(ev)
 
	local col,alph = rt:getPixel(ev.x, ev.y)
 
	if math.abs(col-tonumber(000000,16))<5 then
		print("California")
	end
	if math.abs(col-tonumber(111111,16))<5 then
		print("Arizona")
	end
	if math.abs(col-tonumber(222222,16))<5 then
		print("New Mexico")
	end
	if math.abs(col-tonumber(333333,16))<5 then
		print("Texas")
	end
	if math.abs(col-tonumber(444444,16))<5 then
		print("Louisiana")
	end
	if math.abs(col-tonumber(555555,16))<5 then
		print("Mississippi")
	end
	if math.abs(col-tonumber(666666,16))<5 then
		print("Alabama")
	end
	if math.abs(col-tonumber(777777,16))<5 then
		print("Florida")
	end
 
end
Since it's just a proof of concept, and the code can be improved, I've just used the most southern states.
Find attached the jpgs I've used.

Regards.
US_map_colors.jpg
1005 x 703 - 125K
US_map_blank.jpg
1005 x 703 - 95K
+1 -1 (+4 / -0 )Share on Facebook

Comments

Sign In or Register to comment.