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 (将#修改为@)