Skip to content
This repository was archived by the owner on May 1, 2026. It is now read-only.
This repository was archived by the owner on May 1, 2026. It is now read-only.

SKNode.alpha not applying to children. #2

Description

@andersonlucasg3

When alpha of a SKNode is set, all the children should multiply it's alpha's value.

Eg:

If a node has alpha 0.5 and it's child has 0.75 of alpha.
Any SKSpriteNode that is in node.children[0].children that has 1.0 of alpha should have (0.5 * 0.75 * 1.0) == 0.375.
That means that the rendering should respect the algorithm:

fun calculateParentsAlpha() : Float {
    var accumulatedAlpha = 0.0f
    var parent = this.parent
    while (parent != null) {
        accumulatedAlpha *= parent!!.alpha
        parent = parent.parent
    }
    return accumulatedAlpha
}

val currentNodeAlpha = this.alpha * this.calculatedParentsAlpha()

That was just an example.
But there is an approach with better performance. That would be keep the alpha values of the children updated each time it's parent alpha value is changed.
If an alpha value of a node is changed, all the children of this node should be updated, recursively, with the multiplied value that has been changed. Of course it will require an backup alpha value for each node, otherwise the original value would be lost.

Just another thought about the solution. Open to discussions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions