SKShapeNode消耗太多内存并减慢动画-Spritekit iOS [英] SKShapeNode consuming too much memory and slowing down animation -Spritekit iOS

查看:518
本文介绍了SKShapeNode消耗太多内存并减慢动画-Spritekit iOS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用SKShapeNode创建一个像山一样的对象。我使用CGMutablePathRef给我的路径分数

I am using SKShapeNode to to create a mountain like object . I use CGMutablePathRef to give the points to my path

SKShapeNode *shapenode = [[SKShapeNode alloc] init];

CGMutablePathRef path = CGPathCreateMutable();
CGPathMoveToPoint(path, NULL, 0, 0);
......
for (int i = 0; i < [refData count];i++) {


    CGPathAddLineToPoint(path, NULL, ((float)i/[refData count])*screenWidthBoundry,      [[refData objectAtIndex:i] doubleValue]);
}


CGPathAddLineToPoint(path, NULL, screenWidthBoundry, 0);
CGPathAddLineToPoint(path, NULL, 0, 0);

shapenode.path = path;
shapenode.antialiased = YES;
shapenode.fillColor = [SKColor colorWithRed:17.0/255.0 green:108.0/255.0 blue:125.0/255.0 alpha:1.0];
//shapenode.strokeColor = [UIColor clearColor];

shapenode.lineWidth = 1.0f;

shapenode.physicsBody = [SKPhysicsBody bodyWithEdgeChainFromPath:path];

shapenode.physicsBody.affectedByGravity = NO;
shapenode.physicsBody.categoryBitMask = CollisionTypeMountain;
shapenode.physicsBody.collisionBitMask = 0;
shapenode.physicsBody.contactTestBitMask = CollisionTypeBird;

CGPathRelease(path);
return shapenode;

我的问题是SkShapeNode正在减慢iPhone 4上的动画速度(在iPad和iPhone 5上顺利运行)但仍然不是60 fps)并消耗大量内存。我可以缓存skshapnode对象以顺利运行动画吗?任何帮助表示赞赏!!

My Problem is that SkShapeNode is slowing down the animation on iPhone 4 (runs smoothly on iPad and iPhone 5 but still not 60 fps) and consuming lot of memory. Can I cache skshapnode object to run animation smoothly ? Any Help is appreciated !!

推荐答案

我遇到了同样的问题,SKShapeNodes占用了太多的CPU资源并导致帧率下降。使用SKView的 textureFromNode:方法创建SKTexture。现在创建一个SKSpriteNode,其中包含生成视图的SKTexture。这将解决您的性能问题。

I was running into the same problem with SKShapeNodes consuming too much cpu resources and killing the framerate. Use your SKView's textureFromNode: method to create an SKTexture. Now create an SKSpriteNode with the SKTexture your view generated. This will fix your performance issues.

从SKShapeNode创建SKTexture

这篇关于SKShapeNode消耗太多内存并减慢动画-Spritekit iOS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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