Итак, я пытаюсь реализовать метод alterTime из примера EaseActionsTest из примера Cocos2D в моей игре.
Я пытаюсь реализовать эту идею в своей игре, чтобы создать тип времени замораживанияpowerup для моей игры.Я установил отдельный HUDLayer с CCMenu, чтобы изменить CCSpeed астероидов на 0, чтобы остановить движение.Я установил CCLog, чтобы убедиться, что мой метод freezeTime вызывается, что и происходит, но CCSpeeds астероидов остаются неизменными.Вот мой код для большей ясности.
HUDLayer.h
#import "ActionLayer.h"
@interface HUDLayer : CCLayer {
GameObject *asteroid;
}
-(void)freezeTime:(ccTime)dt;
HUDLayer.mm
-(void)freezeTime:(ccTime)dt
{
id action = [asteroid getActionByTag:kTagAsteroidAction];
[action setSpeed:0.0f];
CCLOG(@"Freeze!");
}
-(void)createPowerUpButtons
{
CGSize winSize = [CCDirector sharedDirector].winSize;
CCSprite *freeze = [CCSprite spriteWithSpriteFrameName:@"powerup.png"];
CCMenuItem *freezeButton = [CCMenuItemImage itemFromNormalSprite:freeze selectedSprite:nil target:self selector:@selector(freezeTime)];
CCMenu *powerUpMenu = [CCMenu menuWithItems:freezeButton, nil];
powerUpMenu.position = ccp(winSize.width * 0.5, winSize.height * 0.1);
[self addChild:powerUpMenu];
}
-(id)init
{
if( (self = [super init]) )
{
[self createPowerUpButtons];
}
return self;
}
ActionLayer.h
#import "HUDLayer.h"
#import "GameObject.h"
enum Actions
{
kTagAsteroidAction = 1
};
@interface ActionLayer : CCLayer
{
GameObject *asteroid;
}
ActionLayer.mm
-(void)updateAsteroids:(ccTime)dt
{
// ---------------------------------------------
// Code to set random sizes and speeds for the asteroids from the array...
// ---------------------------------------------
// Move it offscreen to the left, and when it's done, call removeNode
id action = [CCSequence actions:
[CCMoveBy actionWithDuration:randDuration position:ccp(-winSize.width - asteroid.contentSize.width, 0)],
[CCCallFuncN actionWithTarget:self selector:@selector(invisNode:)], nil];
[action setTag:kTagAsteroidAction];
[asteroid runAction:[CCSpeed actionWithAction:action speed:1.0f]];
[self schedule:@selector(freezeTime:) interval:1.0f];
}
}
-(void)update:(ccTime)dt
{
[self updateAsteroids:dt];
}
Я пытался приблизиться к примеру EaseActionsTest настолько близко, насколько смог, но я получаю эту ошибку при запуске:
'+[NSInvocation invocationWithMethodSignature:]: method signature argument cannot be nil'
Я думаю, что это из-за - (void) freezeTime: (ccTime) dt , потому что док этому я изначально пытался просто - (void) freezeTime;Я получил бы CCLog, который я установил в методе freezeTime, видя, что он вызывается, но скорости астероидов не были затронуты.
Также я попытался:
-(void)freezeTime
{
id action = [asteroid getActionByTag:kTagAsteroidAction];
[action setSpeed:0.1f];
CCLOG(@"Freeze!");
}
-(id)init
{
if( (self = [super init]) )
{
[self freezeTime];
}
return self;
}
Я только что заметилчто скорости здесь тоже не влияют.
Есть идеи, что я могу сделать, чтобы эта работа работала?Любые полезные идеи всегда приветствуются!