Difference between revisions of "Pixel"
m (Text replacement - "<source" to "<syntaxhighlight") |
|||
| (7 intermediate revisions by 2 users not shown) | |||
| Line 1: | Line 1: | ||
__NOTOC__ | __NOTOC__ | ||
<!-- GIDEROSOBJ:Pixel --> | <!-- GIDEROSOBJ:Pixel --> | ||
| − | '''Supported platforms:''' [[File:Platform android.png]][[File:Platform ios.png]][[File:Platform mac.png]][[File:Platform pc.png]][[File:Platform html5.png]][[File:Platform winrt.png]][[File:Platform win32.png]]<br/> | + | '''Supported platforms:''' [[File:Platform android.png]][[File:Platform ios.png]][[File:Platform mac.png]][[File:Platform pc.png]][[File:Platform html5.png]][[File:Platform winrt.png]][[File:Platform win32.png]][[File:Platform linux.png]]<br/> |
'''Available since:''' Gideros 2016.06<br/> | '''Available since:''' Gideros 2016.06<br/> | ||
'''Inherits from:''' [[Sprite]]<br/> | '''Inherits from:''' [[Sprite]]<br/> | ||
| Line 16: | Line 16: | ||
stage:addChild(mypixel) | stage:addChild(mypixel) | ||
| − | </ | + | </syntaxhighlight> |
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
| Line 37: | Line 37: | ||
stage:addChild(p) | stage:addChild(p) | ||
| − | </ | + | </syntaxhighlight> |
| + | |||
| + | '''Moving stars in a gradient sky''' | ||
| + | <syntaxhighlight lang="lua"> | ||
| + | -- moving stars in a gradient sky by: @PaulH | ||
| + | local width, height = 640, 360 | ||
| + | -- a gradient sky | ||
| + | local sky = Pixel.new(0xffffff, 1, width, height) | ||
| + | sky:setColor(0x3a597c, 1, 0x4d0074, 1, 90) -- a gradient set horizontally | ||
| + | -- stars | ||
| + | local spritestars = Sprite.new() -- a sprite to hold all star shapes | ||
| + | for i = 1, 256 do -- @PaulH | ||
| + | local s = Shape.new() | ||
| + | s:setLineStyle(2, 0xffffff) | ||
| + | s:moveTo(0, 0) | ||
| + | s:lineTo(1, 1) | ||
| + | s:endPath() | ||
| + | s:setPosition(math.random(0, width), math.random(0, 2.2*height/3)) | ||
| + | s:setScale(math.random(5, 15) / 10) | ||
| + | s:setAlpha(math.random(10, 50) / 50) | ||
| + | spritestars:addChild(s) | ||
| + | end | ||
| + | -- render stars to a render target | ||
| + | local rtstars = RenderTarget.new(width, height, nil, { wrap="repeat", extend=false, }) | ||
| + | rtstars:draw(spritestars) | ||
| + | -- create an image (Pixel) of the stars | ||
| + | local stars = Pixel.new(rtstars, width, height) | ||
| + | stars:setColorTransform(7/255, 221/255, 219/255, 1) -- stars color | ||
| + | -- order | ||
| + | stage:addChild(sky) | ||
| + | stage:addChild(stars) | ||
| + | |||
| + | -- game loop | ||
| + | local velx = 0 | ||
| + | function onEnterFrame(e) | ||
| + | -- move the stars | ||
| + | velx -= e.deltaTime * 32 -- 128 | ||
| + | stars:setTexturePosition(velx, 0) | ||
| + | end | ||
| + | stage:addEventListener(Event.ENTER_FRAME, onEnterFrame) | ||
| + | </syntaxhighlight> | ||
{|- | {|- | ||
| style="width: 50%; vertical-align:top;"| | | style="width: 50%; vertical-align:top;"| | ||
| + | |||
=== Methods === | === Methods === | ||
[[Pixel.new]] ''creates a new Pixel''<br/><!--GIDEROSMTD:Pixel.new(color,alpha,width,height) creates a new Pixel--> | [[Pixel.new]] ''creates a new Pixel''<br/><!--GIDEROSMTD:Pixel.new(color,alpha,width,height) creates a new Pixel--> | ||
| − | [[Pixel.new]] ''constructor to create a Pixel with texture in | + | [[Pixel.new]] ''constructor to create a Pixel with texture in Letterbox mode''<br/><!--GIDEROSMTD:Pixel.new(texture,width,height,texture_scale_x,texture_scale_y,texture_x,texture_y) constructor to create a Pixel with texture in Letterbox mode--> |
| + | [[Pixel.new]] ''constructor to create a Pixel with texture in Stretched mode''<br/><!--GIDEROSMTD:Pixel.new(width,height,texture) constructor to create a Pixel with texture in Stretched mode--> | ||
[[Pixel:getColor]] ''returns the color(s) of the Pixel''<br/><!--GIDEROSMTD:Pixel:getColor() gets the color(s) of the Pixel--> | [[Pixel:getColor]] ''returns the color(s) of the Pixel''<br/><!--GIDEROSMTD:Pixel:getColor() gets the color(s) of the Pixel--> | ||
[[Pixel:getDimensions]] ''returns the current size of the Pixel''<br/><!--GIDEROSMTD:Pixel:getDimensions() returns the current size of the Pixel--> | [[Pixel:getDimensions]] ''returns the current size of the Pixel''<br/><!--GIDEROSMTD:Pixel:getDimensions() returns the current size of the Pixel--> | ||
Latest revision as of 02:37, 23 March 2025
Supported platforms: ![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
Available since: Gideros 2016.06
Inherits from: Sprite
Description
A rectangular Sprite which can be filled with solid colors, gradients or textures. Pixel aims at being a simpler and faster alternative to Shape when needing to display a coloured box or box with a gradient. It is also useful as Bitmap replacement since every texture will be fitted into Pixel dimensions automatically.
Examples
local mypixel = Pixel.new(0x0000FF, 0.75, 128, 128)
mypixel:setAnchorPoint(0.5, 0.5)
mypixel:setPosition(application:getContentWidth() / 2, 64)
stage:addChild(mypixel)
application:setBackgroundColor(0x323232)
local p = Pixel.new(0xffffff, 1, 32, 32)
p:set("redMultiplier", 1) -- OK
p:set("greenMultiplier", 0) -- OK
p:set("blueMultiplier", 0) -- OK
p:set("alphaMultiplier", 1) -- OK
--p:set("anchorX", .5) -- NOT OK
--p:set("anchorY", .5) -- NOT OK
p:set("anchorX", 16) -- OK
p:set("anchorY", 16) -- OK
p:set("alpha", .5) -- OK
p:set("scaleX", 1.5) -- OK
p:set("rotation", 10) -- OK
p:set("x", 32) -- OK
p:set("y", 32) -- OK
stage:addChild(p)
Moving stars in a gradient sky
-- moving stars in a gradient sky by: @PaulH
local width, height = 640, 360
-- a gradient sky
local sky = Pixel.new(0xffffff, 1, width, height)
sky:setColor(0x3a597c, 1, 0x4d0074, 1, 90) -- a gradient set horizontally
-- stars
local spritestars = Sprite.new() -- a sprite to hold all star shapes
for i = 1, 256 do -- @PaulH
local s = Shape.new()
s:setLineStyle(2, 0xffffff)
s:moveTo(0, 0)
s:lineTo(1, 1)
s:endPath()
s:setPosition(math.random(0, width), math.random(0, 2.2*height/3))
s:setScale(math.random(5, 15) / 10)
s:setAlpha(math.random(10, 50) / 50)
spritestars:addChild(s)
end
-- render stars to a render target
local rtstars = RenderTarget.new(width, height, nil, { wrap="repeat", extend=false, })
rtstars:draw(spritestars)
-- create an image (Pixel) of the stars
local stars = Pixel.new(rtstars, width, height)
stars:setColorTransform(7/255, 221/255, 219/255, 1) -- stars color
-- order
stage:addChild(sky)
stage:addChild(stars)
-- game loop
local velx = 0
function onEnterFrame(e)
-- move the stars
velx -= e.deltaTime * 32 -- 128
stars:setTexturePosition(velx, 0)
end
stage:addEventListener(Event.ENTER_FRAME, onEnterFrame)
MethodsPixel.new creates a new Pixel |
EventsConstants |