gpt4 book ai didi

ios - 如何在 Sprite 工具包中为 touchesBegan 制作一个按钮

转载 作者:行者123 更新时间:2023-11-29 12:05:25 25 4
gpt4 key购买 nike

基本上现在我得到了 TitleScene,我的游戏的当前名称在哪里,当点击屏幕上的任何地方时它会跳转到 GameScene,它看起来像这样:

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

SKScene *scene = [GameScene sceneWithSize:self.size];
SKTransition *transition = [SKTransition pushWithDirection:SKTransitionDirectionUp duration:1.0f];
[self.view presentScene:scene transition:transition];
}

我的问题是如何将此方法更改为按钮?

最佳答案

也许给你的 Sprite 起一个名字“按钮”这样你就知道你在触摸哪个

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
/* Called when a touch begins */

for (UITouch *touch in touches) {
CGPoint location = [touch locationInNode:self];
SKNode *touchedNode = [self nodeAtPoint:location];

if (touchedNode && [touchedNode.name isEqual:@"button"]) {
// your code here
}
}
}

关于ios - 如何在 Sprite 工具包中为 touchesBegan 制作一个按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35214016/

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