gpt4 book ai didi

ios - 使用未声明的类型 'NSEvent'

转载 作者:可可西里 更新时间:2023-11-01 01:42:22 27 4
gpt4 key购买 nike

我正在尝试创建鼠标按下事件,但在“override func mouseDown( theEvent: NSEvent!) { ”行中不断收到错误“使用未声明的类型‘NSEvent’”。在研究和尝试不同的东西之后,我仍然一无所获。以前有人遇到过这个问题吗?

import UIKit
import SpriteKit


let BallCategoryName = "ball"
let MainBallCategoryName = "mainBall"

class GameScene: SKScene {
override func didMoveToView(view: SKView) {
super.didMoveToView(view)

// 1. Create a physics body that borders the screen
let borderBody = SKPhysicsBody(edgeLoopFromRect: self.frame)
// 2. Set the friction of that physicsBody to 0
borderBody.friction = 0
// 3. Set physicsBody of scene to borderBody
self.physicsBody = borderBody

physicsWorld.gravity = CGVectorMake(0, 0)

let ball = childNodeWithName(BallCategoryName) as SKSpriteNode
var mainBall = childNodeWithName(MainBallCategoryName) as SKSpriteNode

ball.physicsBody!.applyImpulse(CGVectorMake(10, -10))

ball.physicsBody!.allowsRotation = false
ball.physicsBody!.friction = 0
ball.physicsBody!.restitution = 1
ball.physicsBody!.linearDamping = 0
ball.physicsBody!.angularDamping = 0

}

override func mouseDown( theEvent: NSEvent!) {
let action = SKAction.moveTo(
CGPoint(x:theEvent.locationInWindow.x,y:theEvent.locationInWindow.y),
duration:2
);
MainBallCategoryName.runAction(action)

}
}

最佳答案

iOS 设备没有鼠标,iOS 也没有 NSEvent 类。它有一个 UIEvent 类,但在 iOS 上名为 mouseDown 的函数并没有什么特别之处。 iOS 事件报告触摸,而不是鼠标按钮。

如果您从教程中复制此代码,则该教程适用于 OS X,而非 iOS。您应该找到 iOS 教程。

关于ios - 使用未声明的类型 'NSEvent',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28518546/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com