微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Swift Playgrounds Brick Breaker,通过鼠标移动 -> 如何通过键盘移动

如何解决Swift Playgrounds Brick Breaker,通过鼠标移动 -> 如何通过键盘移动

我正在玩 Swift Playground Brick Breaker。示例代码桨通过鼠标移动。现在我想使用键盘的左键和右键移动桨。 你能给我一些 swift 的代码吗?

这是 Paddle.swift 代码(鼠标移动)

import Foundation

public class Paddle: Sprite {

var collisionSound: GameSound = .warpMono

/// Allows you to move the bar back and forth with touch.
public func enableHorizontalTracking(in scene: Scene) {
    scene.trackTouch(withSprite: self)
}

/// disable touch control of the bar.
public func disableHorizontalTracking(in scene: Scene) {
    scene.stopTrackingTouch(withSprite: self)
}
    
/// Set the bar to its initial value setting.
public init(image: Image) {
    super.init(graphicType: .sprite,name: "paddle")
    self.image = image
    xScale = 1.30
    friction = 0.1
    interactionCategory = .paddle
    collisionCategories = [.ball]
    collisionNotificationCategories =  [.ball]
    
    setonCollisionHandler { collision in
        let position = collision.spriteB.position
        self.playCollisionSound(self.collisionSound,at: position,using: self.collisionSoundSource)
    }
    disablesOndisconnect = true
}

var collisionSoundSource = Graphic(shape: .circle(radius: 4),color: .clear,name: "impact")
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。