Guest User

Untitled

a guest
Jun 18th, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.34 KB | None | 0 0
  1. #import "MainScene.h"
  2. #import "Sprite.h"
  3. #import "cocos2d.h"
  4. #import "PictureLayer.h"
  5. #import "MotionLayer.h"
  6. @implementation MainScene
  7. @synthesize myArray;
  8. - (void)rippleX:(float)x andY:(float)y; {
  9. Sprite *myBackground = [myArray objectAtIndex:0];
  10. NSLog( @">> %@ %f,%f", myBackground, x, y ); // Sprite is there along
  11. with
  12. the x and y
  13. [myBackground runAction: [Ripple3D actionWithPosition:ccp(x,y) radius:
  14. 240
  15. waves:2 amplitude:60 grid:ccg(32,24) duration:2]];
  16.  
  17. }
  18.  
  19. - (id)init {
  20. self = [super init];
  21. if( self != nil ){
  22. Sprite *background = [Sprite spriteWithFile:@"background.png"];
  23. background.position = ccp( 240, 160 );
  24. background.tag = 500;
  25. myArray = [[NSMutableArray alloc] init];
  26. [myArray addObject:background];
  27. [self addChild:background];
  28. //PictureLayer *pictureLayer = [PictureLayer node];
  29. //[self addChild:pictureLayer];
  30. MotionLayer *motionLayer = [MotionLayer node];
  31. [self addChild:motionLayer];
  32. id liquid = [Liquid actionWithWaves:4 amplitude:8 grid:ccg(30,30)
  33. duration:
  34. 10];
  35. [background runAction:[RepeatForever actionWithAction:[Sequence
  36. actions:
  37. liquid, nil]]];
  38. //[background runAction: [Ripple3D actionWithPosition:ccp(240,100)
  39. radius:100 waves:2 amplitude:60 grid:ccg(32,24) duration:2]]; // this
  40. works
  41.  
  42. }
  43.  
  44. return self;
  45.  
  46. }
  47.  
  48. @end
  49. Now, when I call the runAction within the init block, it works fine.
  50. (the
  51. ripple). When I call the rippleX from my Layer, I get no ripple,
  52. although
  53. the Sprite and x, y log for me.
  54. Here is my .,m for MotionLayer
  55. #import "MotionLayer.h"
  56. #import "MainScene.h"
  57. #import "Ball.h"
  58. #import "cocos2d.h"
  59. @implementation MotionLayer
  60. - (BOOL)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
  61. UITouch *touch = [touches anyObject];
  62. CGPoint currentPosition = [touch locationInView:[touch view]];
  63. CGPoint cLoc = [[Director sharedDirector] convertCoordinate:
  64. currentPosition];
  65. float myX = cLoc.x;
  66. float myY = cLoc.y;
  67. MainScene *obj = [[MainScene alloc] init];
  68. [obj rippleX:myX andY:myY]; // works
  69. return kEventHandled;
  70.  
  71. }
  72.  
  73. - (id)init {
  74. self = [super init];
  75. if( self != nil ){
  76. self.isTouchEnabled = YES;
  77. Ball *ball = [Ball node];
  78. ball.position = ccp( 200,200);
  79. ball.vx = 300;
  80. ball.vy = 200;
  81. [self addChild:ball];
  82. Ball *ball2 = [Ball node];
  83. ball2.position = ccp( 100, 100 );
  84. ball2.vx = 200;
  85. ball2.vy = 200;
  86. [self addChild:ball2];
  87.  
  88. }
  89.  
  90. return self;
  91.  
  92. }
  93.  
  94. @end
Add Comment
Please, Sign In to add comment