KineticJS setText方法像定时器一样更新(KineticJS setText method to update like a Timer)

编程入门 行业动态 更新时间:2024-10-25 07:21:34
KineticJS setText方法像定时器一样更新(KineticJS setText method to update like a Timer)

我需要像定时器一样更新KineticJS文本的文本属性。 但我下面的代码doent按预期工作,我做错了什么:

var dateTimeText = new Kinetic.Text({ x: 40, y: 400, text: "Sample", fontSize: 18, width: 700, fontFamily: 'Calibri', fill: 'black', width: 700, padding: 10, align: 'right', draggable: true }); setInterval(function () { onUpdateTime() }, 1000); function onUpdateTime() { var date = new Date(); dateTimeText.setText(date.toLocaleTimeString()); }

在onUpdateTime()中,我应该对dateTimeText进行操作。 在dateTimeText()上添加可拖动属性并点击它时,我至少可以看到更新的值:)

I need to update the text property of a KineticJS text like a timer. but my below code doent work as expected, what I am doing wrong:

var dateTimeText = new Kinetic.Text({ x: 40, y: 400, text: "Sample", fontSize: 18, width: 700, fontFamily: 'Calibri', fill: 'black', width: 700, padding: 10, align: 'right', draggable: true }); setInterval(function () { onUpdateTime() }, 1000); function onUpdateTime() { var date = new Date(); dateTimeText.setText(date.toLocaleTimeString()); }

In the onUpdateTime(), should I do manipulations on dateTimeText. When adding the draggable attribute on dateTimeText() and when clicking on it, i can atleast see the updated value :)

最满意答案

尝试这个:

function onUpdateTime() { var date = new Date(); dateTimeText.setText(date.toLocaleTimeString()); // layer.draw(); // either this, or whatever the layer is called // dateTimeText.getParent().draw(); // or this, auto get parent layer dateTimeText.getLayer().draw(); // better solution suggested by Eric Rowell }

Try this:

function onUpdateTime() { var date = new Date(); dateTimeText.setText(date.toLocaleTimeString()); // layer.draw(); // either this, or whatever the layer is called // dateTimeText.getParent().draw(); // or this, auto get parent layer dateTimeText.getLayer().draw(); // better solution suggested by Eric Rowell }

更多推荐

本文发布于:2023-08-07 22:11:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1466435.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:定时器   方法   setText   KineticJS   update

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!