Sprite-Kit : Sprite z-Order -


how change sprite's z-order in sprite-kit?

cocos2d code:

[parentnode addchild:sprite1 z:3]; [parentnode addchild:sprite2 z:2]; [parentnode addchild:sprite3 z:1]; 

i tried below code in sprite-kit..but not changing z-order

[parentnode insertchild:sprite1 atindex:3]; [parentnode insertchild:sprite2 atindex:2]; 

for draw order use zposition property of node:

zposition height of node relative parent.

the default value 0.0. positive z axis projected toward viewer nodes larger z values closer viewer. when node tree rendered, height of each node (in absolute coordinates) calculated , nodes in tree rendered smallest z value largest z value. if multiple nodes share same z position, nodes sorted parent nodes drawn before children, , siblings rendered in order appear in parent’s children array. hit-testing processed in opposite order.

the skview class’s ignoressiblingorder property controls whether node sorting enabled nodes @ same z position.

you can use insertchild:atindex: affect z order keep in mind index index of object in array, not it's zposition (ie atindex parameter not same z parameter in cocos2d, in fact it's inverse). nodes added @ lower index drawn before nodes @ higher index.

also note can't insert nodes @ index out of bounds. nsmutablearray docs:

[..] cannot insert object @ index greater current count of array. example, if array contains 2 objects, size 2, can add objects @ indices 0, 1, or 2. index 3 illegal , out of bounds; if try add object @ index 3 (when size of array 2), nsmutablearray raises exception.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -