Giter Site home page Giter Site logo

游戏超时判断如何实现 about hilo HOT 9 CLOSED

hiloteam avatar hiloteam commented on April 28, 2024
游戏超时判断如何实现

from hilo.

Comments (9)

06wj avatar 06wj commented on April 28, 2024

开始时保存下结束时间new Date().getTime() + 3000;,然后定时器里判断当前时间和结束时间的对比

可以看这个demo: http://runjs.cn/detail/lvjkgzrw

from hilo.

jingchaofang avatar jingchaofang commented on April 28, 2024

thanks, the best wishes

from hilo.

jingchaofang avatar jingchaofang commented on April 28, 2024

@06wj 应用时textAlign和textVAlign不生效

from hilo.

jingchaofang avatar jingchaofang commented on April 28, 2024

@06wj 看源码知道还需要初始一下宽高就能正常使用textAlign和textVAlign了,这个建议落实到文档提醒下开发者

new Hilo.Text({
    font: "bold 43px arial,sans-serif",
    textAlign:'right',
    textVAlign:'middle',
    width: 720,
    height: 1080,
    text:'30s'
}).addTo(stage);

from hilo.

06wj avatar 06wj commented on April 28, 2024

好 因为canvas本身没这个属性,是通过js根据width,height设置位置实现的,我加到文档里

from hilo.

06wj avatar 06wj commented on April 28, 2024

@jingchaofang http://hiloteam.github.io/Hilo/docs/api-zh/symbols/Text.html#textAlign 已加

from hilo.

finscn avatar finscn commented on April 28, 2024

建议提供自动计算文字大小的功能。这个并不难。
我之前写的一个 Canvas的Label组件里有类似这样的代码:

            if (this._autoSizeWithText && this.textHolder) {
                if (this.textHolder.needToCompute) {
                    this.textHolder.computeSize();
                    this.computeSizeWithText();
                }
            }

当没有给Label组件设置大小的时候,则采用『文本内容多大,Label组件就多大』的方案。
宽度用 context.measureText 计算。
高度可以用一个专门计算高度的临时canvas来做,提前计算好。 字体,字号和 高度的映射关系。
(一个游戏里的字体和字号是有限的,不可能想做字处理软件一样无法确定用户到底要用什么字体什么字号)

宽高计算好之后要记得 加上 描边、阴影一类的大小。

from hilo.

06wj avatar 06wj commented on April 28, 2024

自动计算文字大小功能有的,只是textAlign和textVAlign需要手动提供对象的宽高才能实现啊

from hilo.

finscn avatar finscn commented on April 28, 2024

@06wj , 哦 明白了, 他说的这个 textAlign 是 label 内的 对齐方式, 不是label容器的。我理解错了

from hilo.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.