Guest User

Untitled

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