Commit d3d3c9d7 authored by 汪欢's avatar 汪欢

first add

parent 7b597ba5
/**
* Created by renjianfeng on 2020-03-13.
*/
const customId = 'basket';
(async function () {
let customModule = await fetch(`../meta.json`);
customModule = await customModule.json();
console.log(customModule);
await loadAssets(customModule.assets);
launchWithCustomModule(customModule);
})();
function launchWithCustomModule(customModule) {
//engine.registerCustomCodeModule(customModule);
engine.registerCustomModule(customId, window[customId]);
const { props: propsOption, assets } = customModule;
let props = engine.computeProps(customModuleProps, propsOption);
const customModuleIns = {
id: customId,
props,
assets,
};
engine.registerCustomModules([customModuleIns]);
engine.launchWithConfig({
options: {
entrySceneView: 'entry',
},
assets: [],
views: [{
name: 'entry',
type: 'node',
properties: {
x: 0,
y: 0,
}
}],
customs: [],
}, null, function () {
setTimeout(() => {
engine.addCustomModule(customId, engine.gameStage.sceneContainer.getChildAt(0));
}, 100);
// setTimeout(() => {
// engine.globalEvent.dispatchEvent('cloud-game-reset', {
// });
// engine.globalEvent.dispatchEvent('pictures-start', {
// });
// }, 1000);
});
// engine.globalEvent.addEventListener('cloud-time-update', (e) => {
// // console.log(e.type, e.data);
// });
// engine.globalEvent.addEventListener('cloud-game-fail', (e) => {
// console.log(e.type, e.data);
// });
// engine.globalEvent.addEventListener('cloud-game-success', (e) => {
// console.log(e.type, e.data);
// });
// engine.globalEvent.addEventListener('cloud-game-reset', (e) => {
// console.log(e.type, e.data);
// });
}
function getAssetByUUID(uuid) {
return engine.resolveCustomAsset(customId, uuid);
}
function getProps() {
return engine.getProps(customId);
}
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<title>美食从天而降</title>
<meta name="viewport"
content="width=device-width,initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no"/>
<meta name="apple-mobile-web-app-capable" content="yes"/>
<meta name="full-screen" content="true"/>
<meta name="screen-orientation" content="portrait"/>
<meta name="x5-fullscreen" content="true"/>
<meta name="360-fullscreen" content="true"/>
<style>
html,
body {
padding: 0;
margin: 0;
border: 0;
width: 100%;
height: 100%;
overflow: hidden;
position: absolute;
background-color: gray;
}
.game-container{
width: 100%;
height: 100%;
line-height:0;
font-size:0;
}
</style>
</head>
<body>
<div id="game-container" class="game-container"></div>
<!-- <script crossorigin="anonymous" src="//yun.duiba.com.cn/editor/zeroing/libs/engine.1de84ff79dba19e949088de63aa75af51a515e5c.js"></script>
<script crossorigin="anonymous" src="//yun.duiba.com.cn/editor/zeroing/libs/svga.fd3923ae6e664251ca7981801a65809cc5f36bc3.js"></script> -->
<script crossorigin="anonymous" src="//yun.duiba.com.cn/editor/zeroing/libs/engine.cba09e24bd26909e1a67685a889d4799f4c2597a.js"></script>
<script crossorigin="anonymous" src="//yun.duiba.com.cn/editor/zeroing/libs/svga.bbb584f45f3ee647d0611653cb854c5d5bb8fb47.js"></script>
<script src="//yun.duiba.com.cn/js-libs/p2.js/0.7.1/p2.min.js"></script>
<!-- <script src="//yun.duiba.com.cn/editor/zeroing/libs/engine.ebc906f6b50b8da0a669f77027981d5f3cb560ce.js"></script> -->
<!-- <script src="http://localhost:4002/debug/engine.js"></script>
<script src="http://localhost:4003/debug/engine-svga.js"></script> -->
<!--<script src="//yun.duiba.com.cn/editor/zeroing/libs/engine.9a9dbfda4cb2dd5508ecddfe3d95dfd88063f7b5.js"></script>-->
<script src="app.js"></script>
<script src="props.js"></script>
<script src="load-assets.js"></script>
<script src="main.js"></script>
<script>
</script>
</body>
/**
* Created by rockyl on 2020-01-21.
*/
const assets = [
{
"name": "背景",
"url": "//yun.duiba.com.cn/aurora/assets/b7708649be2270379bd764e25ee2e783a7d49f7a.jpg",
"uuid": "a880ee6b-c6d1-4d8f-8734-367f368a1803",
"ext": ".jpg"
},
{
"name": "篮板",
"url": "//yun.duiba.com.cn/aurora/assets/13fd42607d6a79c9a8d0d053962d926fa45fa0c9.png",
"uuid": "a1c6f4d9-8f9a-4267-b701-d2a7e9ff5b1b",
"ext": ".png"
},
{
"name": "球网前",
"url": "//yun.duiba.com.cn/aurora/assets/6c94fab92bc10e8716a4d90666b96d73603b8e59.png",
"uuid": "882618a9-2cc9-498e-a764-268c6cfe6c99",
"ext": ".png"
},
{
"name": "球网后",
"url": "//yun.duiba.com.cn/aurora/assets/2a3596dd0291a20fcee55445752dc38634074c59.png",
"uuid": "0680dba9-757b-443b-8d0f-0d5811254c7d",
"ext": ".png"
},
{
"name": "篮球",
"url": "//yun.duiba.com.cn/aurora/assets/3dc11f2d91659b7e7e1d06a9853cbc9f818e1ea2.png",
"uuid": "270bbac6-b59e-4692-80c9-a95aa0b03c17",
"ext": ".png"
}
];
function loadAssets(customModuleAssets, onProgress, onComplete){
return engine.loadAssets(assets.concat(...customModuleAssets), onProgress, onComplete);
}
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('tslib')) :
typeof define === 'function' && define.amd ? define(['tslib'], factory) :
(global = global || self, global.basket = factory(global.tslib));
}(this, (function (tslib) { 'use strict';
function getTexture(uuid) {
return engine.Texture.from(getAssetByUUID(uuid).uuid);
}
function getTextureByName(name) {
return getTexture(engine.getAssetByName(name).uuid);
}
//# sourceMappingURL=utils.js.map
var BasketBoard = (function (_super) {
tslib.__extends(BasketBoard, _super);
function BasketBoard() {
var _this = _super.call(this) || this;
_this.board = new engine.Sprite(getTextureByName('篮板'));
_this.netFront = new engine.Sprite(getTextureByName('球网前'));
_this.netBack = new engine.Sprite(getTextureByName('球网后'));
_this.config = {
boardBody: {
x: 0,
y: 0,
width: 0.3,
height: 2
},
insidePointBody: {
x: 15,
y: 65,
radius: 0.07
},
outsidePointBody: {
x: 180,
y: 65,
radius: 0.05
},
upSensorBody: {
x: 100,
y: 65,
radius: 0.05
},
downSensorBody: {
x: 100,
y: 65 + 80,
radius: 0.05
}
};
_this.addChild(_this.board);
var shape = new engine.Shape();
shape.beginFill(0xff0000, 0.5);
shape.drawEllipse(50, 150, 200, 80);
shape.endFill();
_this.board.addChild(shape);
return _this;
}
BasketBoard.prototype.setPosition = function (x, y) {
this.x = x;
this.y = y;
};
return BasketBoard;
}(engine.Container));
//# sourceMappingURL=basketBoard.js.map
var GameView = (function (_super) {
tslib.__extends(GameView, _super);
function GameView() {
var _this = _super.call(this) || this;
_this.basketBoard = new BasketBoard();
_this.pool = {};
_this.horizontal = [74, 676];
_this.verticalArea = [200, 600];
_this.verticalInit = 462 - 45;
_this.positionInitBall = {
x: 551,
y: 805,
};
_this.vertical = _this.verticalInit;
_this.isRight = false;
_this.saleX = _this.isRight ? 1 : -1;
_this.config = {
net: {
x: 9.5,
y: 19 + 45,
},
insidePointBody: {
x: 15,
y: 65,
radius: 0.07,
},
outsidePointBody: {
x: 180,
y: 65,
radius: 0.05,
},
boardBody: {
x: 0,
y: 0,
width: 0.3,
height: 2,
},
upSensorBody: {
x: 100,
y: 65,
radius: 0.05,
},
downSensorBody: {
x: 100,
y: 65 + 80,
radius: 0.05,
},
};
_this.toRo = 180 / Math.PI;
_this.loopMark = false;
_this.guideMark = false;
_this.ballAddSpeedX = 1.2;
_this.ballAddSpeedY = 5.3;
_this.gravity = -5;
_this.stepSpeed = [0.5, 3.5];
_this.detaTimeEf = _this.stepSpeed[1];
_this.ballSpeedLimitX = 3;
_this.planeHeight = 1100;
_this.brokeMark = false;
_this.doubleHit = 0;
_this.timeLimit = window["timeLimit"] ? window["timeLimit"] : 5;
_this.timeMark = false;
_this.timeCount = _this.timeLimit;
_this.timeSpeed = 1 / 60;
_this.clickMark = false;
_this.once(engine.Event.ADDED_TO_STAGE, _this.start, _this);
var p2 = window["p2"];
var materialBall = new p2.Material(1);
var materialPoint = new p2.Material(2);
var materialBoard = new p2.Material(2);
var materialPlane = new p2.Material(2);
var contactMaterialBallPoint = new p2.ContactMaterial(materialBall, materialPoint, {
friction: 0.3,
restitution: 0.5,
});
var contactMaterialBallBoard = new p2.ContactMaterial(materialBall, materialBoard, {
friction: 0.3,
restitution: 0.5,
});
var contactMaterialBallPlane = new p2.ContactMaterial(materialBall, materialPlane, {
friction: 0.3,
restitution: 0.7,
});
_this.world = new p2.World();
_this.world.sleepMode = p2.World.BODY_SLEEPING;
_this.world.gravity = [0, 10];
var box = new p2.Box({ width: _this.config.boardBody.width, height: _this.config.boardBody.height, material: materialBoard });
_this.boxBody = new p2.Body({ mass: 0, type: p2.Body.STATIC, position: [20, 200] });
_this.boxBody.addShape(box);
var display = new engine.Texture(getTextureByName('篮板'));
var displays = new engine.Sprite(display);
_this.addChild(displays);
_this.boxBody.displays = [displays];
_this.world.addBody(_this.boxBody);
_this.world.defaultContactMaterial.friction = 0.3;
_this.world.defaultContactMaterial.restitution = 0.6;
_this.world.setGlobalStiffness(1e5);
_this.world.addContactMaterial(contactMaterialBallPoint);
_this.world.addContactMaterial(contactMaterialBallBoard);
_this.world.addContactMaterial(contactMaterialBallPlane);
var ball = new p2.Circle({ radius: 60 });
_this.basketball = new p2.Body({
mass: 0,
position: [300, 250],
velocity: [-40, 0],
material: materialBall
});
_this.basketball.addShape(ball);
_this.world.addBody(_this.basketball);
var balldisplay = new engine.Texture(getTextureByName('篮球'));
var balldisplays = new engine.Sprite(balldisplay);
_this.addChild(balldisplays);
_this.basketball.displays = [balldisplays];
var plane = new p2.Plane();
_this.planeBody = new p2.Body({ position: [engine.gameStage.width / 2, engine.gameStage.height - 100] });
_this.planeBody.angle = Math.PI;
_this.planeBody.addShape(plane);
_this.world.addBody(_this.planeBody);
_this.plane = _this.createPlane();
_this.planeBody.displays = [_this.plane];
_this.addEventListener(engine.Event.ENTER_FRAME, _this.onEnterFrame, _this);
return _this;
}
GameView.prototype.onEnterFrame = function () {
this.world.step(60 / 1000);
var len = this.world.bodies.length;
for (var i = 0; i < len; i++) {
var body = this.world.bodies[i];
var display = body.displays[0];
display.x = body.position[0];
display.y = body.position[1];
display.rotation = body.angle * 180 / Math.PI;
}
};
GameView.prototype.createBox = function () {
var sp = new engine.Shape();
sp.beginFill(0x0000ff);
sp.drawRect(0, 0, 50, 50);
sp.endFill();
return sp;
};
GameView.prototype.createPlane = function () {
var sp = new engine.Shape();
sp.beginFill(0x0000ff, 1);
sp.moveTo(0, 0);
sp.lineTo(engine.gameStage.width, 0);
sp.anchorX = sp.width / 2;
sp.anchorY = sp.height / 2;
this.addChild(sp);
return sp;
};
GameView.prototype.createCircle = function () {
var sp = new engine.Shape();
sp.beginFill(0xff0000, 0.7);
sp.drawCircle(200, 150, 60);
sp.endFill();
sp.anchorX = sp.width / 2;
sp.anchorY = sp.height / 2;
return sp;
};
GameView.prototype.start = function () {
console.log(this.world);
};
GameView.prototype.stop = function () { };
GameView.prototype.addEvent = function () { };
return GameView;
}(engine.Container));
var props = {};
function prepareProps() {
var metaProps = getProps();
engine.injectProp(props, metaProps);
}
function injectProps(p) {
engine.injectProp(props, p);
}
//# sourceMappingURL=props.js.map
var GameWrapper = (function (_super) {
tslib.__extends(GameWrapper, _super);
function GameWrapper() {
var _this = _super.call(this) || this;
engine.globalEvent.addEventListener('game-start', _this.start, _this);
engine.globalEvent.addEventListener('game-stop', _this.stop, _this);
var gameView = _this._gameView = new GameView();
_this.addChild(gameView);
return _this;
}
GameWrapper.prototype.start = function (event) {
injectProps(event.data);
this._gameView.start();
};
GameWrapper.prototype.stop = function (event) {
this._gameView.stop();
};
return GameWrapper;
}(engine.Container));
//# sourceMappingURL=GameWrapper.js.map
function index (props) {
prepareProps();
injectProps(props);
var instance = new GameWrapper();
return instance;
}
//# sourceMappingURL=index.js.map
return index;
})));
//# sourceMappingURL=main.js.map
\ No newline at end of file
This diff is collapsed.
/**
* Created by rockyl on 2020-01-21.
*/
let customModuleProps = {
};
{
"name": "拼图",
"desc": "拼图模块1.0",
"props": {
"OFFSET_X": {
"alias": "OFFSET_X",
"type": "number",
"default": 0
},
"OFFSET_Y": {
"alias": "OFFSET_Y",
"type": "number",
"default": 0
},
"GAME_TIME": {
"alias": "游戏时间",
"type": "number",
"default": 20
},
"moistPercent": {
"alias": "湿润度",
"type": "number",
"default": 0
}
},
"assets": [
{
"name": "背景",
"url": "//yun.duiba.com.cn/aurora/assets/b7708649be2270379bd764e25ee2e783a7d49f7a.jpg",
"uuid": "a880ee6b-c6d1-4d8f-8734-367f368a1803",
"ext": ".jpg"
},
{
"name": "篮板",
"url": "//yun.duiba.com.cn/aurora/assets/13fd42607d6a79c9a8d0d053962d926fa45fa0c9.png",
"uuid": "a1c6f4d9-8f9a-4267-b701-d2a7e9ff5b1b",
"ext": ".png"
},
{
"name": "球网前",
"url": "//yun.duiba.com.cn/aurora/assets/6c94fab92bc10e8716a4d90666b96d73603b8e59.png",
"uuid": "882618a9-2cc9-498e-a764-268c6cfe6c99",
"ext": ".png"
},
{
"name": "球网后",
"url": "//yun.duiba.com.cn/aurora/assets/2a3596dd0291a20fcee55445752dc38634074c59.png",
"uuid": "0680dba9-757b-443b-8d0f-0d5811254c7d",
"ext": ".png"
},
{
"name": "篮球",
"url": "//yun.duiba.com.cn/aurora/assets/3dc11f2d91659b7e7e1d06a9853cbc9f818e1ea2.png",
"uuid": "270bbac6-b59e-4692-80c9-a95aa0b03c17",
"ext": ".png"
}
],
"events": {
"in": {
"game-reset":{
"alias": "重置"
},
"game-start": {
"alias": "开始",
"data": {
"picUrl":"图片路径",
"blockUrl":"blockUrl",
"GAME_TIME":"每局的游戏时间",
"MAX_ROW":"行",
"MAX_COL":"列",
"W":"宽",
"H":"高",
"GAP":"图片间隙",
"OFFSET_X":"OFFSET_X",
"OFFSET_Y":"OFFSET_Y"
}
},
"game-stop": {
"alias": "停止"
}
},
"out": {
"cloud-time-update": {
"alias": "倒计时更新",
"data": {
"time":"剩余时间"
}
},
"cloud-game-fail": {
"alias": "游戏结束",
"data": {
"reason": "结束原因(1:时间到了)"
}
},
"cloud-game-success": {
"alias": "游戏成功",
"data": {
"time": "游戏消耗时间"
}
}
}
}
}
\ No newline at end of file
import {getTextureByName} from './utils'
export default class BasketBoard extends engine.Container{
board:engine.Sprite = new engine.Sprite(getTextureByName('篮板'));
netFront:engine.Sprite = new engine.Sprite(getTextureByName('球网前'));
netBack:engine.Sprite = new engine.Sprite(getTextureByName('球网后'));
// 篮筐传感,圆环
private config = {
boardBody:{
x:0,
y:0,
width:0.3,
height:2
},
insidePointBody: {
x: 15,
y: 65,
radius: 0.07
},
outsidePointBody: {
x: 180,
y: 65,
radius: 0.05
},
upSensorBody: {
x: 100,
y: 65,
radius: 0.05
},
downSensorBody: {
x: 100,
y: 65 + 80,
radius: 0.05
}
}
constructor(){
super();
this.addChild(this.board);
// 椭圆
let shape = new engine.Shape();
shape.beginFill(0xff0000,0.5);
shape.drawEllipse(50,150,200,80);
shape.endFill();
this.board.addChild(shape)
}
setPosition(x,y){
this.x = x;
this.y = y;
}
}
\ No newline at end of file
export default class Basketball extends engine.Container{
ball:engine.Shape
gravity = -5;
constructor(){
super()
this.ball = new engine.Shape();
this.ball.beginFill(0x0000ff,0.7);
this.ball.drawCircle(0,0,60);
this.ball.endFill();
this.addChild(this.ball);
}
initPos(x,y){
this.x = x;
this.y = y;
}
updatePos(){
}
}
\ No newline at end of file
import { getTextureByName, getTexture } from "./utils";
import BasketBoard from "./basketBoard";
import Basketball from "./Basketball";
export default class GameView extends engine.Container {
private world:p2.World;
private boxBody:p2.Body;
private planeBody:p2.Body;
private basketball:p2.Body;
private ball:engine.Sprite;
private plane:engine.Sprite;
basketBoard: BasketBoard = new BasketBoard();
private pool = {};
private horizontal = [74, 676]; //二值
private verticalArea = [200, 600]; //范围
private verticalInit = 462 - 45;
private positionInitBall = {
x: 551,
y: 805,
};
private vertical = this.verticalInit;
private isRight = false;
private saleX = this.isRight ? 1 : -1;
private config = {
net: {
x: 9.5,
y: 19 + 45,
},
insidePointBody: {
x: 15,
y: 65,
radius: 0.07,
},
outsidePointBody: {
x: 180,
y: 65,
radius: 0.05,
},
boardBody: {
x: 0,
y: 0,
// length: 2,
// radius: 0.1,
width: 0.3,
height: 2,
},
upSensorBody: {
x: 100,
y: 65,
radius: 0.05,
},
downSensorBody: {
x: 100,
y: 65 + 80,
radius: 0.05,
},
};
private view;
// private basketball;
private direction;
private toRo = 180 / Math.PI;
private loopMark = false;
private guideMark = false;
private ballAddSpeedX = 1.2;
private ballAddSpeedY = 5.3;
private gravity = -5;
private stepSpeed = [0.5, 3.5]; //3.5正常速度,2慢速播放
private detaTimeEf = this.stepSpeed[1];
private ballSpeedLimitX = 3;
private planeHeight = 1100;
private brokeMark = false;
private doubleHit = 0;
private timeLimit = window["timeLimit"] ? window["timeLimit"] : 5;
private timeMark = false;
private timeCount = this.timeLimit;
private timeSpeed = 1 / 60;
private clickMark = false;
constructor() {
super();
this.once(engine.Event.ADDED_TO_STAGE, this.start, this);
var p2 = window["p2"];
// material
var materialBall = new p2.Material(1); //参数id:number
var materialPoint = new p2.Material(2);
var materialBoard = new p2.Material(2);
var materialPlane = new p2.Material(2);
// 不同material碰撞系数
var contactMaterialBallPoint = new p2.ContactMaterial(
materialBall,
materialPoint,
{
friction: 0.3,
restitution: 0.5,
}
);
var contactMaterialBallBoard = new p2.ContactMaterial(
materialBall,
materialBoard,
{
friction: 0.3,
restitution: 0.5,
}
);
var contactMaterialBallPlane = new p2.ContactMaterial(
materialBall,
materialPlane,
{
friction: 0.3,
restitution: 0.7,
}
);
this.world = new p2.World();
this.world.sleepMode = p2.World.BODY_SLEEPING;
this.world.gravity = [0,10];
// this.world.gravity = [0,-5];
//创建box
// var box:p2.Box = new p2.Box({width:100, height:100});
var box:p2.Box = new p2.Box({width:this.config.boardBody.width, height:this.config.boardBody.height,material:materialBoard});
// this.boxBody = new p2.Body({mass:10, angularVelocity:1, position:[200,200]});
this.boxBody = new p2.Body({mass:0, type:p2.Body.STATIC, position:[20,200]});
this.boxBody.addShape(box);
// 添加图片
let display = new engine.Texture(getTextureByName('篮板'));
let displays = new engine.Sprite(display)
this.addChild(displays)
this.boxBody.displays = [displays];
this.world.addBody(this.boxBody);
// 设置摩擦和回弹系数
this.world.defaultContactMaterial.friction = 0.3;
this.world.defaultContactMaterial.restitution = 0.6;
this.world.setGlobalStiffness(1e5);
this.world.addContactMaterial(contactMaterialBallPoint);
this.world.addContactMaterial(contactMaterialBallBoard);
this.world.addContactMaterial(contactMaterialBallPlane);
// 球体
var ball = new p2.Circle({radius:60});
this.basketball = new p2.Body({
mass:0,
position:[300,250],
velocity:[-40,0],
// type:p2.Body.DYNAMIC,
material:materialBall
})
this.basketball.addShape(ball);
this.world.addBody(this.basketball);
// this.ball = this.createCircle();
let balldisplay = new engine.Texture(getTextureByName('篮球'));
let balldisplays = new engine.Sprite(balldisplay);
this.addChild(balldisplays)
this.basketball.displays = [balldisplays];
//创建plane Plane shape class. The plane is facing in the Y direction.
var plane:p2.Plane = new p2.Plane();
this.planeBody = new p2.Body({position:[engine.gameStage.width/2, engine.gameStage.height - 100]}); //GameConst.stage保存全局静态变量stage
this.planeBody.angle = Math.PI;
this.planeBody.addShape(plane);
this.world.addBody(this.planeBody);
this.plane = this.createPlane();
this.planeBody.displays = [this.plane];
//每帧更新
this.addEventListener(engine.Event.ENTER_FRAME, this.onEnterFrame, this);
}
private onEnterFrame(){
//更新物理世界
this.world.step(60/1000);
var len:number = this.world.bodies.length;
for(var i: number = 0;i < len;i++) {
var body: p2.Body = this.world.bodies[i];
var display: engine.DisplayObject = body.displays[0];
display.x = body.position[0]; //同步刚体和egret显示对象的位置和旋转角度
display.y = body.position[1];
display.rotation = body.angle * 180 / Math.PI;
}
}
private createBox(){
// var sp:engine.Sprite = new engine.Sprite();
var sp = new engine.Shape();
sp.beginFill(0x0000ff);
sp.drawRect(0,0,50,50);
sp.endFill();
// sp.anchorX = sp.width/2;
// sp.anchorY = sp.height/2;
return sp;
}
private createPlane(){
// var sp:engine.Sprite = new engine.Sprite();
var sp = new engine.Shape();
// sp.lineStyle(10, 0x00ff00);
sp.beginFill(0x0000ff,1)
sp.moveTo(0, 0);
sp.lineTo(engine.gameStage.width,0);
sp.anchorX = sp.width/2;
sp.anchorY = sp.height/2;
this.addChild(sp);
return sp;
}
private createCircle(){
var sp = new engine.Shape();
sp.beginFill(0xff0000,0.7);
sp.drawCircle(200,150,60);
sp.endFill();
sp.anchorX = sp.width/2;
sp.anchorY = sp.height/2;
return sp;
}
start() {
// let gameBg = new engine.Sprite(
// getTexture("a880ee6b-c6d1-4d8f-8734-367f368a1803")
// );
// this.addChild(gameBg);
// this.createWorld()
// this.createPlane();
console.log(this.world)
// this.addChild(this.world)
/* var fixedTimeStep = 1 / 60; // seconds
var maxSubSteps = 10; // Max sub steps to catch up with the wall clock
var lastTime;
// Animation loop
function animate(time) {
requestAnimationFrame(animate);
var deltaTime = lastTime ? (time - lastTime) / 1000 : 0;
this.world.step(fixedTimeStep, deltaTime, maxSubSteps);
// Render the circle at the current interpolated position
// renderCircleAtPosition(circleBody.interpolatedPosition);
lastTime = time;
}
// Start the animation loop
requestAnimationFrame(animate); */
// this.basketBoard.setPosition(0,100);
// this.addChild(this.basketBoard)
// console.log('1')
// this.basketball.initPos(400,200);
// this.addChild(this.basketball);
}
stop() {}
addEvent() {}
}
import GameView from "./GameView";
import { injectProps } from "../props";
export class GameWrapper extends engine.Container {
// private _status;
private _gameView: GameView;
constructor() {
super();
engine.globalEvent.addEventListener('game-start', this.start, this);
engine.globalEvent.addEventListener('game-stop', this.stop, this);
//创建实例
let gameView = this._gameView = new GameView();
this.addChild(gameView);
}
start(event: engine.Event) {
injectProps(event.data);
// this._status = 1;
this._gameView.start();
}
stop(event: engine.Event) {
this._gameView.stop();
}
// reset(event:engine.Event){
// this._gameView.reset();
// }
}
/**
* Created by rockyl on 2020-01-21.
*/
export function getTexture(uuid) {
return engine.Texture.from(getAssetByUUID(uuid).uuid);
}
export function getTextureByName(name) {
return getTexture(engine.getAssetByName(name).uuid);
}
export function playSound(name) {
engine.playSound(engine.getAssetByName(name).uuid, {keep: true});
}
export function createSvga(name, anchorName?) {
let inst = new svga.Svga();
inst.source = 'asset://' + engine.getAssetByName(name).uuid;
return inst;
}
export function getIndexFromRC(row,col,maxCol){
let index;
index = row * maxCol + col ;
return index
}
export function getRandomArray(array){
array.sort(function() {
return .5 - Math.random();
});
}
\ No newline at end of file
import {GameWrapper} from "./game/GameWrapper";
import {injectProps, prepareProps} from "./props";
export default function (props) {
prepareProps();
injectProps(props);
let instance = new GameWrapper();
return instance;
}
This diff is collapsed.
export let props: any = {};
export function prepareProps() {
let metaProps = getProps();
engine.injectProp(props, metaProps);
}
export function injectProps(p) {
engine.injectProp(props, p);
}
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