npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

input-action

v1.0.3

Published

这是一个简单的,不成熟的,类似于 ue4 输入系统的输入系统. 你可以使用Action来抽象输入, 而不是去监听具体的按键变化.

Downloads

5

Readme

简介

这是一个简单的,不成熟的,类似于 ue4 输入系统的输入系统. 你可以使用Action来抽象输入, 而不是去监听具体的按键变化.

示例

比如, 如果你想在babylonjs中控制一个box前后左右移动, 你可以这么写

    // 配置输入
let input = new InputActionManage("jump", "moveY", "moveX")
let {jump, moveX, moveY} = input.actions
jump.addKey(" ").type("up") // click down up
moveY.addKey("w").scale(1)
moveY.addKey("s").scale(-1)
moveX.addKey("d").scale(1)
moveX.addKey("a").scale(-1)
input.attach(scene.getEngine().getInputElement())
let box = MeshBuilder.CreateBox("")

// 监听输入
scene.onBeforeRenderObservable.add(eventData => {
    let x = moveX.value
    let y = moveY.value
    box.position.addInPlace(new Vector3(x, 0, y).scale(scene.deltaTime * 0.001))
})
input.actions.jump.addListener(() => {
    console.log("jump")
})

这段代码定义了三个Action, 分别是跳跃, 前后移动和左右移动.

然后为jump绑定了空格键, .type的意思是什么时候触发 总共有三种, 分别是 按下时, 松开时和点击时.

为前后移动绑定了w和s按键, 其中的scale代表键按下的时候会应用的值. w为1 ,s为-1.

这样按下w时 moveY的值就是1, 按下s时 moveY的值就是-1. 两个同时按下的话, 值会是0.

类型支持

用typescript, 当然要支持自动补全啦. 定义的action名字, 可以在actions下面被补全出来.

img.png