Sprite:setBlendMode

From GiderosMobile
Revision as of 14:31, 13 July 2023 by Hgy29 (talk | contribs) (Text replacement - "<source" to "<syntaxhighlight")

Available since: Gideros 2011.6
Class: Sprite

Description

Sets the blend mode of the sprite. <syntaxhighlight lang="lua"> Sprite:setBlendMode(blendMode or src,dst) </source>

This method can be called with 1 or 2 parameters.

If one parameter is passed it must be one of the following blending modes:

  • Sprite.ALPHA = "alpha"
  • Sprite.NO_ALPHA = "noAlpha"
  • Sprite.ADD = "add"
  • Sprite.MULTIPLY = "multiply"
  • Sprite.SCREEN = "screen"

If a Sprite object doesn't set any blending mode, it takes the blending mode from its parent sprite.

Note: the following two lines are completely the same: <syntaxhighlight lang="lua"> sprite:setBlendMode("add") sprite:setBlendMode(Sprite.ADD) </source> It's a matter of taste which one to choose.


If two parameters are passed to this method, then a source and destination blend can be set (in that order) and each takes the values:

  • Sprite.ZERO = "zero"
  • Sprite.ONE = "one"
  • Sprite.SRC_COLOR = "srcColor"
  • Sprite.ONE_MINUS_SRC_COLOR = "oneMinusSrcColor"
  • Sprite.DST_COLOR = "dstColor"
  • Sprite.ONE_MINUS_DST_COLOR = "oneMinusDstColor"
  • Sprite.SRC_ALPHA = "srcAlpha"
  • Sprite.ONE_MINUS_SRC_ALPHA = "oneMinusSrcAlpha"
  • Sprite.DST_ALPHA = "dstAlpha"
  • Sprite.ONE_MINUS_DST_ALPHA = "oneMinusDstAlpha"
  • Sprite.SRC_ALPHA_SATURATE = "srcAlphaSaturate"

Parameters

blendMode or src: (String) if one parameter is used, this is the blend mode. If two parameters are used this is the source blend specification
dst: (String) destination blend mode optional

Example

<syntaxhighlight lang="lua"> for x = 1, 11 do for y = 1, 11 do local top = Pixel.new(topTex, s, s) local btm = Pixel.new(btmTex, s, s) stage:addChild(btm) btm:addChild(top) btm:setBlendMode(x, y) btm:setPosition(lh + s * (x-1), lh + s * (y-1)) end end </source>