gpt4 book ai didi

javascript - 在 flash cc createjs 中集成 html : not creating createjs text . 可以集成吗?

转载 作者:行者123 更新时间:2023-12-03 06:49:55 26 4
gpt4 key购买 nike

我试图将这个 h1 插入到 canvas 中。但它没有显示。无论如何,将 w3school html 集成到 Canvas 中,而无需使用 easeljs 程序创建文本。我将其添加到 Canvas 内。

  <body onload="init();" style="background-color:#D4D4D4">
<canvas id="canvas" width="550" height="300" style="background-color:#ffffff">
<h1> i like this </h1>
</canvas>


<script>
function init() {
canvas = document.getElementById("canvas");
exportRoot = new lib.Untitled1();

stage = new createjs.Stage(canvas);
stage.addChild(exportRoot);

stage.update();

createjs.Ticker.setFPS(24);
createjs.Ticker.addEventListener("tick", stage);
}
</script>
</head>

<body onload="init();" style="background-color:#D4D4D4">
<canvas id="canvas" width="550" height="300" style="background-color:#ffffff">
<h1> i like this </h1>
</canvas>

最佳答案

canvas 标记的子元素被视为替代内容,如果浏览器支持 canvas 标记,则不会显示。

由于您已经在使用 createjs,因此您可以通过 createjs text object 添加文本。这是文档中的示例。

var text = new createjs.Text("Hello World", "20px Arial", "#ff7700");
text.x = 100;
text.textBaseline = "alphabetic";
stage.addChild(text);
stage.update();

或者,您可以使用 css 将 html 文本元素放置在 canvas 标签的顶部,如所讨论的 here .

关于javascript - 在 flash cc createjs 中集成 html : not creating createjs text . 可以集成吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37562014/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com