Closed jingchaofang closed 7 years ago
开始时保存下结束时间new Date().getTime() + 3000;
,然后定时器里判断当前时间和结束时间的对比
可以看这个demo: http://runjs.cn/detail/lvjkgzrw
thanks, the best wishes
@06wj 应用时textAlign和textVAlign不生效
@06wj 看源码知道还需要初始一下宽高就能正常使用textAlign和textVAlign了,这个建议落实到文档提醒下开发者
new Hilo.Text({
font: "bold 43px arial,sans-serif",
textAlign:'right',
textVAlign:'middle',
width: 720,
height: 1080,
text:'30s'
}).addTo(stage);
好 因为canvas本身没这个属性,是通过js根据width,height设置位置实现的,我加到文档里
建议提供自动计算文字大小的功能。这个并不难。 我之前写的一个 Canvas的Label组件里有类似这样的代码:
if (this._autoSizeWithText && this.textHolder) {
if (this.textHolder.needToCompute) {
this.textHolder.computeSize();
this.computeSizeWithText();
}
}
当没有给Label组件设置大小的时候,则采用『文本内容多大,Label组件就多大』的方案。 宽度用 context.measureText 计算。 高度可以用一个专门计算高度的临时canvas来做,提前计算好。 字体,字号和 高度的映射关系。 (一个游戏里的字体和字号是有限的,不可能想做字处理软件一样无法确定用户到底要用什么字体什么字号)
宽高计算好之后要记得 加上 描边、阴影一类的大小。
自动计算文字大小功能有的,只是textAlign和textVAlign需要手动提供对象的宽高才能实现啊
@06wj , 哦 明白了, 他说的这个 textAlign 是 label 内的 对齐方式, 不是label容器的。我理解错了
应用场景:游戏倒计时30s结束给出游戏结果,在游戏中用户可能会切换到其他页面再回到游戏页面,不知道具体的实现步骤是怎样的,希望指点一下