SwiftKitでSwiftを使って単純なゲームを作成しました。最後のシーンでは、スコア、共有、再開のボタンが表示されます。SpriteKitでSwiftを使ってスクリーンショットを撮る/共有する
終了シーンのスクリーンショットを共有する機能はまだ保留中です。私はここで非常に単純な解決策を見つけました。https://www.frispgames.com/sharing-a-screenshot-on-ios-using-swift-and-sprite-kit/
私はプロではありません。したがって、このソリューションを実装するためのこれまでのすべての試みは無駄です。
プレイヤーがshareButton()
をタップしても機能していないと、私はそのソリューションで書かれているように、shareScore()
関数を呼び出しようとしています。
は、ここであなたは、あなたが与えられたので、私はチュートリアルからあなたのための簡単な一例を作成しましたshareScore()
機能を使用している方法を示していなかったEndScene
var restartBtn = SKSpriteNode()
var shareBtn = SKSpriteNode()
var scoreLbl = SKLabelNode()
var score = Int()
override func didMoveToView(view: SKView) {
scene!.scaleMode = .AspectFill
self.view?.backgroundColor = UIColor.grayColor()
scoreLabel()
shareBtn = SKSpriteNode(imageNamed: "Share")
shareBtn.position = CGPointMake(self.frame.width/2, self.frame.height/3)
shareBtn.setScale(0.0005)
self.addChild(shareBtn)
restartBtn = SKSpriteNode(imageNamed: "Restart")
restartBtn.position = CGPointMake(self.frame.width/2, self.frame.height/4)
restartBtn.setScale(0.0005)
self.addChild(restartBtn)
}
func scoreLabel() {
let scoreDefault = NSUserDefaults.standardUserDefaults()
score = scoreDefault.valueForKey("score") as! NSInteger
scoreLbl.position = CGPoint(x: self.frame.width/2, y: self.frame.height/2)
scoreLbl.fontSize = 40
scoreLbl.setScale(0.001)
scoreLbl.text = "Score: \(score)"
self.addChild(scoreLbl)
}
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
for touch in touches {
let location = touch.locationInNode(self)
if restartBtn.containsPoint(location) {
let gameScene = GameScene(fileNamed: "GameScene")
let transition = SKTransition.fadeWithDuration(0.5)
let skView = self.view! as SKView
skView.ignoresSiblingOrder = true
gameScene?.scaleMode = .AspectFill
skView.presentScene(gameScene!, transition: transition)
} else if shareBtn.containsPoint(location) {
// Function for sharing screenshot should be called here
}
}
}
あなたのコードを表示してください.. –
@DharmeshKheni私は自分のコードも含めました – Haadi