- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在我的 GameViewController 中,我有按钮标签和所有设置。在 viewDidLoad() 下,我已将标签和所有内容设置为 .hidden = true
并且我的 gameOver 内容位于我的 GameScene 文件中,我无法将按钮标签设置为 .hidden = true
>。该按钮称为 backToMenu,如果我在 GameViewController 中的任何位置输入它,它会识别它,但是当我尝试在 GameScene 中输入 backToMenu.hidden = false
时,它会给我一个错误。有什么方法可以让我在 GameScene 中访问它们吗?
GameScene Code:
func gameOver() {
bigBox.hidden = false
backToMenu.hidden = false
scoreLabel.hidden = false
var alrentSound = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("MenuSelect", ofType: "mp3")!)
AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback, error: nil)
AVAudioSession.sharedInstance().setActive(true, error: nil)
var error: NSError?
screenTapped = AVAudioPlayer(contentsOfURL: alrentSound, error: &error)
screenTapped.prepareToPlay()
screenTapped.stop()
square1.removeFromParent()
wallGen.stopWalls()
//diamondGen.stopDiamonds()
movingGround.stop()
square1.stop()
//square2.stop()
// save current points label value
let pointsLabel = childNodeWithName("pointsLabel") as! PPPointsLabel
let highscoreLabel = childNodeWithName("highscoreLabel") as! PPPointsLabel
if highscoreLabel.number < pointsLabel.number {
highscoreLabel.setTo(pointsLabel.number)
let defaults = NSUserDefaults.standardUserDefaults()
defaults.setInteger(highscoreLabel.number, forKey: "highscore")
}
}
GameVieController Code:
@IBOutlet weak var bigBox: UIImageView!
@IBOutlet weak var backToMenu: UIButton!
@IBOutlet weak var scoreLabel: UILabel!
@IBAction func backToMenuButton(sender: AnyObject) {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewControllerWithIdentifier("MainMenuViewController") as! UIViewController
self.dismissViewControllerAnimated(true, completion: nil)
var alrentSound = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("MenuSelect", ofType: "mp3")!)
AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback, error: nil)
AVAudioSession.sharedInstance().setActive(true, error: nil)
var error: NSError?
screenTapped = AVAudioPlayer(contentsOfURL: alrentSound, error: &error)
screenTapped.prepareToPlay()
screenTapped.play()
}
override func viewDidLoad() {
super.viewDidLoad()
bigBox.hidden = true
backToMenu.hidden = true
scoreLabel.hidden = true
// Configure the view
let skView = view as! SKView
// store a ref
// gameScene.gameDelegate = self
// Create and configure the scene
gameScene = GameScene(size: skView.bounds.size)
gameScene?.scaleMode = .AspectFill
// Present the scene
skView.presentScene(gameScene)
}
最佳答案
这是因为变量位于不同的类中。一种方法是声明变量类变量,如下所示
class var myVariable = // whatever
如果你想清理你的代码,你也可以有静态 getter,就像这样
static func getMyVariable() -> MyVariableType
{
return myVariable
}
这样,变量就可以从任何地方访问,并且可以通过键入来访问它们
GameViewController.getMyVariable()
或
GameViewController.myVariable
关于ios - 从 GameViewController 到 GameScene 访问按钮、标签和 uiimageview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32251489/
我创建了分享按钮,用于在 Facebook 、推特等平台上分享我的分数。在 GameViewController 中创建的按钮以及我在游戏场景中创建的分数和高分。 我确实分享了分数,但我不知道如何将我
运行在spriteKit下的App。几天前,一旦 gameViewController 被加载,gameScene 就会被加载。今天我把它的加载 Action 改成只有在点击开始按钮时才加载gameS
想在游戏开始前预加载 textureAtlases,所以我决定将场景启动代码放入完成处理程序中,但由于某些原因应用程序崩溃了。这是我的代码: import UIKit import SpriteKit
我已将横幅 View 集成到应用程序内的场景中,但无法将插页式广告集成到另一个场景中。这是我的代码:导入 SpriteKit导入游戏包导入 GoogleMobileAds class GameOve
我创建了一个 HomeScene.sks 和一个 HomeScene.swift。在 GameViewController 中,我已将默认的“GameScene”更改为“HomeScene”,如下所示
一旦我的游戏完成,我将在我的 GameViewController 中运行 self.performSegueWithIdentifier("goToGameOver", sender: nil),它
我有两个场景,GameScene 和 PlayScene。我可以展示我的 GameScene,但我无法展示 PlayScene,我使用的是相同的代码和正确的文件名。我正在使用 UIButton 来调用
我正在使用 SpriteKit 框架在 Swift 中开发一款游戏。在此应用程序中,我有 GameScene.sks,其中显示了我的 UI。在该 .sks 文件中,底部菜单有一个 SKReferenc
下面复制相关代码,我也在Github上放了一个简单的测试项目来演示这种情况: https://github.com/prinomen/viewPresentSceneTest 我有一个 GameVie
我成功测试了应用内购买后广告的移除。我只需要在他们完成付款并完成交易后,当前 GameScene 上的横幅广告仍然存在。为了删除它们,我必须重新启动该应用程序。我的 GameViewControlle
所以我在我的 swift 项目中创建了几个不同的 SKScenes 并且我在几个教程中看到你不必将 gameScene.swift 作为你的第一个场景启动,但是我找不到一个教程解释如何 import
我一直在使用 SpriteKit 和 Swift 开发游戏,但我似乎无法确定 GameViewController 和我的任何一个 SKScene 之间的真正区别秒。我试图理解这些差异,因为我想在我的
当我尝试在 Swift 中为我的游戏添加不同的场景时,我遇到了 unarchiveFromFile 方法。这种方法的问题在于它只适用于 GameScene 类。如果你从 extension SKNod
我在 GameViewController 类中创建了一个 UIScrollView,其中 subview 是场景。当用户进入特定场景并按下特定按钮时,ScrollView 必须停止滚动。 我怎样才能
我在 GameViewController 中制作了游戏菜单。然后,当按下 Go 按钮时,我尝试移动到 GameScene。我使用默认代码来呈现 GameScene 文件。 if let scene
我想在 SceneKit 应用程序中使用 Core Data,但是在创建项目时,选择"file"、“新建”-> 后没有选项可以选中“使用核心数据” 项目->游戏;如果我在创建项目后尝试将 Core D
我已将 admob 奖励视频添加到我的应用中。 admob 一切正常。但是,我无法在观看奖励视频后更新直播标签。如果我去另一个场景然后回来,它会更新并显示新值。 //GameViewControlle
在 GameViewController 中,我想从我的一个 SKScenes 访问方法。它的类称为 PlayScene。 我一直在努力解决这个问题,但还没有成功。我正在尝试像 let gameSce
这是我的相关代码: 来 self 的 GameScene 类: func resetCircleAndScore(scale: CGFloat) { circleIsStationar
我在 Storyboard中创建了一个按钮,它位于我的游戏屏幕上。它在 GameViewController() 中有一个 IB Action ,如下所示: @IBAction func but
我是一名优秀的程序员,十分优秀!