我认为这很容易成为一个简单的问题但不适合我。我在循环中,我看不出答案。
我尝试访问对象内部的方法但是收到此消息:
-[SKSpriteNode playWordSound]: unrecognized selector sent to instance 0x7fbd75e52a60
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[SKSpriteNode playWordSound]: unrecognized selector sent to instance 0x7fbd75e52a60' ***
我的代码如下:
Word.h
#import <SpriteKit/SpriteKit.h>
@interface Word : SKSpriteNode
- (instancetype)init;
- (void)playWordSound;
@end
Word.m
#import "Word.h"
@implementation Word
- (instancetype)init {
if (self = [super init]) {
[self createWord];
// some physics here
}
return self;
}
// Crear la ball con el word
- (void)createWord {
// some code here
}
- (void)playWordSound {
// some code to play a sound
}
在MyScene中调用的代码是:
- (void)didBeginContact:(SKPhysicsContact *)contact {
// …
if (other.categoryBitMask & PCWordCategory) {
Word *wordEffect = (Word *)other.node;
[self flyAwayWord:wordEffect];
// HERE IS THE ERROR —
[wordEffect playWordSound];
// HERE IS THE ERROR -
wordEffect.physicsBody = nil;
}
// …
}
此方法的定义有什么问题。对不起,但我看不出一些明显的。
答案 0 :(得分:1)
你投错了类型:
Word *wordEffect = (Word *)other.node;
你认为它是Word,但实际上它是
SKSpriteNode