- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在我创建的游戏中,我创建了一种游戏模式,玩家有 30 秒的时间击中尽可能多的目标。我在 -(void)update:(CFTimeInterval)currentTime 方法中添加了一个 30 秒的倒数计时器。当倒计时开始时,帧速率显着下降,每当物体与目标发生碰撞时,就会使用 99% 的 cpu。当计时器未运行时,不会发生这种情况。还有另一种添加倒数计时器的方法吗?如果不是,我怎样才能减少CPU使用率并保持帧速率恒定?我正在使用 Xcode 6.1,代码如下。这也是 iOS 8 的问题。在 iOS 7.1 上运行良好。
-(void)update:(CFTimeInterval)currentTime {
/* Called before each frame is rendered */
//reset counter if starting
int highscoret = [[NSUserDefaults standardUserDefaults] integerForKey: @"highScoret"];
if (startGamePlay){
startTime = currentTime;
startGamePlay = NO;
}
countDown.text = [NSString stringWithFormat:@"Start!"];
int countDownInt = 30.0 -(int)(currentTime-startTime);
if(countDownInt>0){ //if counting down to 0 show counter
countDown.text = [NSString stringWithFormat:@"%i", countDownInt];
}else if(countDownInt==0) { //if not show message, dismiss, whatever you need to do.
countDown.text=@"Time's Up!";
self.highScoret.text = [NSString stringWithFormat:@"%d Baskets",highscoret];
SKScene *endGameScene = [[GameOverT alloc] initWithSize:self.size];
SKTransition *reveal = [SKTransition fadeWithDuration:0.5];
[self.view presentScene:endGameScene transition:reveal];
[self saveScore2];
if (self.points > highscoret) {
self.highScoret.text = [NSString stringWithFormat:@"%d Points",highscoret];
[self saveScore];
self.points = 0;
self.scoreLabel.text = [NSString stringWithFormat:@"%d Points",_points];
}
else {
self.points = 0;
self.scoreLabel.text = [NSString stringWithFormat:@"%d Points",_points];
self.highScoret.text = [NSString stringWithFormat:@"%d Points",highscoret];
}
}
}
这是其他相关代码
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
/* Called when a touch begins */
for (UITouch *touch in touches) {
CGPoint location = [touch locationInNode:self];
if (CGRectContainsPoint(countDown.frame, location)){
startGamePlay = YES;
self.baskett = 0;
[self reset];
}
}
UITouch * touch = [touches anyObject];
CGPoint location = [touch locationInNode:self];
SKSpriteNode * object = [SKSpriteNode spriteNodeWithImageNamed:@"object.png"];
object.position = self.object2.position;
object.physicsBody = [SKPhysicsBody bodyWithCircleOfRadius:ball.size.width/2];
object.physicsBody.dynamic = YES;
object.physicsBody.categoryBitMask = objectCategory;
object.physicsBody.contactTestBitMask = targetCategory;
object.physicsBody.collisionBitMask = 0;
object.physicsBody.usesPreciseCollisionDetection = YES;
CGPoint offset = rwSub(location, object.position);
if (offset.y <= 0) return;
[self addChild:object];
CGPoint direction = rwNormalize(offset);
CGPoint shootAmount = rwMult(direction, 1000);
CGPoint realDest = rwAdd(shootAmount, object.position);
float velocity = 200/1.0;
float realMoveDuration = self.size.width / velocity;
SKAction * actionMove = [SKAction moveTo:realDest duration:realMoveDuration];
SKAction * actionMoveDone = [SKAction removeFromParent];
[object runAction:[SKAction sequence:@[actionMove, actionMoveDone]]];
}
-(void)object:(SKSpriteNode *) object didCollideWithTarget:(SKSpriteNode *) target {
[object removeFromParent];
[[self scene] runAction:[SKAction playSoundFileNamed:@"effect2.wav" waitForCompletion:NO]];
self.points++;
self.scoreLabel.text = [NSString stringWithFormat:@"%d Points",_points];
if (self.points == 3) {
[self obstacle];
}
}
最佳答案
更新函数中的计时器不是一个好主意,将 skaction 与 waitForDuration 一起使用可能会解决您的问题
SKAction *updateTime= [SKAction sequence:@[
///fire function after one second
[SKAction waitForDuration:1.0f],
[SKAction performSelector:@selector(callFunction)
onTarget:self]
]];
//where 30 is number of time you want’s to call your function
[self runAction:[SKAction repeatAction:updateTime count:30] ];
-(void) callFunction
{
//what ever you want to do
}
关于iOS 8 如何防止 Spritekit 帧率下降,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26599503/
我使用 QBFC v13 和 Delphi XE6。 目标是从我的应用程序创建 Estimate 并将其参数设置到 QuickBooks 中。 我从 QBFC13 导入类型库并将其添加到我的项目中。
我有一个数据库,其中有很多格式不正确的地址。在这个地址中,我只有一个街道地址或带有城市名称的街道。在我的应用程序中,用户选择一些类别,然后我想在 map 上显示例如 50,100,300 等地址。(不
在大多数软件项目中,缺陷源自需求、设计、编码和缺陷更正。根据我的经验,大多数缺陷都源于编码阶段。 我有兴趣了解软件开发人员使用哪些实用方法来降低缺陷注入(inject)率。 我已经看到以下方法的使用取
我正在使用实时 API 中的标签订阅构建一个应用程序,并且有一个与容量规划相关的问题。我们可能有大量用户同时发布到订阅的主题标签,因此问题是 API 实际发布到我们的订阅处理端点的频率是多少?例如,如
尝试使用 NULLIF 或 IFNULL 函数,但仍收到被零除的消息。 SELECT client_id ,COUNT(distinct CASE WHEN status = 'failed' THE
我目前正在开发一个使用 Django-rest-framework 制作的 API。我必须根据每个用户组设置限制率。 我们目前使用默认配置的 memcached 作为缓存后端,即按站点缓存。 在使用
我认为有时在神经网络(特别是一般对抗网络)训练期间改变丢失率可能是一个好主意,从高丢失率开始,然后线性地将丢失率降低到零。您认为这有意义吗?如果是的话,是否有可能在 tensorflow 中实现这一点
我有一个 Windows Server 2008,Plesk 运行着两个网站。有时服务器运行缓慢,并且有一个 named.exe 进程使 CPU 峰值达到 100%。它持续很短的时间,过一会儿它又来了
我正在使用 scikit-learn 随机森林分类器,我想通过将成功投票所需的树数量从大于 50% 增加到 75% 来降低 FP 率,在阅读文档后我不这样做确定如何做到这一点。有没有人有什么建议。 (
当我连续按下按键事件(字母 k)时,为什么以下按键事件不会减慢 3000 密耳?如果我按住手指,计数会迅速增加,因为 mcount 上没有 setTimeout。这是为什么?每次计数之间应该有延迟,但
我是一名优秀的程序员,十分优秀!