sergzach
sergzach

Reputation: 6764

Can I add several sprite children with the same index?

I want 2 sprites on the one index position. The sprites have different coordinates (x attributes), so, each of them are visible when the child position is active.

Clarification, the code:

addChildAt( sprite1, 1 );
addChildAt( sprite2, 1 );   

Are both of the sprites visible?

Upvotes: 0

Views: 79

Answers (2)

Stan Reshetnyk
Stan Reshetnyk

Reputation: 2036

No, you can't. But you can add extra sprite between parent and children to easily control visibility or whatever. Sample:

parentSprite.addChild(extra)
extra.addChildAt( sprite1, 1 );
extra.addChildAt( sprite2, 2 );   

Upvotes: 2

VBCPP
VBCPP

Reputation: 153

The documentation gives you the answer of what will happen with your snippet.

index:int — The index position to which the child is added. If you specify a currently occupied index position, the child object that exists at that position and all higher positions are moved up one position in the child list.

Two objects can't share the same index because it wouldn't make sense. How would you display two overlapping objects at the same index?

Upvotes: 3

Related Questions