栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Go语言

2021SC@SDUSC Ebiten(十二) 输入工具代码详解

Go语言 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

2021SC@SDUSC Ebiten(十二) 输入工具代码详解

2021SC@SDUSC 

 

Go语言的简单2D游戏库-Ebiten   

 

目录

代码

Functions 

func AppendJustConnectedGamepadIDs 

func AppendJustPressedTouchIDs 

func AppendPressedKeys 

func GamepadButtonPressDuration 

func IsGamepadButtonJustPressed 

func IsGamepadButtonJustReleased 

func IsGamepadJustDisconnected 

func IsKeyJustPressed 

func IsKeyJustReleased 

func IsMouseButtonJustPressed 

func IsMouseButtonJustReleased 

func IsStandardGamepadButtonJustPressed 

func IsStandardGamepadButtonJustReleased 

func IsTouchJustReleased 

func MouseButtonPressDuration 

func StandardGamepadButtonPressDuration 

func TouchPressDuration


代码
func AppendPressedKeys(keys []ebiten.Key) []ebiten.Key {
	theInputState.m.RLock()
	defer theInputState.m.RUnlock()

	for i, d := range theInputState.keyDurations {
		if d == 0 {
			continue
		}
		keys = append(keys, ebiten.Key(i))
	}
	return keys
}
func PressedKeys() []ebiten.Key {
	return AppendPressedKeys(nil)
}
func IsKeyJustPressed(key ebiten.Key) bool {
	return KeyPressDuration(key) == 1
}
func IsKeyJustReleased(key ebiten.Key) bool {
	theInputState.m.RLock()
	r := theInputState.keyDurations[key] == 0 && theInputState.prevKeyDurations[key] > 0
	theInputState.m.RUnlock()
	return r
}
func KeyPressDuration(key ebiten.Key) int {
	theInputState.m.RLock()
	s := theInputState.keyDurations[key]
	theInputState.m.RUnlock()
	return s
}
func IsMouseButtonJustPressed(button ebiten.MouseButton) bool {
	return MouseButtonPressDuration(button) == 1
}
func IsMouseButtonJustReleased(button ebiten.MouseButton) bool {
	theInputState.m.RLock()
	r := theInputState.mouseButtonDurations[button] == 0 &&
		theInputState.prevMouseButtonDurations[button] > 0
	theInputState.m.RUnlock()
	return r
}
func MouseButtonPressDuration(button ebiten.MouseButton) int {
	theInputState.m.RLock()
	s := theInputState.mouseButtonDurations[button]
	theInputState.m.RUnlock()
	return s
}
func AppendJustConnectedGamepadIDs(gamepadIDs []ebiten.GamepadID) []ebiten.GamepadID {
	origLen := len(gamepadIDs)
	theInputState.m.RLock()
	for id := range theInputState.gamepadIDs {
		if _, ok := theInputState.prevGamepadIDs[id]; !ok {
			gamepadIDs = append(gamepadIDs, id)
		}
	}
	theInputState.m.RUnlock()
	s := gamepadIDs[origLen:]
	sort.Slice(s, func(a, b int) bool {
		return s[a] < s[b]
	})
	return gamepadIDs
}
func JustConnectedGamepadIDs() []ebiten.GamepadID {
	return AppendJustConnectedGamepadIDs(nil)
}
func IsGamepadJustDisconnected(id ebiten.GamepadID) bool {
	theInputState.m.RLock()
	_, prev := theInputState.prevGamepadIDs[id]
	_, current := theInputState.gamepadIDs[id]
	theInputState.m.RUnlock()
	return prev && !current
}
func IsGamepadButtonJustPressed(id ebiten.GamepadID, button ebiten.GamepadButton) bool {
	return GamepadButtonPressDuration(id, button) == 1
}
func IsGamepadButtonJustReleased(id ebiten.GamepadID, button ebiten.GamepadButton) bool {
	theInputState.m.RLock()
	prev := 0
	if _, ok := theInputState.prevGamepadButtonDurations[id]; ok {
		prev = theInputState.prevGamepadButtonDurations[id][button]
	}
	current := 0
	if _, ok := theInputState.gamepadButtonDurations[id]; ok {
		current = theInputState.gamepadButtonDurations[id][button]
	}
	theInputState.m.RUnlock()
	return current == 0 && prev > 0
}
func GamepadButtonPressDuration(id ebiten.GamepadID, button ebiten.GamepadButton) int {
	theInputState.m.RLock()
	s := 0
	if _, ok := theInputState.gamepadButtonDurations[id]; ok {
		s = theInputState.gamepadButtonDurations[id][button]
	}
	theInputState.m.RUnlock()
	return s
}
func IsStandardGamepadButtonJustPressed(id ebiten.GamepadID, button ebiten.StandardGamepadButton) bool {
	return StandardGamepadButtonPressDuration(id, button) == 1
}
func IsStandardGamepadButtonJustReleased(id ebiten.GamepadID, button ebiten.StandardGamepadButton) bool {
	theInputState.m.RLock()
	defer theInputState.m.RUnlock()

	var prev int
	if _, ok := theInputState.prevStandardGamepadButtonDurations[id]; ok {
		prev = theInputState.prevStandardGamepadButtonDurations[id][button]
	}
	var current int
	if _, ok := theInputState.standardGamepadButtonDurations[id]; ok {
		current = theInputState.standardGamepadButtonDurations[id][button]
	}
	return current == 0 && prev > 0
}
func StandardGamepadButtonPressDuration(id ebiten.GamepadID, button ebiten.StandardGamepadButton) int {
	theInputState.m.RLock()
	defer theInputState.m.RUnlock()

	if _, ok := theInputState.standardGamepadButtonDurations[id]; ok {
		return theInputState.standardGamepadButtonDurations[id][button]
	}
	return 0
}
func AppendJustPressedTouchIDs(touchIDs []ebiten.TouchID) []ebiten.TouchID {
	origLen := len(touchIDs)
	theInputState.m.RLock()
	for id, s := range theInputState.touchDurations {
		if s == 1 {
			touchIDs = append(touchIDs, id)
		}
	}
	theInputState.m.RUnlock()
	s := touchIDs[origLen:]
	sort.Slice(s, func(a, b int) bool {
		return s[a] < s[b]
	})
	return touchIDs
}
func JustPressedTouchIDs() []ebiten.TouchID {
	return AppendJustPressedTouchIDs(nil)
}
func IsTouchJustReleased(id ebiten.TouchID) bool {
	theInputState.m.RLock()
	r := theInputState.touchDurations[id] == 0 && theInputState.prevTouchDurations[id] > 0
	theInputState.m.RUnlock()
	return r
}
func TouchPressDuration(id ebiten.TouchID) int {
	theInputState.m.RLock()
	s := theInputState.touchDurations[id]
	theInputState.m.RUnlock()
	return s
}

