Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Example of Pixel sprite type — Gideros Forum

Example of Pixel sprite type

SinisterSoftSinisterSoft Maintainer
edited April 2016 in Code snippets
Here is an example of the Pixel sprite type in the next version of Gideros (added by @Hgy29)...
local clown=Bitmap.new(Texture.new("clown.png"))
local w,h=clown:getWidth(),clown:getHeight()
 
local render=RenderTarget.new(w,h)
render:clear(0,0)
render:draw(clown)
 
local pixelClown=Sprite.new()
pixels={}
 
for y=0,h-1 do
	for x=0,w-1 do
		local c,a=render:getPixel(x,y)
		if a>0 then
			pixels[#pixels+1]=Pixel.new(c,math.random(),9,9)
			pixels[#pixels]:setPosition((-w*5)+x*10,(-h*5)+y*10)
			pixelClown:addChild(pixels[#pixels])
		end
	end
end
 
pixelClown:setPosition(200,200)
 
stage:addChild(pixelClown)
 
function gameLoop(e)
	pixelClown:setRotation(pixelClown:getRotation()+1)
	for loop=1,#pixels do
		local c,a=pixels[loop]:getColor()
		a=a+0.03
		if a>1 then a=a-1 end
		pixels[loop]:setColor(c,a)
	end
end
 
stage:addEventListener(Event.ENTER_FRAME,gameLoop)

Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!).
https://deluxepixel.com
+1 -1 (+5 / -0 )Share on Facebook

Comments

Sign In or Register to comment.