Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #import "MainScene.h"
- #import "Sprite.h"
- #import "cocos2d.h"
- #import "PictureLayer.h"
- #import "MotionLayer.h"
- @implementation MainScene
- @synthesize myArray;
- - (void)rippleX:(float)x andY:(float)y; {
- Sprite *myBackground = [myArray objectAtIndex:0];
- NSLog( @">> %@ %f,%f", myBackground, x, y ); // Sprite is there along
- with
- the x and y
- [myBackground runAction: [Ripple3D actionWithPosition:ccp(x,y) radius:
- 240
- waves:2 amplitude:60 grid:ccg(32,24) duration:2]];
- }
- - (id)init {
- self = [super init];
- if( self != nil ){
- Sprite *background = [Sprite spriteWithFile:@"background.png"];
- background.position = ccp( 240, 160 );
- background.tag = 500;
- myArray = [[NSMutableArray alloc] init];
- [myArray addObject:background];
- [self addChild:background];
- //PictureLayer *pictureLayer = [PictureLayer node];
- //[self addChild:pictureLayer];
- MotionLayer *motionLayer = [MotionLayer node];
- [self addChild:motionLayer];
- id liquid = [Liquid actionWithWaves:4 amplitude:8 grid:ccg(30,30)
- duration:
- 10];
- [background runAction:[RepeatForever actionWithAction:[Sequence
- actions:
- liquid, nil]]];
- //[background runAction: [Ripple3D actionWithPosition:ccp(240,100)
- radius:100 waves:2 amplitude:60 grid:ccg(32,24) duration:2]]; // this
- works
- }
- return self;
- }
- @end
- Now, when I call the runAction within the init block, it works fine.
- (the
- ripple). When I call the rippleX from my Layer, I get no ripple,
- although
- the Sprite and x, y log for me.
- Here is my .,m for MotionLayer
- #import "MotionLayer.h"
- #import "MainScene.h"
- #import "Ball.h"
- #import "cocos2d.h"
- @implementation MotionLayer
- - (BOOL)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
- UITouch *touch = [touches anyObject];
- CGPoint currentPosition = [touch locationInView:[touch view]];
- CGPoint cLoc = [[Director sharedDirector] convertCoordinate:
- currentPosition];
- float myX = cLoc.x;
- float myY = cLoc.y;
- MainScene *obj = [[MainScene alloc] init];
- [obj rippleX:myX andY:myY]; // works
- return kEventHandled;
- }
- - (id)init {
- self = [super init];
- if( self != nil ){
- self.isTouchEnabled = YES;
- Ball *ball = [Ball node];
- ball.position = ccp( 200,200);
- ball.vx = 300;
- ball.vy = 200;
- [self addChild:ball];
- Ball *ball2 = [Ball node];
- ball2.position = ccp( 100, 100 );
- ball2.vx = 200;
- ball2.vy = 200;
- [self addChild:ball2];
- }
- return self;
- }
- @end
Add Comment
Please, Sign In to add comment