Functions 

func AppendJustConnectedGamepadIDs 
func AppendJustConnectedGamepadIDs(gamepadIDs []ebiten.GamepadID) []ebiten.GamepadID

AppendJustConnectedGamepadIDs 将仅在当前帧中连接的游戏手柄 ID 附加到游戏手柄 ID,并返回扩展缓冲区。提供一个已经有足够容量的切片有效地工作。

AppendJustConnectedGamepadIDs 是并发安全的。

func AppendJustPressedTouchIDs 
func AppendJustPressedTouchIDs(touchIDs []ebiten.TouchID) []ebiten.TouchID

AppendJustPressedTouchIDs 将仅在当前帧中创建的触摸 ID 附加到 touchID,并返回扩展缓冲区。提供一个已经有足够容量的切片有效地工作。

AppendJustPressedTouchIDs 是并发安全的。

func AppendPressedKeys 
func AppendPressedKeys(keys []ebiten.Key) []ebiten.Key

AppendPressedKeys 将当前按下的键盘键附加到键并返回扩展缓冲区。提供一个已经有足够容量的切片有效地工作。

AppendPressedKeys 是并发安全的。

func GamepadButtonPressDuration 
func GamepadButtonPressDuration(id ebiten.GamepadID, button ebiten.GamepadButton) int

