Thursday, October 21, 2010

Scrolling the background

Currently the scrolling is done by CCParallaxNode. There is 3 children layer added to the node, and when it's moved by 480pixels away, the node is positioned back to the origo, and the children elements get's a new texture.
It's fast, but it should work with offsets to remove the positioning of the parallax node from the code.
It was a bit hard to found out how to reposition the child elements. First I tried to go throw them, and set the new position, but nothing happened. After 1 hour I started to dig into Cocos2D and came up with this solution:
for(unsigned int i=0; i < parallaxArray_->num; i++ ) {
    [parallaxArray_->arr[i] setOffset:ccpAdd([parallaxArray_->arr[i] offset], offsetToAdd)];
}

0 comments:

Post a Comment