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 }更多推荐
发布评论