GamepadButtonPressDuration 返回按下游戏手柄 id 的游戏手柄按钮的帧数。

GamepadButtonPressDuration 是并发安全的。

func IsGamepadButtonJustPressed 
func IsGamepadButtonJustPressed(id ebiten.GamepadID, button ebiten.GamepadButton) bool

IsGamepadButtonJustPressed 返回一个布尔值,指示是否在当前帧中按下了游戏手柄 id 的给定游戏手柄按钮。

IsGamepadButtonJustPressed 是并发安全的。

func IsGamepadButtonJustReleased 
func IsGamepadButtonJustReleased(id ebiten.GamepadID, button ebiten.GamepadButton) bool

IsGamepadButtonJustReleased 返回一个布尔值,指示游戏手柄 id 的给定游戏手柄按钮是否仅在当前帧中释放。

IsGamepadButtonJustReleased 是并发安全的。

func IsGamepadJustDisconnected 
func IsGamepadJustDisconnected(id ebiten.GamepadID) bool

IsGamepadJustDisconnected 返回一个布尔值,指示给定 id 的游戏手柄是否仅在当前帧中释放。

IsGamepadJustDisconnected 是并发安全的。

func IsKeyJustPressed 
func IsKeyJustPressed(key ebiten.Key) bool

IsKeyJustPressed 返回一个布尔值,指示给定的键是否仅在当前帧中被按下。

IsKeyJustPressed 是并发安全的。

func IsKeyJustReleased 
func IsKeyJustReleased(key ebiten.Key) bool

IsKeyJustReleased 返回一个布尔值,指示给定的键是否仅在当前帧中被释放。

IsKeyJustReleased 是并发安全的。

func IsMouseButtonJustPressed 
func IsMouseButtonJustPressed(button ebiten.MouseButton) bool

IsMouseButtonJustPressed 返回一个布尔值,指示给定的鼠标按钮是否仅在当前帧中被按下。

IsMouseButtonJustPressed 是并发安全的。

func IsMouseButtonJustReleased 
func IsMouseButtonJustReleased(button ebiten.MouseButton) bool

IsMouseButtonJustReleased 返回一个布尔值,指示给定的鼠标按钮是否仅在当前帧中被释放。

IsMouseButtonJustReleased 是并发安全的。

func IsStandardGamepadButtonJustPressed 
func IsStandardGamepadButtonJustPressed(id ebiten.GamepadID, button ebiten.StandardGamepadButton) bool

IsStandardGamepadButtonJustPressed 返回一个布尔值,指示是否在当前帧中按下了游戏手柄 id 的给定标准游戏手柄按钮。

IsStandardGamepadButtonJustPressed 是并发安全的。

func IsStandardGamepadButtonJustReleased 
func IsStandardGamepadButtonJustReleased(id ebiten.GamepadID, button ebiten.StandardGamepadButton) bool

IsStandardGamepadButtonJustReleased 返回一个布尔值,指示游戏手柄 id 的给定标准游戏手柄按钮是否仅在当前帧中释放。

IsStandardGamepadButtonJustReleased 是并发安全的。

func IsTouchJustReleased 
func IsTouchJustReleased(id ebiten.TouchID) bool

IsTouchJustReleased 返回一个布尔值,指示给定的触摸是否仅在当前帧中释放。

IsTouchJustReleased 是并发安全的。

func MouseButtonPressDuration 
func MouseButtonPressDuration(button ebiten.MouseButton) int

MouseButtonPressDuration 返回在帧中按下鼠标按钮的时间。

MouseButtonPressDuration 是并发安全的。

func StandardGamepadButtonPressDuration 
func StandardGamepadButtonPressDuration(id ebiten.GamepadID, button ebiten.StandardGamepadButton) int

StandardGamepadButtonPressDuration 返回按下游戏手柄 id 的标准游戏手柄按钮的帧数。

StandardGamepadButtonPressDuration 是并发安全的。

func TouchPressDuration
func TouchPressDuration(id ebiten.TouchID) int

TouchPressDuration 返回触摸在帧中保留的时间。

TouchPressDuration 是并发安全的。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/990655.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号