gpt4 book ai didi

ios - 如何在 SpriteKit 中添加高亮按钮?

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:14:46 26 4
gpt4 key购买 nike

我知道如何在 SpriteKit 中添加 Button。

我已经完成了 SKSpriteNode。但是我不知道如何添加像 UIButton 这样的高亮按钮。

我的意思是,当我按下 SKSpriteNode(Button) 时,我想显示突出显示的图像,例如来自 UIKit 的 UIButton

我该怎么做?

这是我的代码,用于 ButtonSKSpriteNode

self.playButton = [SKSpriteNode spriteNodeWithImageNamed:@"playButton.png"];
self.playButton.position = CGPointMake(self.frame.origin.x + 400, 100);
self.playButton.name = @"playButton";
self.playButton.zPosition = 2;
[self addChild:self.playButton];

最佳答案

我试过了,得到了你想要的东西,

  BOOL isMySpriteNodeTouched = NO;
mySprite = [[SKSpriteNode alloc]initWithImageNamed:@"ball"];
mySprite.position = CGPointMake(self.size.width/2.0f, self.size.height/2.0f);
mySprite.name = @"mySprite";
[self addChild:mySprite];


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

{
for (UITouch *touch in touches)
{
CGPoint touchPoint = [touch locationInNode:self];
SKNode *localNode = [[SKNode alloc]init];
localNode = [self nodeAtPoint:touchPoint];

if ([localNode.name isEqualToString:mySprite.name])
{
mySprite.texture = [SKTexture textureWithImage:[UIImage imageNamed:@"highlightedBall"]];
isMySpriteNodeTouched = YES;
}
}



-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
if(isMySpriteNodeTouched)
{
isMySpriteNodeTouched = !isMySpriteNodeTouched;
mysprite.texture = [SKTexture textureWithImage:[UIImage imageNamed:@"ball"]];
}
}

关于ios - 如何在 SpriteKit 中添加高亮按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29852145/

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