1
我是easelJS的新手。我想創建一個矩形,然後我想在輸入框中鍵入文本。這裏是我的代碼在畫框中居中放置一個矩形文字
function init() {
var stage = new createjs.Stage("canvas");
var layoutWidth = 0.8 * stage.canvas.width;
var layoutHeight = 0.6 * stage.canvas.height;
var layoutRect = new createjs.Shape();
layoutRect.graphics.beginStroke("black").drawRect((stage.canvas.width - layoutWidth)/2, (stage.canvas.height - layoutHeight)/2, layoutWidth, layoutHeight);
var button1 = new createjs.Shape();
button1.graphics.beginStroke("black").drawRect((stage.canvas.width - layoutWidth)/2, (stage.canvas.height - layoutHeight)/2 + 0.90 * layoutHeight, layoutWidth/2, 0.10 * layoutHeight);
var button2 = new createjs.Shape();
button2.graphics.beginStroke("black").drawRect((stage.canvas.width - layoutWidth)/2 + layoutWidth/2, (stage.canvas.height - layoutHeight)/2 + 0.90 * layoutHeight, layoutWidth/2, 0.10 * layoutHeight)
var inputText = document.getElementById("input") ;
var text = new createjs.Text();
text.set({
text: inputText.value
})
stage.addChild(layoutRect, button1, button2,text);
stage.update();
inputText.onkeyup = function(){
text.set({
text: inputText.value
})
stage.update()
}
}
我想這個文本出現在button1裏面,並正確對齊在中心。請解釋如何做到這一點。謝謝
謝謝。我有另一個疑問。如果我想在button1中放置一個圖像,使它佔據button1,該怎麼做?我無法設置圖像的寬度和高度。 –
您可以將其添加爲Container的子項,就像文本一樣。要縮放圖像,請使用'scaleX'和'scaleY'設置器。閱讀更多信息:http://blog.createjs.com/update-width-height-in-easeljs/ – Lanny