Sprite kit 雪碧套件,按钮按下延迟
我正在写一个精灵工具包游戏,它使用按钮,它们是游戏中非常重要的一部分。问题是我需要他们有延迟,所以假设你只能每5分钟按一次。提前感谢你的帮助 .H文件Sprite kit 雪碧套件,按钮按下延迟,sprite-kit,Sprite Kit,我正在写一个精灵工具包游戏,它使用按钮,它们是游戏中非常重要的一部分。问题是我需要他们有延迟,所以假设你只能每5分钟按一次。提前感谢你的帮助 .H文件 typedef NS_ENUM(NSInteger, ButtonState) { On, Off }; @interface Button2 : SKLabelNode - (instancetype)initWithState:(ButtonState) setUpS
typedef NS_ENUM(NSInteger, ButtonState)
{
On,
Off
};
@interface Button2 : SKLabelNode
- (instancetype)initWithState:(ButtonState) setUpState;
- (void) buttonPressed;
@end
.M文件
@implementation Button2
{
ButtonState _currentState;
}
- (id)initWithState:(ButtonState) setUpState
{
if (self = [super init]) {
_currentState = setUpState;
self = [Button2 labelNodeWithFontNamed:@"Chalkduster"];
self.text = [self updateLabelForCurrentState];
self.fontSize = 30;
}
return self;
}
- (NSString *) updateLabelForCurrentState
{
NSString *label;
if (_currentState == On) {
label = @"Sell";
}
else if (_currentState == Off) {
}
return label;
}
- (void) buttonPressed
{
if (_currentState == Off) {
_currentState = On;
}
else {
_currentState = Off;
}
self.text = [self updateLabelForCurrentState];
}
@end
我猜触摸代理是在场景中实现的,使用该场景可以在触摸点找到节点,并在其上调用buttonPressed方法 您可以设置bool标志,按下按钮时可以设置该标志 在.h文件中:
@property BOOL interactionAllowed;
可以在场景的触摸代理中访问此属性,如:
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
CGPoint touchPoint = [touch locationInNode:self];
SKNode *node = [self nodeAtPoint:touchPoint];
if ([node isKindOfClass:[Button2 class]])
{
Button2 *button = (Button2*)node;
if (button.interactionAllowed)
{
[button buttonPressed];
}
}
}
关于设置(和重置)interactionAllowed属性:
- (void) buttonPressed
{
if (_currentState == Off) {
_currentState = On;
self.interactionAllowed = NO;
[self runAction:[SKAction sequence:@[[SKAction waitForDuration:3000], [SKAction runBlock:^{
self.interactionAllowed = YES;
}]]]];
}
else {
_currentState = Off;
}
self.text = [self updateLabelForCurrentState];
}
我收到1个错误和1个警告,我无法解决如何修复它们。错误-方法调用的参数太多,应为1,有2个警告不兼容的指针类型将“SKAction*”发送到“NSArray*”类型的参数。请检查编辑后的答案。。。我直接写了这段代码,没有把序列对象放在ArrayTanks中,你知道我如何在屏幕上显示它吗?显示什么?时间倒计时?