I am creating a breakout style game for iOS8 where blocks fall from the top of the screen.
I decided to try Apple's new SKLightNode in the sprite kit, and it worked fine, casting light at the top of the screen:
in levelScene.h:
#import <SpriteKit/SpriteKit.h>
in levelScene.m:
-(id)initWithSize:(CGSize)size { ... SKLightNode* light = [[SKLightNode alloc] init];
and casting a shadow from the oar at the bottom of the screen:
-(id)initWithSize:(CGSize)size { ... self.paddle.shadowCastBitMask = lightCategory; ... }
However, when I try to make my falling blocks cast shadows by defining the shadowCastBitMask of my rectangle (or block) spriteNodes, which, unlike the paddles, are added at different intervals during the game, I experience a strange kind of clipping where the whole screen and all its contents vary up to about 60% -80% of the original size, slightly contracting vertically. Only for the shortest moments, so I canโt get a decent idea of โโwhat he even does with the image, not to mention why. I did not find anything related to this error on the Internet.
I can say that it plays every time , that the block enters the top of the screen, even the first time, assuming that it has nothing to do with calling multiple instances at the same time. Since the paddle (and the ball when testing) seems to cast a shadow without problems, I can only assume that this is either due to the fact that the call is made during the game, and not before it starts, as is the case with the paddle, or that in my call to -addRectangle has something that I am missing.
So here is the whole (void) addRectangle, the call to shadowCastBitMask = ... is close to the end:
- (void)addRectangle { // Create sprite self.rectangle = [SKSpriteNode spriteNodeWithImageNamed:@"Rectangle"]; // Determine where to spawn the rectangle along the X axis int minX = (CGRectGetMinX(self.frame) + (self.rectangle.size.width/2)) ; int maxX= (( CGRectGetMaxX(self.frame)) - (self.rectangle.size.width)) ; int actualX = ( arc4random_uniform(maxX) +minX); // Create the rectangle slightly off-screen self.rectangle.position = CGPointMake(actualX, self.frame.size.height + self.rectangle.size.height/1); self.rectangle.zPosition = 5; // Determine speed of the rectangle if(multiplier>=29 && multiplier<49){ int minDuration = 5.5; int maxDuration = 7.0; int rangeDuration = maxDuration - minDuration; int actualDuration = (arc4random() % rangeDuration) + minDuration; // Create the actions SKAction * actionMove = [SKAction moveTo:CGPointMake(actualX, -self.rectangle.size.height/1) duration:actualDuration]; [self.rectangle runAction:actionMove]; } if(multiplier>=49 && multiplier < 99){ int minDuration = 4.0; int maxDuration = 5.0; int rangeDuration = maxDuration - minDuration; int actualDuration = (arc4random() % rangeDuration) + minDuration; // Create the actions SKAction * actionMove = [SKAction moveTo:CGPointMake(actualX, -self.rectangle.size.height/1) duration:actualDuration]; [self.rectangle runAction:actionMove]; } if(multiplier>=99){ int minDuration = 3.0; int maxDuration = 4.0; int rangeDuration = maxDuration - minDuration; int actualDuration = (arc4random() % rangeDuration) + minDuration; // Create the actions SKAction * actionMove = [SKAction moveTo:CGPointMake(actualX, -self.rectangle.size.height/1) duration:actualDuration]; [self.rectangle runAction:actionMove]; } else if (multiplier<29){ int minDuration = 6.0; int maxDuration = 10.0; int rangeDuration = maxDuration - minDuration; int actualDuration = (arc4random() % rangeDuration) + minDuration; // Create the actions SKAction * actionMove = [SKAction moveTo:CGPointMake(actualX, -self.rectangle.size.height/1) duration:actualDuration]; [self.rectangle runAction:actionMove]; } self.rectangle.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:self.rectangle.size]; self.rectangle.physicsBody.dynamic = YES; self.rectangle.physicsBody.restitution = 0.4f; self.rectangle.physicsBody.density = 1000; self.rectangle.physicsBody.categoryBitMask = blockCategory; self.rectangle.physicsBody.contactTestBitMask = bottomCategory | paddleCategory | laserCategory; self.rectangle.physicsBody.collisionBitMask = 0x0 ; self.rectangle.physicsBody.affectedByGravity = NO; //the offending line: self.rectangle.shadowCastBitMask = lightCategory; [self addChild:self.rectangle]; [_blocks addObject:self.rectangle]; _EyeLeft = [SKSpriteNode spriteNodeWithImageNamed:@"Eye"]; _EyeLeft.position = CGPointMake(_EyeLeft.parent.position.x-10, _EyeLeft.parent.position.y) ; // _EyeLeft.zPosition = 7; _EyeLeft.physicsBody.allowsRotation = YES; _EyeLeft.name = @"Eye"; [self.rectangle addChild: _EyeLeft]; [_Eyes addObject:_EyeLeft]; _EyeRight = [SKSpriteNode spriteNodeWithImageNamed:@"Eye"]; _EyeRight.position = CGPointMake(_EyeRight.parent.position.x+10, _EyeRight.parent.position.y) ; // _EyeRight.zPosition = 7; _EyeRight.physicsBody.allowsRotation = YES; _EyeRight.name = @"Eye"; // _EyeLeft.physicsBody.angularDamping = 0.2; [self.rectangle addChild: _EyeRight]; [_Eyes addObject:_EyeRight]; }
The error will not be reproduced if I simply delete the shadowCastBitMask = ... call, but then I have no shadows.
I also do not understand why the whole picture will change, since I am not, as far as I know, a call to any commands related to the scale or scene at that time, of course, not caused by such a call.
Any help in general will be appreciated. Thank you in advance for your time and any help.