プレーヤー クラスで宣言された 2 つのアニメーションがあり、別のクラスから実行したいのですが、ここにコードを表示できません (ここで読めない場合は、pastebin にあります: http://pastebin.com/iy0eFMWL ) : player.h
@interface Player : CCSprite {
CCAnimate *animationOllie;
CCRepeatForever *repeatNormal;
}
player.m:
@implementation Player
-(id)initWithFile:(NSString *)filename
{
if (self = [super initWithFile:filename]) {
self.velocity = ccp(0.0, 0.0);
CCAnimation *ollie = [CCAnimation animation];
[ollie setDelayPerUnit:0.05f];
[ollie addSpriteFrameWithFilename:@"ollie1.png"];
[ollie addSpriteFrameWithFilename:@"ollie2.png"];
animationOllie = [CCAnimate actionWithAnimation:ollie];
CCAnimation *normal = [CCAnimation animation];
[normal setDelayPerUnit:0.05f];
[normal addSpriteFrameWithFilename:@"normal1.png"];
[normal addSpriteFrameWithFilename:@"normal2.png"];
CCAnimate *animationNormal = [CCAnimate actionWithAnimation:normal];
repeatNormal = [CCRepeatForever actionWithAction:animationNormal];
[self runAction:repeatNormal];
}
return self;
}
-(void)animateThePlayer {
[self stopAction:repeatNormal];
[self runAction:animationOllie];
}
GameScene クラス: GameScene.h:
@interface GamePlayLayer : CCLayerColor {
float yVel;
}
GameScene.m:
#import "Player.h"
@interface GamePlayLayer()
{
Player *player;
}
@end
@implementation GamePlayLayer
-(id) init
{
if( (self=[super initWithColor:ccc4(255,255,255,255)] )) {
player = [[Player alloc] initWithFile:@"normal1.png"];
[self addChild:player];
self.isTouchEnabled = YES;
player.position = ccp(85,70);
[self schedule:@selector(update:)];
}
return self;
}
-(void)update:(ccTime)dt {
if (player.position.y > 70) {
yVel -= 0.1;
}
else {
if (yVel != 5.5) {
yVel = 0;
player.position = ccp(player.position.x, 70);
}
}
player.position = ccp(player.position.x, player.position.y + yVel);
}
- (void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
yVel = 5.5;
[player animateThePlayer];
}
それだけです。問題なくビルドされ、すべてが機能しますが、レイヤーをクリックするとクラッシュし、次のメッセージが表示されます。
0x1df609b: movl 8(%edx), %edi スレッド 1: EXC_BAD_ACCESS (コード=2, アドレス=0xf
私に何ができる?前もって感謝します