简体   繁体   中英

Changing a SKSpriteNode's anchor point during animation?

So I have the function below that starts my characters attack animation, the only problem is that the two textures are different sizes hence the "resize: true". What I want to do is change the anchor point of the second texture so that when my character attacks instead of the second texture being centered, moving the body of the character, I want it to be slightly offset to the right so that the body aligns with the previous texture's body.

Is there a way to have anchor points specific to a texture or would I need to change the Sprite's anchor point between frames?

func attackLeft() {
    attackLeftFrames = [attackLeft1, attackLeft2]
    attackLeftAction = SKAction.animate(with: attackLeftFrames, timePerFrame: 0.25, resize:true, restore:true)
    forever = SKAction.repeatForever(attackLeftAction)
    self.run(forever, withKey: "attackLeft")
}

So because I am working with fairly simple sprites (64x64) I just changed the texture itself, adding a specific amount of pixels to either side of the image to make it centered as the other would be. I would still like to know how to do this programmatically if possible though for future reference.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM