Hello there, is it possible to modify a node's ParallaxRatio and PositionOffset after it's added to a ParallaxNode?
Thanks in advance
Change ParallaxRatio and PositionOffset ?
(4 posts) (4 voices)-
Posted 2 years ago #
-
The best approach is to remove the child and re-add it with the new ratio/offset
Posted 2 years ago # -
ParallaxNode has a property called parallaxArray. It contains all objects (with their offsets and ratios) that were added to parallaxNode. You can retrieve object you want from that array and modify its ratio/offset values.
-- from ParallaxNode.h --
/** array that holds the offset / ratio of the children */
@property (nonatomic,readwrite) ccArray * parallaxArray;Posted 2 years ago # -
I created a wrapper function that went like this:
-(void) modifyChildRatio:(CocosNode*)child newRatio:(CGPoint)newRatio; { for(unsigned int i=0; i < parallaxArray_->num; i++ ) { CGPointObject *point = parallaxArray_->arr[i]; //NSLog(@"Checking %@", point.child); // Found it, modify its ratio if(point.child == child) { point.ratio = newRatio; } } }However when it was called, it messed up all the positions - I ended up discarding this function, and just working around it some other way, but just a heads up.
I think you'd have to modify the offset once the ratio is modified, but like I said i gave up this route and went another way.Posted 2 years ago #
Reply
You must log in to post.