It looks like you're new here. If you want to get involved, click one of these buttons!
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 |
Likes: antix, pie, n1cke, JuanZambrano
Comments
Likes: MoKaLux
Fragmenter - animated loop machine and IKONOMIKON - the memory game
It would be easier (I don't know if this will work, it might) for you to maybe clip a master sprite object to the area you want look at, then draw it to a rendertarget, then unclip the master sprite to draw to the stage at the end of the event. Then getPixel on the render target ?
https://deluxepixel.com
i imagined that perhaps the stage behaves similarly as a rendertarget under the hood, as from outside it looks like that - something you assign sprites to, then it is clipped and drawn somewhere in some memory (on screen in the case of the stage).
what you propose is completely workable, i will check the performance hit of it as i want to make a color-picker to my drawing app, which means that i need to get the pixel at each frame.
Fragmenter - animated loop machine and IKONOMIKON - the memory game
Likes: keszegh
Fragmenter - animated loop machine and IKONOMIKON - the memory game
Likes: keszegh, antix
Fragmenter - animated loop machine and IKONOMIKON - the memory game
how much easier life would be if google came up with +1.1 or +2 instead of +1.
Fragmenter - animated loop machine and IKONOMIKON - the memory game
Likes: keszegh
https://deluxepixel.com
Fragmenter - animated loop machine and IKONOMIKON - the memory game
https://deluxepixel.com
Likes: MoKaLux