标签: gamekit

为什么我不能在iOS9中设置GKAgent2D的速度?

如果我尝试在iOS9中更改GKAgent2D(或其父类GKAgent)的speed参数值,我会收到此无法识别的选择器错误:

***由于未捕获的异常'NSInvalidArgumentException'终止应用程序,原因:' - [GKAgent2D setSpeed:]:发送到实例的无法识别的选择器

但是在iOS10中,不会发生此错误,并且正确更改代理的速度.

我可以在一个非常简单的示例中重现错误(单视图iOS应用程序,将视图控制器代码更改为以下内容,请注意GKAgent2D或GKAgent发生错误):

import UIKit
import GameplayKit

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        var agent = GKAgent()
        agent.speed = 10

        print(agent.speed)
    }

}
Run Code Online (Sandbox Code Playgroud)

上面总是在线路上发生这种无法识别的选择器错误而崩溃,该线路在运行iOS9.3的模拟器上设置代理的速度,而不是iOS10.3(所有这些都在Xcode 8.3.2下).

GKAgent的速度属性记录为在iOS9下读写并受支持 - 请参阅Apple的GKAgent文档,speed属性.

我在GKAgentDelegate遇到了类似的问题,只有使用无法识别的agentWillUpdate选择器才能在iOS9上崩溃.我通过在我的代码中放入一个虚拟方法来解决这个问题:

func agentWillUpdate(_ agent: GKAgent) {
}
Run Code Online (Sandbox Code Playgroud)

我已经尝试了类似的解决方案,以新的错误,在我的GKAgent2D子类中重写速度性能,并提供一个明确的setter和getter,甚至支持由私人浮法速度参数通过Kdawg的建议,但同样的错误仍然出现当超级速度参数设置时:

class Agent:GKAgent2D {
    override var speed:Float {
        get {return localSpeed}
        set {localSpeed = newValue}
    }
    private var localSpeed:Float {
        get {return super.speed}
        set {super.speed = newValue}
    }
}
Run Code Online (Sandbox Code Playgroud)

有什么想法吗?

具体来说:iOS9中关于选择器的GKAgent是否存在任何已知问题?

或者,对替代工作的任何想法?

如果可以,我想支持iOS9.它看起来像是GameplayKit中的一个错误 - 但我希望Apple对报告的回应是它在iOS10中得到修复.

gamekit ios

9
推荐指数
1
解决办法
197
查看次数

在iPhone 3.0中,Gamekit服务器可以支持多少个客户端

iPhone SDK 3.0中的GameKit使用服务器 - 客户端模型在两个iPhone之间创建点对点蓝牙连接.在蓝牙规范中,最多可以将7个客户端连接到服务器.但是在GameKit文档中,没有任何关于这个问题的文字.这是否意味着GameKit服务器可以连接7个以上的客户端?如果是,这是否意味着一些客户处于睡眠模式?

谢谢!

bluetooth gamekit

8
推荐指数
1
解决办法
2026
查看次数

在游戏套件中协商2场比赛时遇到麻烦

我得到了一些我无法从GameKit解码的行为.

有时,完成邀请的玩家会陷入"等待......"循环,并且无法根据他的邀请结束交易.

我相信它与多任务处理和邀请处理程序有关......似乎如果被邀请者的应用程序从头开始,那么可以正确接受邀请.但这种机制对我来说并不那么透明.

有什么可能缺失的线索?我被文档蒙蔽了眼睛.

iphone cocoa-touch gamekit ios

8
推荐指数
1
解决办法
405
查看次数

邀请游戏中心的朋友以编程方式进行匹配

GameKit是否允许您以编程方式邀请特定的游戏中心朋友参加比赛,即无需呈现GC ViewController?以下handleInviteFromGameCenter文档似乎暗示您可以填充GKMatchRequest.playersToInvite并将其与[GKTurnBasedMatch findMatchForRequest]一起使用:

当您的委托收到此消息时,您的应用程序应创建一个新的GKMatchRequest对象,并将playersToInvite参数分配给匹配请求的playersToInvite属性.然后,您的应用程序可以调用GKTurnBasedMatch类方法findMatchForRequest:withCompletionHandler:以编程方式查找匹配项,也可以使用该请求实例化新的GKTurnBasedMatchmakerViewController以显示该播放器的用户界面.

但是我发现当findMatchForRequest用填充的匹配调用我的完成块时,传递给它的GameCenter ID不会被设置为第二个玩家.相反,它是空的,状态是"匹配".因此,当我调用endTurnWithNextParticipant时,它会成功,但我的第二台设备上没有收到邀请.这说明了我在做什么:

GKMatchRequest *request = [[[GKMatchRequest alloc] init] autorelease]; 
request.minPlayers = 2;
request.maxPlayers = 2;
request.playersToInvite = [NSArray arrayWithObjects: otherPlayerGCID,nil ];

