文本
在你的游戏中添加文本是很简单的。创建一个含有 "Text" 组件的实体:
var helloWorldText = Crafty.e('2D, DOM, Text')
.attr({
x: 10,
y: 10
});
最简单的文字例子看起来像这样:
helloWorldText.text('Hello World');
文本样式
"Text" 组件提供了很多方法来修饰文本。
你可以使用 .textColor()
方法设置文本颜色:
helloWorldText.textColor('red');
你可以使用 ´.textFont()` 方法通过样式对象定义文本样式:
helloWorldText.textFont({
size: '20px',
weight: 'bold'
});
可使用的属性如下:
- type
- weight
- size
- family
- lineHeight
- variant
2D 属性
大多数标准的 2D 属性也适用于文本:你可以移动它,旋转它,附加它到其他的实体等等。但还有一些地方需要注意: