Difference between revisions of "Sprite:setStyle"
From GiderosMobile
(Created page with "__NOTOC__ '''Available since:''' Gideros 2022.6<br/> '''Class:''' Sprite<br/> === Description === Attaches a style table to a Sprite and mark it as dirty. This means that...") |
|||
Line 44: | Line 44: | ||
local spriteStyle={ | local spriteStyle={ | ||
__Parent=stageStyle, --Inherits from 'stageStyle' | __Parent=stageStyle, --Inherits from 'stageStyle' | ||
− | color1="=baseColor:brightness:1.1", | + | color1="=baseColor:brightness:1.1", -- alpha, mix, brightness |
color2="=baseColor:brightness:0.8", | color2="=baseColor:brightness:0.8", | ||
color3="=baseColor:brightness:0.0", | color3="=baseColor:brightness:0.0", |
Latest revision as of 21:27, 17 October 2025
Available since: Gideros 2022.6
Class: Sprite
Description
Attaches a style table to a Sprite and mark it as dirty. This means that a Sprite can now be given style references instead of plain values. Gideros will resolve the references to actual values thanks to Style tables at runtime.
Sprite:setStyle(style)
Currently styles are handled for Sprite layout constraints, layout parameters and for Pixel color (more may come in the future)
Parameters
style: (table) the styling table
Examples
local style={
cellColor=vector(1,0,0,1) --cellColor is Red initially
}
for i=1,10 do
local p=Pixel.new(vector(0,0,0,0),10,10)
p:setX((i-1)*15)
p:setStyle(style)
p:setColor("cellColor")
stage:addChild(p)
end
Core.asyncCall(function()
Core.yield(3) --Wait 3s
style.cellColor=vector(0,1,0,1) --Set cellColor to green
for i=1,10 do
stage:getChildAt(i):setStyle(style)
print(stage:getChildAt(i):resolveStyle("cellColor",style))
end
end)
A checker board
local stageStyle={
baseColor=ColorValue(0.7,0.6,0,1)
}
local spriteStyle={
__Parent=stageStyle, --Inherits from 'stageStyle'
color1="=baseColor:brightness:1.1", -- alpha, mix, brightness
color2="=baseColor:brightness:0.8",
color3="=baseColor:brightness:0.0",
}
for x=1,4 do
for y=1,4 do
local gradient=Pixel.new(0xFFFFFF,1,32,32)
gradient:setPosition(128+x*32,128+y*32)
gradient:setStyle(spriteStyle)
-- gradient:setColor("color"..(1+((x+y)%2))) -- alternates between color1 and color2
gradient:setColor("color"..(1+((x+y)%3))) -- alternates between color1, color2 and color3
stage:addChild(gradient)
end
end
stage:addEventListener(Event.MOUSE_DOWN,function()
stageStyle.baseColor=ColorValue(math.random(),math.random(),math.random(),1)
stage:setStyle(stageStyle,true)
end)
- Sprite:addChild
- Sprite:addChildAt
- Sprite:addChildrenAt
- Sprite:clearBlendMode
- Sprite:clone
- Sprite:contains
- Sprite:get
- Sprite:getAlpha
- Sprite:getAnchorPoint
- Sprite:getAnchorPosition
- Sprite:getBounds
- Sprite:getChildAt
- Sprite:getChildIndex
- Sprite:getChildrenAtPoint
- Sprite:getClip
- Sprite:getColorTransform
- Sprite:getDrawCount
- Sprite:getHeight
- Sprite:getLayoutConstraints
- Sprite:getLayoutInfo
- Sprite:getLayoutParameters
- Sprite:getMatrix
- Sprite:getNumChildren
- Sprite:getParent
- Sprite:getPosition
- Sprite:getRotation
- Sprite:getRotationX
- Sprite:getRotationY
- Sprite:getScale
- Sprite:getScaleX
- Sprite:getScaleY
- Sprite:getScaleZ
- Sprite:getSize
- Sprite:getSkew
- Sprite:getSkewX
- Sprite:getSkewY
- Sprite:getWidth
- Sprite:getX
- Sprite:getY
- Sprite:getZ
- Sprite:globalToLocal
- Sprite:hitTestPoint
- Sprite:isOnStage
- Sprite:isVisible
- Sprite:localToGlobal
- Sprite:redrawEffects
- Sprite:removeChild
- Sprite:removeChildAt
- Sprite:removeFromParent
- Sprite:resolveStyle
- Sprite:set
- Sprite:setAlpha
- Sprite:setAnchorPoint
- Sprite:setAnchorPosition
- Sprite:setBlendMode
- Sprite:setClip
- Sprite:setColorTransform
- Sprite:setEffectConstant
- Sprite:setEffectStack
- Sprite:setGhosts
- Sprite:setHiddenChildren
- Sprite:setLayoutConstraints
- Sprite:setLayoutParameters
- Sprite:setMatrix
- Sprite:setPosition
- Sprite:setRotation
- Sprite:setRotationX
- Sprite:setRotationY
- Sprite:setScale
- Sprite:setScaleX
- Sprite:setScaleY
- Sprite:setScaleZ
- Sprite:setShader
- Sprite:setShaderConstant
- Sprite:setSkew
- Sprite:setSkewX
- Sprite:setSkewY
- Sprite:setStencilOperation
- Sprite:setStopEventPropagation
- Sprite:setStyle
- Sprite:setVisible
- Sprite:setWorldAlign
- Sprite:setX
- Sprite:setY
- Sprite:setZ
- Sprite:spriteToLocal
- Sprite:spriteToLocalMatrix
- Sprite:swapChildren
- Sprite:swapChildrenAt
- Sprite:updateStyle
- Sprite.ADD
- Sprite.ALPHA
- Sprite.EFFECT MODE AUTOMATIC
- Sprite.EFFECT MODE CONTINUOUS
- Sprite.EFFECT MODE TRIGGERED
- Sprite.LAYOUT ANCHOR CENTER
- Sprite.LAYOUT ANCHOR EAST
- Sprite.LAYOUT ANCHOR NORTH
- Sprite.LAYOUT ANCHOR NORTHEAST
- Sprite.LAYOUT ANCHOR NORTHWEST
- Sprite.LAYOUT ANCHOR SOUTH
- Sprite.LAYOUT ANCHOR SOUTHEAST
- Sprite.LAYOUT ANCHOR SOUTHWEST
- Sprite.LAYOUT ANCHOR WEST
- Sprite.LAYOUT FILL BOTH
- Sprite.LAYOUT FILL HORIZONTAL
- Sprite.LAYOUT FILL NONE
- Sprite.LAYOUT FILL VERTICAL
- Sprite.MULTIPLY
- Sprite.NO ALPHA
- Sprite.SCREEN
- Sprite.new
- Event.ADDED_TO_STAGE
- Event.ENTER_FRAME
- Event.KEY_CHAR
- Event.KEY_DOWN
- Event.KEY_UP
- Event.LAYOUT_RESIZED
- Event.MOUSE_DOWN
- Event.MOUSE_ENTER
- Event.MOUSE_HOVER
- Event.MOUSE_LEAVE
- Event.MOUSE_MOVE
- Event.MOUSE_UP
- Event.MOUSE_WHEEL
- Event.REMOVED_FROM_STAGE
- Event.TOUCHES_BEGIN
- Event.TOUCHES_CANCEL
- Event.TOUCHES_END
- Event.TOUCHES_MOVE