[GKTurnBasedMatch findMatchForRequest:request 
                  withCompletionHandler:^(GKTurnBasedMatch *match, NSError *error) 
{
    if (error) 
        NSLog(@"returned from fimdmatch but with error");
    else if (match != nil) {
        NSLog(@"match returned success and match populated");
        NSArray* otherPlayers = [match participants];
        if (otherPlayers.count>1) {
           NSData* placeholder = [@"no data" dataUsingEncoding:NSUTF8StringEncoding];
           [match endTurnWithNextParticipant:[otherPlayers objectAtIndex:1] 
                  matchData:placeholder 
                  completionHandler:^(NSError *error) 
           {
              if (error) 
                 NSLog(@"returned from END …
Run Code Online (Sandbox Code Playgroud)

gamekit game-center

8
推荐指数
1
解决办法
4635
查看次数

Game Center不响应authenticateWithCompletionHandler请求(iOS)

这是我的情况:

1)用户第一次打开我的应用程序.我立即调用authenticateLocalUser尝试将它们登录到Game Center.已成功显示带有"登录","创建帐户"和"取消"按钮的弹出窗口.

2)用户现在不想登录,因此他们单击"取消".(这不是他们第三次点击'取消',我没有收到'禁用游戏中心,从游戏中心应用程序登录以启用'消息.)用户可以继续正常使用我的应用程序.

3)用户以后想要使用Game Center,所以他们点击我给他们的按钮登录游戏中心.我再次调用authenticateLocalUser.这次,弹出窗口不会出现.实际上没有任何反应,除了我收到这些控制台日志消息:

2012-04-26 08:38:42.861 Clink[332:707] authenticateWithCompletionHandler: enter
2012-04-26 08:38:42.863 Clink[332:707] authenticateWithCompletionHandler: exit
Run Code Online (Sandbox Code Playgroud)

4)我已经测试过两次立即按下再次调用authenticateLocalUser的按钮,并且在这之前等待很长一段时间.无论什么时候我再次调用authenticateLocalUser,再一次没有出现,我从函数中得到这个错误:

Error Domain=GKErrorDomain Code=7 "The requested operation could not be completed because local player is already authenticating."
Run Code Online (Sandbox Code Playgroud)

所以似乎正在发生的事情是,当我在步骤3中调用authenticateLocalUser时,我要求Game Center进行身份验证,但它已挂起并且没有响应我的请求.然后在第4步,当我再次尝试时,它告诉我它无法处理我的请求,因为它已经在尝试进行身份验证.但是我已经等了10分钟才得到第3步中我的请求的响应,而且我从来没有从游戏中心获得一个.

这是我的authenticateLocalUser函数的内容.据我所知,我没有从我从Apple的示例代码下载的版本中更改它.

- (void) authenticateLocalUser
{
    if([GKLocalPlayer localPlayer].authenticated == NO)
    {
        [[GKLocalPlayer localPlayer] authenticateWithCompletionHandler:^(NSError *error) 
        {
             [self callDelegateOnMainThread: @selector(processGameCenterAuth:) withArg: NULL error: error];
        }];
    }
}
Run Code Online (Sandbox Code Playgroud)

有没有其他人遇到过这个问题或对可能发生的事情有任何想法?我已经看了一段时间,我不确定发生了什么.

提前致谢!!

objective-c gamekit ios game-center

8
推荐指数
1
解决办法
3607
查看次数

iPhone - 通过蓝牙发送图像和文本的错误

我的GameKit框架有问题.在我的应用程序中,我想发送文本或图像.现在,当我发送图像时UIImagePicker,它运行良好.当我发送文本时,UIAlertView对于没有图像的图像,它不会显示相同的内容.这是.h:

    #import <UIKit/UIKit.h>
#import <GameKit/GameKit.h>

@interface ViewController : UIViewController <GKPeerPickerControllerDelegate, GKSessionDelegate, UIActionSheetDelegate, UINavigationControllerDelegate, UIImagePickerControllerDelegate> {
    GKSession *currentSession;
    IBOutlet UITextField *txtMessage;
    IBOutlet UIButton *connect;
    IBOutlet UIButton *disconnect;
    GKPeerPickerController *picker;
    UIImagePickerController *imgPicker;
    BOOL isText;
    UIImage *_image;
}
@property (nonatomic, retain) GKSession *currentSession;
@property (nonatomic, retain) UITextField *txtMessage;
@property (nonatomic, retain) UIButton *connect;
@property (nonatomic, retain) UIButton *disconnect;
-(IBAction) btnSend:(id) sender;
-(IBAction) btnConnect:(id) sender;
-(IBAction) btnDisconnect:(id) sender;
-(IBAction)chooseImageData:(id)sender;
@end
Run Code Online (Sandbox Code Playgroud)

而且.m:

#import "ViewController.h"
#import …
Run Code Online (Sandbox Code Playgroud)

iphone image bluetooth gamekit ios

8
推荐指数
1
解决办法
586
查看次数

在iPhone之间传输数据的最佳选择

我想设置一个客户端 - 服务器架构,用于在多个iPhone之间传输数据.例如,'服务器'iPhone拥有动物的主列表.任意数量的客户端iPhone可以连接到服务器iPhone,然后读取和编辑列表.我试过的一些方法:

  • 多路连接 - 仅支持最多8个客户端.如果有办法解决这个问题,那正是我正在寻找的
  • GameKit - 我已经读过,当处理多个客户端时,蓝牙连接可能会出错
  • BLE - 蓝牙的特征值限制为512个八位字节.我假设动物列表在存档时可能会增长到大于最大特征值.
  • 套接字 - 我宁愿不必依赖外部服务器

我愿意接受'hacky'解决方案.我想把每只动物作为一个独立的特征进行广播,但这可能会减慢发现速度,我觉得它会引起一些其他的麻烦.任何帮助将不胜感激

iphone bluetooth gamekit ios multipeer-connectivity

8
推荐指数
1
解决办法
3566
查看次数

在特定场景中构建SpriteKit/GameKit排行榜

我对Swift很陌生,而且我在游戏中实现排行榜时遇到了一些麻烦.我刚看了一个教程:'游戏中心排行榜!(Xcode中的Swift 2)'其中GameCenter信息都通过应用程序的一个视图.在我的游戏中,我希望用户能够玩游戏,然后只有当他们处于特定SKScene意愿时他们才能访问GameCenter.

因此,例如,在GameOverScene意志上他们将被用户认证,并且还能够上传他们的高分.我想我也错过了GameViewController(所有教程逻辑所在的位置)和我制作的众多场景之间的一些差异.

这是我的代码,我尝试使用GKGameCenterControllerDelegateon GameOverScene和创建各种函数来访问GameCenter.当用户在视图中点击某个标签时进行调用:(这显然不起作用,因为我试图访问这样的行上的场景:self.presentViewController(view!, animated:true, completion: nil)


class GameOverScene: SKScene, GKGameCenterControllerDelegate  {

    init(size: CGSize, theScore:Int) {
        score = theScore
        super.init(size: size)
    }
    ...

    override func didMoveToView(view: SKView) {

        authPlayer()

        leaderboardLabel.text = "Tap for Leaderboard"
        leaderboardLabel.fontSize = 12
        leaderboardLabel.fontColor = SKColor.redColor()
        leaderboardLabel.position = CGPoint(x: size.width*0.85, y: size.height*0.1)
        addChild(leaderboardLabel)

        ...

    override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {

        for touch : AnyObject in touches {
            let location = touch.locationInNode(self)

            if(CGRectContainsPoint(leaderBoardLabel.frame, location)){ …
Run Code Online (Sandbox Code Playgroud)

gamekit sprite-kit game-center-leaderboard swift

8
推荐指数
2
解决办法
1537
查看次数

ios - Gamekit 的 GKOctree 找不到元素

我正在尝试使用GKOctree在 3D 空间中有效检索对象。但是,以下代码似乎没有按预期工作:

import GameplayKit

let tree = GKOctree(boundingBox: GKBox(
  boxMin: vector_float3(x: -10, y: -10, z: -10),
  boxMax: vector_float3(x: 10, y: 10, z: 10)
), minimumCellSize: 0.1)

tree.add(NSObject(), at: vector_float3(x: 0, y: 0, z: 0))
tree.elements(at: vector_float3(x: 0, y: 0, z: 0)).count // 1, fine

tree.elements(in: GKBox(
  boxMin: vector_float3(x: -1, y: -1, z: -1),
  boxMax: vector_float3(x: 1, y: 1, z: 1)
)).count // 0, ??

tree.elements(in: GKBox(
  boxMin: vector_float3(x: 1, y: 1, z: 1),
  boxMax: vector_float3(x: -1, y: …
Run Code Online (Sandbox Code Playgroud)

gamekit ios octree swift

8
推荐指数
1
解决办法
189
查看次数

inviteHandler从未打过电话

我正在使用Game Kit将两个玩家添加到游戏中.我的测试设备是运行4.3.5的第三代iPod touch和运行4.2.1的第二代iPod touch.两个设备上都启用了游戏中心通知.我没有使用iPhone模拟器.这两个设备都使用单独的帐户登录到Game Center Sandbox.帐户已经是朋友了.

我可以成功验证localPlayer并启动邀请,但受邀请的设备永远不会收到邀请,并且inviteHandler永远不会调用受邀请的游戏.在inviteHandler被认证后立即设置localPlayer.我已经浏览了游戏套件编程指南并实现了GKMatchmakerViewControllerDelegate协议中的所有方法,但我很难过.

gamekit ios

7
推荐指数
1
解决办法
1019
查看次数