下面是一个数组,它的元素存储了一些长文本行。
var fcontent = [
["Definition: The term computer is obtained from the word compute. A computer is an electronic device that inputs (takes in) facts (known as data), and then processes (does something to or with) it. Afterwards it outputs, or displays, the results for you to see. Data is all kinds of facts, including, pictures, letters, numbers, sounds, etc."],
["Moreover: A computer is a system that is made up of a number of components. Next is a diagram of a computer system with some of its components"],
];
我正在使用以下函数在 Canvas 上显示元素:
firstLevelContent:function()
{
var startPoint = 48; $('.gamelayer').hide();
$('#gamecanvas').show();
for (var i=0; i<fcontent.length; i++)
{
game.context.strokeRect(1, 25, 637, 385);
game.context.fillStyle = 'brown';
game.context.font = 'bold 20px sans-serif';
game.context.textBaseline = 'bottom';
game.context.fillText(fcontent[i], 2, startPoint);
startPoint+=17;
}
},
但是文本显示在代码中,我想找到一种方法来换行以适应画布的宽度(640),这样我就可以看到所有显示的文本。请帮助我。谢谢。