1
我有以下代碼來創建動畫紋理:雪碧套件創建動畫對象
-(void) setUpActions {
SKTextureAtlas * atlas = [SKTextureAtlas atlasNamed:@"player"];
// Running player animation
SKTexture * runTexture1 = [atlas textureNamed:@"player1.png"];
SKTexture * runTexture2 = [atlas textureNamed:@"player2.png"];
SKTexture * runTexture3 = [atlas textureNamed:@"player3.png"];
SKTexture * runTexture4 = [atlas textureNamed:@"player4.png"];
SKTexture * runTexture5 = [atlas textureNamed:@"player5.png"];
SKTexture * runTexture6 = [atlas textureNamed:@"player6.png"];
SKTexture * runTexture7 = [atlas textureNamed:@"player7.png"];
SKTexture * runTexture8 = [atlas textureNamed:@"player8.png"];
NSArray * runTexture = @[runTexture1, runTexture2, runTexture3, runTexture4, runTexture5, runTexture6, runTexture7, runTexture8];
runAnimation = [SKAction animateWithTextures:runTexture timePerFrame:0.06 resize:YES restore:NO];
SKSpriteNode * playerNode = (SKSpriteNode *)[self childNodeWithName:@"player"];
[playerNode runAction:[SKAction repeatActionForever:runAnimation]];
}
,這將創建精靈節點,並添加到另一種方法場景:
-(SKSpriteNode *)createPlayer {
SKSpriteNode *player = [SKSpriteNode spriteNodeWithImageNamed:@"player"];
player.position = CGPointMake(100, 160);
player.name = @"player";
player.zPosition = 100;
return player;
}
做就這樣,我不得不創建一個具有靜態圖像的對象,並用動畫紋理覆蓋它。如何創建一個沒有默認靜態圖像的動畫對象?
很好用!非常感謝! – user2255273