javascript 如何制作健康棒

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20277052/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 18:08:21  来源:igfitidea点击:

How to make a health bar

javascripthtml

提问by user3047715

I am trying to make my own version of a pokemon game using very simple HTML and JavaScript.

我正在尝试使用非常简单的 HTML 和 JavaScript 制作我自己的口袋妖怪游戏版本。

So far, I have everything covered, except the health bar. How do I make an entity in my code, that will represent a bar, and when the opposing team selects a move, the health bar goes down?

到目前为止,我已经涵盖了所有内容,除了健康栏。我如何在我的代码中创建一个实体,它代表一个酒吧,当对方团队选择一个动作时,健康栏会下降?

Would I use a bunch of small div's?

我会使用一堆小 div 吗?

回答by MultiplyByZer0

I would recommend a HTML progress bar:

我会推荐一个 HTML 进度条:

<progress id="health" value="100" max="100"></progress>

And when they lose/gain health, do run this Javascript code:

当他们失去/获得健康时,请运行以下 Javascript 代码:

let health = document.getElementById("health")
health.value -= 10; //Or whatever you want to do with it.

回答by Marc