Button 缩放场景不';按钮的t刻度面积

Button 缩放场景不';按钮的t刻度面积,button,scaling,sprite-kit,Button,Scaling,Sprite Kit,为了将3.5英寸iPhone的场景缩放到4英寸的手机,我使用了这个代码 -(无效)createSceneContents{ if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) { CGSize result = [[UIScreen mainScreen] bounds].size; if(result.height == 480) { } if(result.height == 568)

为了将3.5英寸iPhone的场景缩放到4英寸的手机,我使用了这个代码

-(无效)createSceneContents{

if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
{
    CGSize result = [[UIScreen mainScreen] bounds].size;
    if(result.height == 480)
    {
    }
    if(result.height == 568)
    {
        [self runAction:[SKAction scaleXBy:1 y:1.2 duration:0]];
    }
}
它缩放的场景足够接近我的喜好,但我遇到了一个问题,点击按钮

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    UITouch *touch = [touches anyObject];
    CGPoint location = [touch locationInNode:self];
    SKNode *node = [self nodeAtPoint:location];

    if ([node.name isEqualToString:@"Saloon"]) {
        if (self.MOVING == NO) {
            self.SaloonWalk = YES;
            self.MOVING = YES;
        }
    }

问题是,当我点击酒馆时,即使它与场景一起缩放,我的代码仍然具有未缩放的尺寸。因此,如果我点击略低于酒馆的位置,它会运行上面的代码,但如果我在酒馆顶部附近点击,什么都不会发生。我已经进行了一些搜索,但在缩放触摸“否”区域方面没有找到任何帮助使用我新缩放的场景进行de。

假设您已将SKSpriteNode子类化以构建按钮,并且上面显示的ToucheSStart位于按钮子类中,则需要调用父级的位置:

CGPoint location = [touch locationInNode:self.parent];
由于locationInNode在传入的节点坐标中为您提供位置。如果您要查找按钮节点,则触摸对象应发送locationInNode和您要查找的对象的父节点