SpriteKit texture not visible

本秂侑毒 提交于 2019-12-12 06:38:07

问题


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];
}

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

回答1:


It might be me who is overlooking something, but don't you simply remove the touchesended code complete totally. Since all your actions end with the normal state, then you can just remove actions on the touchesBegan, and then let them run through their cycle even though the user up-touches.




回答2:


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.



来源:https://stackoverflow.com/questions/22218784/spritekit-texture-not-visible

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!