所以,它非常像这样:我有这个有效的手势识别器,下面是GameViewController类中的代码:
Option Explicit
dim cn, cmDB, rs
set cn = CreateObject("ADODB.Connection")
cn.ConnectionString= "DSN=PostgreSQLDsn"
cn.open
cn.CommandTimeout = 28800
Set cmDB = CreateObject("ADODB.Command")
cmDB.CommandTimeout = 28800
set rs = CreateObject("ADODB.recordset")
rs.CursorType = 2
msgbox "disconnected internet here then clicked ok to proceed"
set cn = TestReOpenConnection(cn,"DSN=PostgreSQLDsn",28800,2,100)
if cn is nothing then
msgbox "not good"
WScript.Quit
end if
set rs = cn.execute("select * from test;")
msgbox "all good: " & rs.fields("x")
WScript.Quit
function TestReOpenConnection(cn,sDsn,iConnTimeOut,iWaitSecs,iTimesToTry)
dim iWaitMilSecs
iWaitMilSecs = iWaitSecs * 1000
dim bConnected
bConnected = false
dim iTries
iTries = 0
dim rsTest
set rsTest = CreateObject("ADODB.recordset")
do while bConnected = false
On Error Resume Next
Set rsTest = cn.execute("select 1;")
If Err Then
if iTries <> 0 then
WScript.Sleep iWaitMilSecs 'if we tried once already, then wait
end if
cn.Close
set cn = CreateObject("ADODB.Connection")
cn.ConnectionString= sDsn
On Error Resume Next
cn.open
cn.CommandTimeout = iConnTimeOut
else
bConnected = true
set TestReOpenConnection = cn
End If
iTries = iTries + 1
if iTries > iTimesToTry then
set TestReOpenConnection = nothing
exit do
end if
loop
end function
我正在调用的函数在GameScene类中,它看起来像这样:
INSERT FILE
我在更新功能上也有一个计时器,这样每隔一段时间,就会产生一个球。点击屏幕时,球也必须产生。这是代码:
@IBAction func handleTap(_ sender: UITapGestureRecognizer)
{
GameScene().makeCirc();
}
然而,输出有点奇怪。没有点击,输出是circCount,它通常是一个常数12,这应该是它应该是的。但是,当我点击时,显示的circCount为0,而不是产生球并使circCount 13+,但是,所有对象仍然在屏幕上。
无论如何在没有circCount为0的情况下从另一个类产生球?谢谢!
编辑:这是viewDidMove函数,如果它有帮助:
public func makeCirc() {
circle = SKShapeNode (circleOfRadius: 15)
circle.name = "white circ"
circle.position = CGPoint (x: 0, y: 10)
circle.fillColor = .white
circle.physicsBody = SKPhysicsBody(circleOfRadius: 15)
circle.physicsBody?.isDynamic = true
circle.physicsBody?.affectedByGravity = false
circle.physicsBody?.linearDamping = 0
circle.physicsBody?.restitution = 1.0
circle.physicsBody?.allowsRotation = true
circle.physicsBody?.mass = 300
circle.physicsBody?.density = 2*3.14*15/(circle.physicsBody?.mass)!
circle.physicsBody?.angularDamping = 0.0
self.addChild(circle)
circle.physicsBody?.applyImpulse(CGVector(dx: 0.0, dy:1.0))
print(circCount)
circCount += 1
}
答案 0 :(得分:0)
好吧,所以我在完成下面的工作后完成了所有工作。谢谢你的帮助!
let scene = GKScene (fileNamed: "GameScene")
var instance = GameScene()
override func viewDidLoad() {
super.viewDidLoad()
let sceneNode = scene?.rootNode as! GameScene?
// Load 'GameScene.sks' as a GKScene. This provides gameplay related content
// including entities and graphs.
let tapGesture = UITapGestureRecognizer.init(target: self, action: #selector(handleTap(_:)))
self.view.addGestureRecognizer(tapGesture)
self.view.isUserInteractionEnabled = true
// Get the SKScene from the loaded GKScene
// Set the scale mode to scale to fit the window
sceneNode?.scaleMode = .aspectFill
instance = (sceneNode)!
// Present the scene
if let view = self.view as! SKView? {
view.presentScene(sceneNode)
view.ignoresSiblingOrder = true
view.showsFPS = true
view.showsNodeCount = true
}
}