(canvas)
| 21 | ]); |
| 22 | |
| 23 | export async function init(canvas) { |
| 24 | const game = new Game(); |
| 25 | await game.init({ |
| 26 | systems: [ |
| 27 | //@ts-ignore |
| 28 | new RendererSystem({ |
| 29 | canvas, |
| 30 | width: 750, |
| 31 | height: 1000, |
| 32 | backgroundColor: '#f5f5f5', |
| 33 | }), |
| 34 | //@ts-ignore |
| 35 | new TextSystem(), |
| 36 | ], |
| 37 | }); |
| 38 | |
| 39 | game.scene.transform.size = { |
| 40 | width: 750, |
| 41 | height: 1000, |
| 42 | }; |
| 43 | |
| 44 | // 1. 基础 HTML 文本 |
| 45 | const basicHtmlText = new GameObject('basicHtmlText', { |
| 46 | position: { x: 0, y: 80 }, |
| 47 | origin: { x: 0.5, y: 0 }, |
| 48 | anchor: { x: 0.5, y: 0 }, |
| 49 | }); |
| 50 | |
| 51 | basicHtmlText.addComponent( |
| 52 | new HTMLText({ |
| 53 | text: '<h1 style="margin:0">欢迎使用 HTMLText</h1>', |
| 54 | style: { |
| 55 | fontFamily: 'Arial', |
| 56 | fontSize: 32, |
| 57 | fill: '#ff6b6b', |
| 58 | align: 'center', |
| 59 | }, |
| 60 | }), |
| 61 | ); |
| 62 | |
| 63 | game.scene.addChild(basicHtmlText); |
| 64 | |
| 65 | // 2. 富文本 - 混合样式 |
| 66 | const richText = new GameObject('richText', { |
| 67 | position: { x: 0, y: 180 }, |
| 68 | origin: { x: 0.5, y: 0 }, |
| 69 | anchor: { x: 0.5, y: 0 }, |
| 70 | }); |
| 71 | |
| 72 | richText.addComponent( |
| 73 | new HTMLText({ |
| 74 | text: ` |
| 75 | <p style="margin:0"> |
| 76 | 这是<strong style="color:#e74c3c">粗体</strong>和 |
| 77 | <em style="color:#3498db">斜体</em>文本, |
| 78 | 还有<span style="text-decoration:underline">下划线</span>。 |
| 79 | </p> |
| 80 | `, |
nothing calls this directly
no test coverage detected