0
我想創建脈衝平臺並在CCScale中遇到一些問題。 我有我的平臺,NSMuttableArray類的一些對象。Cocos2d CCScale
@interface Platforms : CCNode{
CCSprite *platformSprite;
int typeP;
}
@property (nonatomic, retain) CCSprite *platformSprite;
@property int typeP;
@implementation
- (id)init:(int)type
{
self = [super init];
if (self != nil) {
typeP = type;
platformSprite = [CCSprite spriteWithFile:@"ball.png" rect:CGRectMake(0, 0, 51, 52)];
[self addChild:platformSprite];
}
return self;
}
我添加的所有對象篩選
for (int i = 0 ; i < [_array count]; i++) {
Platforms* _platforms2 = [[_array objectAtIndex:i ]retain];
[self addChild:_platforms2];
[_platforms2 release];
}
所以...我想獲得的所有對象,其中typeP == 1 我得到這一切的對象並將它們添加到NSMuttableArray
for (int i = 0 ; i < [platformsArrayOnScreen count]; i++) {
Platforms* temp = [platformsArrayOnScreen objectAtIndex:i];
if (temp.typeP == 1) {
[scaleArray addObject:temp];
}
比我想所有的人擴展到[CCScaleTo actionWithDuration:0.5 scale:0.2f];
和規模[CCScaleTo actionWithDuration:0.5 scale:1.0f];
後,我創建功能[self schedule:@selector(checkForScale:)];
-(void)checkForScale:(ccTime)dt {
for (int i = 0; i < [scaleArray count]; i++) {
Platforms* temp2 = [scaleArray objectAtIndex:i];
if ([temp2.platformSprite scale] == 1.0f) {
[self scaleDown:temp2];
}
if([temp2.platformSprite scale] == 0.2f){
[self scaleUp:temp2];
}
}
}
-(void)scaleDown:(Platforms *)tempSprite {
id scaleDown = [CCScaleTo actionWithDuration:0.3 scaleX:0.2f scaleY:0.2f];
[tempSprite.platformSprite runAction:scaleDown];
}
-(void)scaleUp:(Platforms *)tempSprite {
id scaleUp = [CCScaleTo actionWithDuration:0.3 scaleX:1.0f scaleY:1.0f];
[tempSprite runAction:scaleUp];
}
但它不工作((我的平臺不脈動。我的問題在哪裏? 謝謝。
分別稱爲比例放大/按比例縮小?你應該在那裏設置一個斷點並找出答案。我能想象的唯一事情就是與浮點值相等是棘手的。即規模性質可能不完全是0.2f,但0.199999999f或0.200000001f – LearnCocos2D