gpt4 book ai didi

ios - 'Player' 没有可见的@interface 声明选择器 'walkRight'

转载 作者:行者123 更新时间:2023-11-29 10:41:26 26 4
gpt4 key购买 nike

//播放器.m

#import "Player.h"
@implementation Player

+(id)player{

Player *player = [Player spriteNodeWithColor:[UIColor brownColor] size:CGSizeMake(32, 32)];

player.name = @"player";

player.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:player.size];

return player;

}



- (void)walkRight {

SKAction *incRight = [SKAction moveByX:10 y:0 duration:0];

[self runAction:incRight];

}


@end

//MyScene.h

#import "MyScene.h"
#import "Player.h"



@implementation MyScene

-(id)initWithSize:(CGSize)size {

if (self = [super initWithSize:size]) {

/* Setup your scene here */

self.anchorPoint = CGPointMake(0.5, 0.5);

self.backgroundColor = [SKColor colorWithRed:0.15 green:0.15 blue:0.3 alpha:1.0];



SKSpriteNode *ground = [SKSpriteNode spriteNodeWithColor:[UIColor greenColor] size:CGSizeMake(self.frame.size.width, 30)];

ground.position = CGPointMake(0, -self.frame.size.height/2 + ground.frame.size.height/2);

ground.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:ground.size];

ground.physicsBody.dynamic = NO;

[self addChild:ground];



Player *player = [Player player];

[self addChild:player];

}

return self;

}



-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

Player *player = (Player *)[self childNodeWithName:@"player"];

[player walkRight];



}



-(void)update:(CFTimeInterval)currentTime {

/* Called before each frame is rendered */

}



@end

我是 objective-c 的新手。好吧,我尝试构建上面的代码并得到错误“'Player'的不可见@interface声明选择器'walkRight'”我真的不知道为什么。如果有人能帮助我,我将不胜感激。谢谢。

最佳答案

确保您已在 Player.h 文件中声明了 walkRight 方法。这应该在该文件中的接口(interface)声明之后的某个地方:

-(void)walkRight;

这允许导入 Player.h 的其他文件知道 Player.m 实现了 walkRight 方法。

关于ios - 'Player' 没有可见的@interface 声明选择器 'walkRight',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24377901/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com