Commit ecdc964e authored by wildfirecode13's avatar wildfirecode13

1

parent 36f8b2d7
/**
* Created by rockyl on 2020/11/14.
* 一个简单示例
*/
import {WidgetBase, TextField, Sprite, TextureCache, Tween} from "spark-wrapper-fyge"; import {WidgetBase, TextField, Sprite, TextureCache, Tween} from "spark-wrapper-fyge";
export class GameStage extends WidgetBase { export class GameStage extends WidgetBase {
...@@ -13,19 +9,4 @@ export class GameStage extends WidgetBase { ...@@ -13,19 +9,4 @@ export class GameStage extends WidgetBase {
label.size = 40; label.size = 40;
this.addChild(label); this.addChild(label);
} }
/**
* 销毁回调
*/
onDestroy() {
}
start() {
}
stop() {
}
} }
import React, {useState, useRef} from 'react'; import React, {useState, useRef} from 'react';
import './App.scss'; import './App.scss';
import {CanvasWidget} from '@spark/ui'; import {CanvasWidget} from '@spark/ui';
import {Playground} from "./bundle"; import {Playground} from "./game/main.js";
/** /**
* 配置覆盖 * 配置覆盖
...@@ -21,7 +21,7 @@ const widgetConfig = { ...@@ -21,7 +21,7 @@ const widgetConfig = {
} }
function App() { function App() {
const [widgetVisible, setWidgetVisible] = useState(false); const [widgetVisible, setWidgetVisible] = useState(true);
const widgetRef = useRef(); const widgetRef = useRef();
function onReady(widget) { function onReady(widget) {
...@@ -59,13 +59,13 @@ function App() { ...@@ -59,13 +59,13 @@ function App() {
return ( return (
<div className="App"> <div className="App">
<div className="control-bar"> {/* <div className="control-bar">
<button onClick={e => onClickButton('setup')}>setup</button> <button onClick={e => onClickButton('setup')}>setup</button>
<button onClick={e => onClickButton('unSetup')}>unSetup</button> <button onClick={e => onClickButton('unSetup')}>unSetup</button>
<button onClick={e => onClickButton('start')}>start</button> <button onClick={e => onClickButton('start')}>start</button>
<button onClick={e => onClickButton('stop')}>stop</button> <button onClick={e => onClickButton('stop')}>stop</button>
</div> </div> */}
{ {
widgetVisible ? <CanvasWidget ref={widgetRef} className="canvas-widget" widgetFactory={Playground} widgetConfig={widgetConfig} widgetVisible ? <CanvasWidget ref={widgetRef} className="canvas-widget" widgetFactory={Playground} widgetConfig={widgetConfig}
onEvent={onEvent} onEvent={onEvent}
......
import { WidgetBase, TextField } from 'spark-wrapper-fyge';
import metaConfig from '../meta.json';
class GameStage extends WidgetBase {
onLaunched() {
let label = new TextField();
label.text = 'Hello CanvasWidget!';
label.fillColor = '#000';
label.size = 40;
this.addChild(label);
}
/**
* 销毁回调
*/
onDestroy() {
}
start() {
}
stop() {
}
}
/**
* Created by rockyl on 2020/9/19.
*/
/**
* Playground模块
* @description Playground模块的工厂方法
* @ctype CANVAS_WIDGET
*/
function Playground() {
return new GameStage(getMetaConfig('Playground'));
}
function getMetaConfig(id){
return metaConfig[id]
}
//===== END APPEND CODE =====
export { Playground };
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment