【发布时间】:2018-12-29 13:20:20
【问题描述】:
import React, { Component } from 'react';
import Phaser from 'phaser';
export default class App extends Component {
constructor(props) {
super(props);
this.game = null;
this.create = () => {
this.game.stage.backgroundColor = '#124184';
}
}
componentDidMount() {
this.game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-target',
{
create: this.create
}
);
console.log(this.create);
}
render() {
return (
<section id="phaser-target">
hello there old friend
</section>
)
}
}
所以我创建了 Phaser 游戏对象,在组件中做了 mount 方法,注意我的html 看起来像这样:
<body style="overflow: hidden;">
<noscript>
You need to enable JavaScript to run this app.
</noscript>
<div id="root"><section><section id="phaser-target">hello there old friend</section></section></div>
<script type="text/javascript" src="/static/js/bundle.js"></script>
<canvas width="1024" height="768"></canvas></body>
画布正在目标元素之外渲染。
还有,我的this.create 函数,我从来没有真正进入过那里。我console.log 但它永远不会进入。
我正在重新阅读代码,对我来说这一切都很有意义,它应该可以工作,但我不明白为什么不能。
谁能给我一些指导?
【问题讨论】:
标签: javascript reactjs phaser-framework