SpriteKit质地不可见 [英] SpriteKit texture not visible

查看:174
本文介绍了SpriteKit质地不可见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个游戏,也有与一些动画,当用户使用移动游戏控制其中起,战斗文字等。

有一个正常状态,即当用户没有触摸任何控制,玩家的人物的质感已被分配到正常状态或休息状态的质感。

如果用户非常快速地行使这些控件,那么玩家的人物的质感,他又回到了正常状态时消失。如果任何控件都不过使用,那么动画是可见的。

谁能帮我这个问题?任何帮助将大大AP preciated。

我已经显示了一些我在下面使用的基本编程结构。

  // ------------------------------------ -------------------------------------* //正常或休息状态的质感。*SKAction * normalStateAction = [SKAction setTexture:normalStateTexture];
* //播放任何角色动画像走,打,跳等。*[playerCharacter.sprite runAction:[SKAction顺序:@ [charAnimAction,normalStateAction]]];
* //在任何游戏控制的TouchesEnded'方法。* - (无效){TouchesEnded    //删除previous行动。
    [playerCharacter.sprite removeAllActions]    //运行正常国家行动。
    [playerCharacter.sprite runAction:normalStateAction];
}// ------------------------------------------------ -------------------------


解决方案

我相信我有一个类似的,如果不是同一个问题。我触发各种动画(其中尤其是动画是依赖于无论是在游戏正在进行)上触摸。当触摸是快速和动画快速射击时,SKSpriteNode的基础纹理似乎消失了。

坏消息是,我不知道是什么原因造成的。我做了什么来解决这个问题一直不断检查,如果我SKSprite节点上的纹理已设置为零后我运行一个SKAction。感觉浪费,使这个检查每一个我解雇一个动作的时间,但它已经解决了这一情况,并没有对我的游戏性能的感知影响。

所以,我在做这个样子的东西删节版(SWIFT):

  FUNC doAnimation(){    _character.runAction(someSKAction,withKey:动画)    //哎呀!我们又失去了我们的基地质感!
    如果_character.texture == {为零
        让地图集= SKTextureAtlas(命名为:someAtlasName)
        让质地= atlas.textureNamed(idleFrame)
        _character.texture =质感
    }
}

这看来似乎是某种SpriteKit的bug,因为我不觉得,我做任何事情太奇特。这很难确切地提出这样的观点,直到它可以分离和再现。

我很想知道您是否曾经解决了(而不是围绕砍死)这个问题。请分享如果你这样做,因为这解决办法是有点太哈克。谢谢你。

I'm developing a game where there are characters with a number of animations, which play when the user uses the game controls for moving, fighting, etc.

There is a normal state, i.e. when the user is not touching any control, the player's character's texture has been assigned to a Normal State or Resting State texture.

If the user exercises these controls very quickly, then the player's character's texture disappears when he goes back to the Normal state. If any of the controls are used however, then the animations are visible.

Can anyone help me with this issue? Any help would be greatly appreciated.

I have displayed some of the basic programming structure I have used below.

//------------------------------------------------------------------------- 

*// The 'Normal or Resting' state texture.*

SKAction *normalStateAction = [SKAction setTexture:normalStateTexture];


*// To Play any Character Animation like Walk, Fight, Jump, etc.*

[playerCharacter.sprite runAction:[SKAction sequence:@[charAnimAction,normalStateAction]]];


*// In the 'TouchesEnded' method for any Game Control.*

-(void)TouchesEnded {

    // Remove previous actions.
    [playerCharacter.sprite removeAllActions];

    // Run Normal State action.
    [playerCharacter.sprite runAction:normalStateAction];
}

//------------------------------------------------------------------------- 

解决方案

I believe I am having a similar, if not the same issue. I trigger various animations (where the particular animation is dependent on whatever is going on in the game) on touches. When the touches are rapid and the animations are firing quickly, the base texture of the SKSpriteNode seemingly disappears.

The bad news is that I don't know what is causing it. What I've done to work around the issue has been to constantly check if the texture on my SKSprite node has been set to nil immediately after I run an SKAction. It feels wasteful to make this check each time I fire an action, but it has resolved this situation and has not had a perceptible impact on the performance of my game.

So, an abridged version (in Swift) of what I'm doing looks like this :

func doAnimation(  ) {

    _character.runAction(someSKAction, withKey: "animation")

    //Whoops!, we lost our base texture again!
    if _character.texture == nil {
        let atlas = SKTextureAtlas(named: "someAtlasName")
        let texture = atlas.textureNamed("idleFrame" )
        _character.texture = texture
    }
}

This seems like it is some sort of SpriteKit bug, as I don't feel that I'm doing anything too exotic. It's difficult to definitively make that claim until it can be isolated and reproduced.

I would love to know if you ever resolved (rather than hacked around) this issue. Please share if you did, because this work around is a little too hacky. Thanks.

这篇关于SpriteKit质地不可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