- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在 Objective C Sprite Kit 框架中开发的游戏的滚动背景 (WAVE) 有问题。我正在使用“iOS 游戏教程”一书中的方法(强烈推荐 - 非常有用的书)作为指南,因为我是新手。
我一切正常,但在我关闭游戏后......我的 iPhone 已经坐了大约 20-30 分钟 - 我回到游戏时滚动 BG 空白了 5-15 秒然后它加载和滚动。奇怪的是,当我第一次测试游戏时 - 它立即加载没有问题。我也有节点/图形,它们每次都能快速加载,没有任何问题。
这是每帧更新的主要代码片段:
- (void)moveWave
{
CGPoint waveVelocity = CGPointMake(-wave_speed, 0);
CGPoint amtToMove = CGPointMultiplyScalar(waveVelocity, _dt);
_waveLayer.position = CGPointAdd(_waveLayer.position, amtToMove);
[_waveLayer enumerateChildNodesWithName:@"wave"
usingBlock:^(SKNode *node, BOOL *stop){
SKSpriteNode * wave = (SKSpriteNode *) node;
CGPoint waveScreenPos = [_waveLayer convertPoint:wave.position
toNode:self];
if (waveScreenPos.x <= -wave.size.width) {
wave.position = CGPointMake(wave.position.x+wave.size.width*2,
wave.position.y);
}
}];
}
关于为什么回到 iPhone 闲置 20 分钟然后重新加载游戏的任何帮助或见解,只有滚动 BG 丢失但在 5-15 秒后,它开始并且看起来很好。同样,当我第一次加载它时......或退出 5 分钟然后返回游戏......一切正常并立即加载。
编辑 - 我知道这是滚动功能/方法,因为我尝试过不滚动就加载 BG 图像,即使在我退出游戏 20 多分钟后再回来时它也能正常加载。嗯嗯..即使没有加载滚动BG,我也可以玩游戏。滚动 BG 总是最终加载 - 通常是 5-10 秒后。
最佳答案
将以下代码添加到 1) 当用户按下主页按钮时暂停游戏和 2) 当用户点击应用程序图标时恢复游戏。
// Register to be notified when the app is about to change to background state
UIApplication *app = [UIApplication sharedApplication];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(applicationWillResignActive:)
name:UIApplicationWillResignActiveNotification
object:app];
此方法在应用进入后台模式之前调用。
- (void) applicationWillResignActive:(NSNotification *)notification
{
// Pause the game
self.scene.view.paused = YES;
UIApplication *app = [UIApplication sharedApplication];
// Register to be notified when app is about to become the foreground app
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(applicationWillEnterForegroundOrDidBecomeActive:)
name:UIApplicationWillEnterForegroundNotification
object:app];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:UIApplicationWillResignActiveNotification
object:app];
}
此方法在应用进入前台模式之前调用。
- (void) applicationWillEnterForegroundOrDidBecomeActive:(NSNotification *)notification
{
UIApplication *app = [UIApplication sharedApplication];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:UIApplicationWillEnterForegroundNotification
object:app];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(applicationWillResignActive:)
name:UIApplicationWillResignActiveNotification
object:app];
// Add tap recognizer
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc]
initWithTarget:self action:@selector(handleTapGesture:)];
tapGesture.delegate = (id)self;
[self.view addGestureRecognizer:tapGesture];
}
此方法会在用户点击屏幕时恢复游戏。
- (void) handleTapGesture:(UITapGestureRecognizer *)gesture
{
// Remove the tap recognizer
[self.view removeGestureRecognizer:gesture];
// Resume the game
self.scene.view.paused = NO;
}
关于ios - 暂停返回后滚动 BG 丢失(iOS-SpriteKit-iphone),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25212790/
如果这个在过去有效,但突然就不行了。下面是结构:Thre 也有一个设置和控制,背景颜色和图像设置都单独工作,但是当我有两个设置时它不会工作,最初我让它工作,颜色总是工作,除非选择背景图像,那会覆盖它,
我有一个网站,它通过加入 body 标签的 bg 和 div 标签的 bgs 来完成布局。但是,根据您使用的浏览器和操作系统,由于滚动条,它们似乎无法准确匹配。 (我已经通过添加 overflow:h
我正在尝试根据用户将鼠标悬停在求职者按钮还是招聘人员按钮上来更改背景图片。 我尝试了以下代码(在 JS Fiddle 中有效)但失败了。我插入了一个 background-color 命令(参见注释行
所以我有一个包含几行内容的部分。线条覆盖了窗口宽度的 100%,但是内容仅显示在部分的右侧。左边必须有一个图像。我试着用 bg-image 和 z-index 来做,但问题是它被埋在线条的 bg-co
与 Bootstrap 的 bg-danger 类关联的背景颜色未应用于类 form-control 的输入文本框。如何做到这一点? 最佳答案 form-co
我在有序列表中显示代码,以便它显示行号。每个 li 都有一个 pre 标签,其中填充了一行代码。 我的问题是,当我设置 ol 的宽度并允许溢出滚动时,溢出的背景颜色与最初显示区域的背景颜色不同。 ol
例如,在一列中我有 3 个 block (div),在第二列中我有其他 block 的列表 (div)。 第一列 block 代表蛋糕层,第二列 block 代表可以应用于任何蛋糕层的口味。 因此,通
我正在处理日期和时间的本地化代码,当文化设置为保加利亚语并且我传入的日期是 11 月时,我看到了一个奇怪的行为。 本质上,我正在尝试调用: if (DateTime.TryParse(theDateT
在下图中,viewController 背景为白色,pageViewController 背景颜色可见。如何清除或透明 viewController 背景,以便紫罗兰色成为所有 viewControl
阅读 pygame 教程 here ,你会发现这个例子:(箭头是我的) for o in objects: screen.blit(background, o.pos, o.pos) # Re
我制作了一个播放背景音乐的服务,但是当音乐结束时我想再次重播它。我可以在我的服务中使用哪种方法? public class BackgroundSoundService extends Service
我正在设计一个由大量元素组成的常规 android LinearLayout,我将布局参数都设置为 wrap_content 并使其环绕 bg 或 elements 根据哪个更大,那么,如何分配布局,
我有一个像 BasicCell>ContentView>Container 这样的 UITableView 单元设置。当我在界面生成器中设置容器的背景时,我得到了我设置的所需的深灰色阴影。但是,当我以
我正在尝试制作我的横幅图片,目前它的全宽约为 1500 像素,我已将其设置为背景图片,这样我就可以在顶部使用一些元素,我知道你可以制作一个全宽的图片标签,但我不确定您是否可以对背景图片标签执行相同的操
我这里有这样的背景 background:url(../img/arrow_lch.png) right no-repeat #2e443a; 我只需要降低 bg color(#2e443a) 不透明
我的网站有一个看起来很酷的背景,但可能会影响可用性(如果你看得太久它会烧毁)所以我想要一个链接,可以用 javascript 更改/删除背景图像。我用谷歌搜索过,但找不到有用的东西。 有没有办法建立一
我想将视差滚动效果添加到我主页的 .intro-body 中,就像我将此效果添加到我的“关于”中的超大屏幕图像中一样、“简历”和“作品集”页面。然而,出于某种原因,当我将它应用于 .bg 类时,背景图
我得到了一个名为remove.bg 的API。我想在Flutter应用中使用此API(以python语言提供)。可能吗 此API用于删除图像背景。 为了使此功能正常工作,我需要执行哪些步骤/研究? 进
每当我将鼠标悬停在某个元素上时,我都会尝试更改页面背景。目前我已经将不同的图像上传到我的网络服务器中,当我将鼠标悬停在 div 上时,我想将页面背景从其中一个图像更改为另一张图像。我该怎么做呢?无论是
我这里有一段非常基本的 R 代码,以及它生成的图。为什么圆点没有填成红色? plot(1, 1, col="blue", bg="red", cex=4) 最佳答案 您需要使用 pch = 21 到
我是一名优秀的程序员,十分优秀!