也许有人可以给我指出正确的方向,在这里,因为我一直在用头撞墙。让我全神贯注于 Sprite Kit 和 UIKit 互操作性的主要问题。
我的游戏从一个表格 View 开始,它将所有玩家的游戏保存在单独的单元格中(与 friend 游戏一样)。当点击一个单元格时,我会加载一个 SKView,它会显示一个 SKScene,其中包含预先从 Parse.com 下载的所有相关游戏数据。
问题是,由于没有更好的术语,我不知道如何让场景“更新”所有当前的游戏数据。正如预期的那样,呈现的场景仅显示背景图像和一些其他图像,但屏幕上应该显示的 Sprite 却没有。相反,它是我最后一次从 SKScene 中滑出时出现在屏幕上的 Sprite 。我可以将所有传入的游戏数据记录到控制台中,所以我知道那里没有问题。此外,当我对场景的 sprite 执行某种操作(删除、刷新等)时,它会导致场景及其所有 sprite 有点“醒来”,并且所有应该在那里的 sprite 都会出现.
第二个可能相关的问题是,当我从 SKScene 滑动回主 TableView 时,不会调用 willMoveFromView:。 (这是我为 Sprite 、背景、按钮等执行所有清理代码的地方)只有当我点击同一个表格 View 单元格并返回到同一个游戏场景时, willMoveFromView: 才会被调用。滑出 SKScene/SKView 时不应该调用它吗?但是,我再次遇到了同样的“更新”问题,即场景有点被旧数据/ Sprite 卡住了。有任何想法吗?我已尝试包含所有相关代码,但我认为您不会发现任何异常之处。我的感觉是这更像是一个概念性问题,我上面的评论就足够了:
@interface MGGameMenuViewController : UIViewController <UITableViewDelegate, UITableViewDataSource, PFLogInViewControllerDelegate, PFSignUpViewControllerDelegate, NSURLConnectionDataDelegate, UIAlertViewDelegate>
@property (nonatomic, retain) UITableView *tView;
@property (nonatomic, readwrite) MGSpriteKitViewController *skvc;
@end
@implementation MGGameMenuViewController
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.section == 0) {
self.matchtoBePassedIn = [self.yourTurnArray objectAtIndex:indexPath.row];
[self launchGamePlaySceneWithMatchData:self.matchtoBePassedIn];
}
else if (indexPath.section == 1) {
self.matchtoBePassedIn.cardsDealt = [NSMutableArray arrayWithCapacity:9];
self.matchtoBePassedIn = [self.theirTurnArray objectAtIndex:indexPath.row];
[self launchGamePlaySceneWithMatchData:self.matchtoBePassedIn];
}
else {
NSLog(@"section chosen was neither 0 nor 1.");
}
}
// launch gameplay
-(void)launchGamePlaySceneWithMatchData:(MGMatch *)match {
if (self.skvc == nil) {
MGSpriteKitViewController *spriteKitVC = [[MGSpriteKitViewController alloc] initWithNibName:@"MGSpriteKitViewController" bundle:nil];
spriteKitVC.matchToBePassedFromGameMenuToGameplayScene = match;
self.skvc = spriteKitVC;
}
if (self.skvc) {
@try {
if (![self.skvc isBeingPresented]) {
self.skvc.matchToBePassedFromGameMenuToGameplayScene = match;
[self.navigationController pushViewController:self.skvc animated:YES];
}
}
@catch (NSException *exception) {
NSRange range = [exception.reason rangeOfString:@"Pushing the same view controller instance more than once is not supported"];
NSRange range2 = [exception.reason rangeOfString:@"Tried to pop to a view controller that doesn't exist"];
if([exception.name isEqualToString:@"NSInvalidArgumentException"] &&
range.location != NSNotFound) {
NSLog(@"[MGGameMenuViewController] NSInvalidArgumentException caught.");
if (![self.skvc isBeingPresented]) {
self.skvc.matchToBePassedFromGameMenuToGameplayScene = match;
[self.navigationController popToViewController:self.skvc animated:YES];
}
}
if ([exception.name isEqualToString:@"NSInternalInconsistencyException"] && range2.location != NSNotFound) {
if (![self.skvc isBeingPresented]) {
self.skvc.matchToBePassedFromGameMenuToGameplayScene = match;
[self.navigationController pushViewController:self.skvc animated:YES];
}
}
}
@finally {
NSLog(@"[MGGameMenuViewController] finally");
}
}
[self.navigationController.navigationBar setHidden:YES];
}
//SKView
SKView *spriteView;
@interface MGSpriteKitViewController : UIViewController
@property (nonatomic, retain) MGMatch *matchToBePassedFromGameMenuToGameplayScene;
@property (nonatomic, retain) MGGameplayScene *gameplayScene;
@end
@implementation MGSpriteKitViewController
@synthesize matchToBePassedFromGameMenuToGameplayScene, gameplayScene;
-(void)viewDidLoad {
[super viewDidLoad];
spriteView = (SKView *)self.view;
spriteView.showsDrawCount = NO;
spriteView.showsFPS = NO;
spriteView.showsNodeCount = YES;
}
-(void)viewWillAppear:(BOOL)animated {
self.gameplayScene = [[MGGameplayScene alloc] initWithSize:CGSizeMake(320.0f, 568.0f)];
self.gameplayScene.passedInMatch = self.matchToBePassedFromGameMenuToGameplayScene;
self.gameplayScene.playerImageCache = self.playerImageCache;
[spriteView presentScene:self.gameplayScene];
}
-(void)viewDidDisappear:(BOOL)animated {
[super viewDidDisappear:YES];
self.gameplayScene = nil;
}
@end
//游戏发生的 SKScene
@interface MGGameplayScene : SKScene
@property (nonatomic) contentCreated;
... various assets
@end
@implementation MGGameplayScene
-(void)didMoveToView:(SKView *)view {
if (self.contentCreated == NO) {
[self createSceneContents];
self.contentCreated = YES;
}
}
-(void)willMoveFromView:(SKView *)view {
[self removeAllChildren];
}
// for practicies
-(void)createSceneContents {
self.backgroundColor = [UIColor whiteColor];
self.scaleMode = SKSceneScaleModeAspectFit;
[self setAllAssetsToNil];
[self recreateAssetsWithRelevantData];
}
@end
最佳答案
在 Storyboard 中将 MGSpriteKitViewController 中的 uiview 的类指定为 skview。
关于ios - UIView > SKView ... willMoveFromView : not being called when expected and sprites not being "updated",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19011759/
我正在尝试测试是否存在表单。我是Rails新手。我的new.html.erb_spec.rb文件的内容是:require'spec_helper'describe"messages/new.html.erb"doit"shouldrendertheform"dorender'/messages/new.html.erb'reponse.shouldhave_form_putting_to(@message)with_submit_buttonendendView本身,new.html.erb,有代码:当我运行rspec时,它失败了:1)messages/new.html.erbshou
我在从html页面生成PDF时遇到问题。我正在使用PDFkit。在安装它的过程中,我注意到我需要wkhtmltopdf。所以我也安装了它。我做了PDFkit的文档所说的一切......现在我在尝试加载PDF时遇到了这个错误。这里是错误:commandfailed:"/usr/local/bin/wkhtmltopdf""--margin-right""0.75in""--page-size""Letter""--margin-top""0.75in""--margin-bottom""0.75in""--encoding""UTF-8""--margin-left""0.75in""-
给定这段代码defcreate@upgrades=User.update_all(["role=?","upgraded"],:id=>params[:upgrade])redirect_toadmin_upgrades_path,:notice=>"Successfullyupgradeduser."end我如何在该操作中实际验证它们是否已保存或未重定向到适当的页面和消息? 最佳答案 在Rails3中,update_all不返回任何有意义的信息,除了已更新的记录数(这可能取决于您的DBMS是否返回该信息)。http://ar.ru
为了将Cucumber用于命令行脚本,我按照提供的说明安装了arubagem。它在我的Gemfile中,我可以验证是否安装了正确的版本并且我已经包含了require'aruba/cucumber'在'features/env.rb'中为了确保它能正常工作,我写了以下场景:@announceScenario:Testingcucumber/arubaGivenablankslateThentheoutputfrom"ls-la"shouldcontain"drw"假设事情应该失败。它确实失败了,但失败的原因是错误的:@announceScenario:Testingcucumber/ar
我有一个具有一些属性的模型:attr1、attr2和attr3。我需要在不执行回调和验证的情况下更新此属性。我找到了update_column方法,但我想同时更新三个属性。我需要这样的东西:update_columns({attr1:val1,attr2:val2,attr3:val3})代替update_column(attr1,val1)update_column(attr2,val2)update_column(attr3,val3) 最佳答案 您可以使用update_columns(attr1:val1,attr2:val2
我遵循MichaelHartl的“RubyonRails教程:学习Web开发”,并创建了检查用户名和电子邮件长度有效性的测试(名称最多50个字符,电子邮件最多255个字符)。test/helpers/application_helper_test.rb的内容是:require'test_helper'classApplicationHelperTest在运行bundleexecraketest时,所有测试都通过了,但我看到以下消息在最后被标记为错误:ERROR["test_full_title_helper",ApplicationHelperTest,1.820016791]test
我正在尝试从Postgresql表(table1)中获取数据,该表由另一个相关表(property)的字段(table2)过滤。在纯SQL中,我会这样编写查询:SELECT*FROMtable1JOINtable2USING(table2_id)WHEREtable2.propertyLIKE'query%'这工作正常:scope:my_scope,->(query){includes(:table2).where("table2.property":query)}但我真正需要的是使用LIKE运算符进行过滤,而不是严格相等。然而,这是行不通的:scope:my_scope,->(que
我正在尝试编写一个将文件上传到AWS并公开该文件的Ruby脚本。我做了以下事情:s3=Aws::S3::Resource.new(credentials:Aws::Credentials.new(KEY,SECRET),region:'us-west-2')obj=s3.bucket('stg-db').object('key')obj.upload_file(filename)这似乎工作正常,除了该文件不是公开可用的,而且我无法获得它的公共(public)URL。但是当我登录到S3时,我可以正常查看我的文件。为了使其公开可用,我将最后一行更改为obj.upload_file(file
这里有一个很好的答案解释了如何在Ruby中下载文件而不将其加载到内存中:https://stackoverflow.com/a/29743394/4852737require'open-uri'download=open('http://example.com/image.png')IO.copy_stream(download,'~/image.png')我如何验证下载文件的IO.copy_stream调用是否真的成功——这意味着下载的文件与我打算下载的文件完全相同,而不是下载一半的损坏文件?documentation说IO.copy_stream返回它复制的字节数,但是当我还没有下
当我尝试安装Ruby时遇到此错误。我试过查看this和this但无济于事➜~brewinstallrubyWarning:YouareusingOSX10.12.Wedonotprovidesupportforthispre-releaseversion.Youmayencounterbuildfailuresorotherbreakages.Pleasecreatepull-requestsinsteadoffilingissues.==>Installingdependenciesforruby:readline,libyaml,makedepend==>Installingrub