我正在製作iOS8的球/槳「突圍」式遊戲,其中塊從屏幕頂部落下。當調用shadowCastBitMask時出現奇怪的屏幕調整大小錯誤=
我決定嘗試蘋果的精靈套件的新SKLightNode和它的工作奇妙,從屏幕頂部鑄造光:
在levelScene.h:
#import <SpriteKit/SpriteKit.h>
在levelScene.m
:
-(id)initWithSize:(CGSize)size {
...
SKLightNode* light = [[SKLightNode alloc] init];
// light.enabled = YES;
light.categoryBitMask = lightCategory;
light.falloff = 1;
light.ambientColor = [UIColor whiteColor];
light.lightColor = [[UIColor alloc] initWithRed:0.0 green:1.0 blue:0.5 alpha:0.5];
light.shadowColor = [[UIColor alloc] initWithRed:0.0 green:0.0 blue:0.0 alpha:0.2];
light.position = CGPointMake(CGRectGetMidX(self.frame), self.frame.size.height - 20);
[self addChild:light];
...
}
和鑄造從靠近屏幕底部的槳陰影:
-(id)initWithSize:(CGSize)size {
...
self.paddle.shadowCastBitMask = lightCategory;
...
}
但是,當我嘗試通過定義我的矩形(或塊)spriteNodes的shadowCastBitMask來投影陰影時,它與槳不同,在整個播放過程中以不同的間隔添加,我體驗了一種奇怪的裁剪整個屏幕及其所有內容重新調整到原始大小的60%-80%,並略微垂直壓扁。這只是最短暫的時刻,所以我無法獲得它對圖像做什麼的體面的想法,更不用說爲什麼了。我沒有發現任何關於這個bug的信息。
我可以說,它每再現一個塊從屏幕的頂部進入,即使是第一次,這表明它與多個實例同時被調用無關。由於槳(和測試時的球)似乎沒有問題地投下陰影,我只能假定它是與在遊戲過程中進行調用的事實有關,而不是在它開始之前進行的, paddle,或者我的-addRectangle調用中有某些東西在丟失。
所以,這裏是 - (無效)addRectangle其全部的shadowCastBitMask = ...呼叫已經接近尾聲:
- (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];
}
的錯誤,如果我只是刪除shadowCastBitMask不再現= ...打電話,但是我沒有得到陰影。
我也不明白爲什麼整幅圖片會調整大小,因爲據我所知,我並沒有調用當時與刻度或場景相關的任何命令,當然不會由這樣的調用觸發。
任何幫助都將不勝感激, 在此先感謝您的時間和任何幫助提供。
我得到這一點。你找到解決方案嗎? – RichS 2015-03-24 21:05:50
我從來沒有害怕,我放棄使用下降的塊的陰影,並在槳上使用它們,沒有問題,顯然:/ – lazyjoeco 2015-03-26 10:27:44
恥辱。謝謝回覆。 – RichS 2015-03-27 11:20:39