简体   繁体   English

使processing.js草图从外部JS变量获取值

[英]Making processing.js sketch get value from external JS variable

I have a game written in Javascript with the Processing.js library. 我有一个Javascript编写的带有Processing.js库的游戏。 I want to make highscores for that game, and for that I want the user to be able to type a name in an input tag in the page HTML. 我想为该游戏创造高分,为此,我希望用户能够在页面HTML的输入标签中输入名称。 The problem is that I don't know how to make my Processing.js sketch "see" the variable containing the value of the input field. 问题是我不知道如何使我的Processing.js草图“看到”包含输入字段值的变量。 Does anyone know how I can do this? 有人知道我该怎么做吗? Thanks in advanced 提前致谢

You should check out the Processing.js documentation, specifically the JavaScript Quick Start , specifically the Writing Documents that Combine Processing and JavaScript Code section. 您应该查看Processing.js文档,特别是JavaScript快速入门 ,特别是结合处理和JavaScript代码编写文档部分。

There are three main ways to approach this: you can write Processing code that accesses an external JavaScript variable, or you could write JavaScript code that does something like call a setter function in your Processing code, or you could write JavaScript code directly in your Processing code. 有三种主要的处理方式:您可以编写访问外部JavaScript变量的Processing代码,也可以编写在Processing代码中执行诸如调用setter函数之类的JavaScript代码,或者直接在Processing中编写JavaScript代码码。

Any of those approaches would work fine for what you're trying to do. 这些方法中的任何一种都可以很好地满足您的尝试。 If you still can't get it working, please post a MCVE of what you tried in a new question, and we'll go from there. 如果仍然无法正常运行,请发布您在新问题中尝试过的内容的MCVE ,我们将从那里开始。 Good luck. 祝好运。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM