Leanote's Blog
I love Leanote!
Toggle navigation
Leanote's Blog
Home
Chrome
Git
Linux
Windows
Others
工具大全
VsCode
Expo
Html
JavaScript
Npm
Node
Mock
React-Native
React
TypeScript
小程序
插件
正则
Dva
Ant-Design-React
Umi
Vue
Vux
Ant-Design-Vue
Http
Java
flutter
开发小工具
About Me
Archives
Tags
react使用pixi画图
2019-11-14 07:46:24
17
0
0
admin
> npm i pixi.js ### 使用: ``` import React, { Component } from 'react' import PropTypes from 'prop-types' import * as Pixi from "pixi.js" const styles = { box: { position: "relative", zIndex: "999999999999999999", } } class PixiComponent extends Component { constructor(props) { super(props) this.state = { pixi: null, gameCanvas: null, } } refCallBack = ref => { if (!this.state.gameCanvas) { this.setState({ gameCanvas: ref }, () => { const app = new Pixi.Application({ transparent: true, // backgroundColor: 0xffffff, resizeTo: window, }); this.setState({ pixi: app }, () => { let newGameCanvas = this.state.gameCanvas newGameCanvas.appendChild(this.state.pixi.view); this.setState({ gameCanvas: newGameCanvas }, () => { this.state.pixi.start(); console.log(this.state.gameCanvas); console.log(this.state.pixi); }) }) }) } } componentWillUnmount() { this.state.pixi.stop(); } render() { return ( <div ref={this.refCallBack} /> ) } } PixiComponent.propTypes = { } export default PixiComponent ```
Pre:
react ref(父组件访问子组件, 除了props)
Next:
react常用npm插件
0
likes
17
Weibo
Wechat
Tencent Weibo
QQ Zone
RenRen
Submit
Sign in
to leave a comment.
No Leanote account?
Sign up now.
0
comments
More...
Table of content
No Leanote account? Sign up now.