rapier2d示例
This commit is contained in:
9
tools/flashfin-rapier2d/assets/fonts.meta
Normal file
9
tools/flashfin-rapier2d/assets/fonts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "1.2.0",
|
||||
"importer": "directory",
|
||||
"imported": true,
|
||||
"uuid": "6f5a343f-6383-4387-afc0-17b54ab0e2de",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
BIN
tools/flashfin-rapier2d/assets/fonts/pixelhanzi.ttf
(Stored with Git LFS)
Normal file
BIN
tools/flashfin-rapier2d/assets/fonts/pixelhanzi.ttf
(Stored with Git LFS)
Normal file
Binary file not shown.
12
tools/flashfin-rapier2d/assets/fonts/pixelhanzi.ttf.meta
Normal file
12
tools/flashfin-rapier2d/assets/fonts/pixelhanzi.ttf.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"ver": "1.0.1",
|
||||
"importer": "ttf-font",
|
||||
"imported": true,
|
||||
"uuid": "1cfbb169-e553-48b7-8741-55373a87f587",
|
||||
"files": [
|
||||
".json",
|
||||
"pixelhanzi.ttf"
|
||||
],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
9
tools/flashfin-rapier2d/assets/prefab.meta
Normal file
9
tools/flashfin-rapier2d/assets/prefab.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "1.2.0",
|
||||
"importer": "directory",
|
||||
"imported": true,
|
||||
"uuid": "236b5f6b-6868-436d-87da-90ff4fcd7d95",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
BIN
tools/flashfin-rapier2d/assets/prefab/ballitem.prefab
(Stored with Git LFS)
Normal file
BIN
tools/flashfin-rapier2d/assets/prefab/ballitem.prefab
(Stored with Git LFS)
Normal file
Binary file not shown.
13
tools/flashfin-rapier2d/assets/prefab/ballitem.prefab.meta
Normal file
13
tools/flashfin-rapier2d/assets/prefab/ballitem.prefab.meta
Normal file
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"ver": "1.1.50",
|
||||
"importer": "prefab",
|
||||
"imported": true,
|
||||
"uuid": "f011b380-7741-4c8d-ae17-76cf8a5fc011",
|
||||
"files": [
|
||||
".json"
|
||||
],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"syncNodeName": "ballitem"
|
||||
}
|
||||
}
|
||||
BIN
tools/flashfin-rapier2d/assets/prefab/testitem.prefab
(Stored with Git LFS)
Normal file
BIN
tools/flashfin-rapier2d/assets/prefab/testitem.prefab
(Stored with Git LFS)
Normal file
Binary file not shown.
13
tools/flashfin-rapier2d/assets/prefab/testitem.prefab.meta
Normal file
13
tools/flashfin-rapier2d/assets/prefab/testitem.prefab.meta
Normal file
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"ver": "1.1.50",
|
||||
"importer": "prefab",
|
||||
"imported": true,
|
||||
"uuid": "1f217bc3-f4c1-4c97-80cd-f92e92bebb09",
|
||||
"files": [
|
||||
".json"
|
||||
],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"syncNodeName": "testitem"
|
||||
}
|
||||
}
|
||||
BIN
tools/flashfin-rapier2d/assets/scene_box2d.scene
(Stored with Git LFS)
Normal file
BIN
tools/flashfin-rapier2d/assets/scene_box2d.scene
(Stored with Git LFS)
Normal file
Binary file not shown.
11
tools/flashfin-rapier2d/assets/scene_box2d.scene.meta
Normal file
11
tools/flashfin-rapier2d/assets/scene_box2d.scene.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"ver": "1.1.50",
|
||||
"importer": "scene",
|
||||
"imported": true,
|
||||
"uuid": "452ca018-6ac2-414a-966a-166c7c8f4c30",
|
||||
"files": [
|
||||
".json"
|
||||
],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
BIN
tools/flashfin-rapier2d/assets/scene_rapier2d.scene
(Stored with Git LFS)
Normal file
BIN
tools/flashfin-rapier2d/assets/scene_rapier2d.scene
(Stored with Git LFS)
Normal file
Binary file not shown.
1
tools/flashfin-rapier2d/assets/scene_rapier2d.scene.meta
Normal file
1
tools/flashfin-rapier2d/assets/scene_rapier2d.scene.meta
Normal file
@@ -0,0 +1 @@
|
||||
{"ver":"1.1.50","importer":"scene","imported":true,"uuid":"6773b206-616b-4cb6-9a1b-0182367abb1c","files":[".json"],"subMetas":{},"userData":{}}
|
||||
9
tools/flashfin-rapier2d/assets/scripts.meta
Normal file
9
tools/flashfin-rapier2d/assets/scripts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "1.2.0",
|
||||
"importer": "directory",
|
||||
"imported": true,
|
||||
"uuid": "fe6eee8d-b74e-4f57-be34-fb9bacca7f0f",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
49
tools/flashfin-rapier2d/assets/scripts/Clogger.ts
Normal file
49
tools/flashfin-rapier2d/assets/scripts/Clogger.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
|
||||
function padStart(value: string | number, length: number, padChar: string): string {
|
||||
let result = String(value);
|
||||
while (result.length < length) {
|
||||
result = padChar + result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
class Clogger {
|
||||
private prefix: string;
|
||||
|
||||
constructor(prefix: string = '') {
|
||||
this.prefix = prefix;
|
||||
}
|
||||
|
||||
// 将参数转换为字符串并输出到控制台
|
||||
private formatAndLog(...args: any[]): void {
|
||||
const now = new Date();
|
||||
const hours = padStart(now.getHours(), 2, '0');
|
||||
const minutes = padStart(now.getMinutes(), 2, '0');
|
||||
const seconds = padStart(now.getSeconds(), 2, '0');
|
||||
const milliseconds = padStart(now.getMilliseconds(), 3, '0');
|
||||
|
||||
const timestamp = `${hours}:${minutes}:${seconds}.${milliseconds}`;
|
||||
|
||||
console.log(
|
||||
this.prefix +'|'+ timestamp +'|'+
|
||||
args.map(arg => (typeof arg === 'object' ? JSON.stringify(arg) : String(arg))).join(' ')
|
||||
);
|
||||
}
|
||||
debug(...args: any[]): void {
|
||||
this.formatAndLog('DEBUG', ...args);
|
||||
}
|
||||
|
||||
log(...args: any[]): void {
|
||||
this.formatAndLog('LOG', ...args);
|
||||
}
|
||||
|
||||
warn(...args: any[]): void {
|
||||
this.formatAndLog('WARN', ...args);
|
||||
}
|
||||
|
||||
error(...args: any[]): void {
|
||||
this.formatAndLog('ERROR', ...args);
|
||||
}
|
||||
}
|
||||
|
||||
export const logger = new Clogger('SOIDA');
|
||||
9
tools/flashfin-rapier2d/assets/scripts/Clogger.ts.meta
Normal file
9
tools/flashfin-rapier2d/assets/scripts/Clogger.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "ff0e1b17-5af0-4e18-8357-b98382f3911c",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
100
tools/flashfin-rapier2d/assets/scripts/RapierDebugRenderer.ts
Normal file
100
tools/flashfin-rapier2d/assets/scripts/RapierDebugRenderer.ts
Normal file
@@ -0,0 +1,100 @@
|
||||
import { _decorator, Component, Graphics, Color } from 'cc';
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
// import RAPIER from '@dimforge/rapier2d';
|
||||
|
||||
export const RAPIER_PTM_RATIO:number = 32.0;
|
||||
|
||||
@ccclass('RapierDebugRenderer')
|
||||
export class RapierDebugRenderer extends Component {
|
||||
@property(Graphics)
|
||||
graphics: Graphics = null!;
|
||||
|
||||
// 可选:可调整的线宽
|
||||
@property
|
||||
lineWidth: number = 1.0;
|
||||
|
||||
// 可选:坐标缩放系数
|
||||
@property
|
||||
scale: number = RAPIER_PTM_RATIO;
|
||||
|
||||
@property
|
||||
onoff: boolean = false;
|
||||
|
||||
|
||||
private _world: any = null; // RAPIER.World 类型
|
||||
|
||||
/**
|
||||
* 设置物理世界引用
|
||||
* @param world RAPIER物理世界实例
|
||||
*/
|
||||
public setWorld(world: any) {
|
||||
this._world = world;
|
||||
}
|
||||
|
||||
/**
|
||||
* 在每帧更新中调用以渲染调试图形
|
||||
*/
|
||||
update() {
|
||||
if (!this._world || !this.graphics) return;
|
||||
|
||||
this.onoff && this.render(this._world);
|
||||
}
|
||||
|
||||
clear(){
|
||||
this.graphics&&this.graphics.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* 渲染物理世界的调试信息
|
||||
* @param world RAPIER物理世界
|
||||
*/
|
||||
render(world: any) {
|
||||
// 获取调试渲染数据
|
||||
const { vertices, colors } = world.debugRender();
|
||||
|
||||
// 清除之前的绘制内容
|
||||
this.graphics.clear();
|
||||
|
||||
// const g = this.graphics;
|
||||
// g.lineWidth = 10;
|
||||
// g.fillColor.fromHEX('#ff0000ff');
|
||||
// g.moveTo(-40, 0);
|
||||
// g.lineTo(0, -80);
|
||||
// g.lineTo(40, 0);
|
||||
// g.lineTo(0, 80);
|
||||
// g.close();
|
||||
// g.stroke();
|
||||
// g.fill();
|
||||
|
||||
// 遍历所有线段进行绘制
|
||||
for (let i = 0; i < vertices.length / 4; i++) {
|
||||
// 从颜色数组中获取当前线段的颜色
|
||||
const r = Math.floor(colors[i * 8] * 255); // 转换为 0-255 范围
|
||||
const g = Math.floor(colors[i * 8 + 1] * 255);
|
||||
const b = Math.floor(colors[i * 8 + 2] * 255);
|
||||
const a = colors[i * 8 + 3] * 255; // alpha 直接使用 0-255 范围
|
||||
|
||||
// 设置线条样式
|
||||
this.graphics.lineWidth = this.lineWidth;
|
||||
this.graphics.strokeColor = new Color(r, g, b, a);
|
||||
|
||||
// 获取线段的起点和终点坐标
|
||||
// 注意:Cocos Creator 使用左下角为原点的坐标系,y轴向上为正
|
||||
// 而 RAPIER 可能使用不同的坐标系,因此这里做适当调整
|
||||
|
||||
// 获取原始坐标
|
||||
let x1 = vertices[i * 4] * this.scale;
|
||||
let y1 = vertices[i * 4 + 1] * this.scale;
|
||||
let x2 = vertices[i * 4 + 2] * this.scale;
|
||||
let y2 = vertices[i * 4 + 3] * this.scale;
|
||||
|
||||
|
||||
// 执行绘制
|
||||
this.graphics.moveTo(x1, y1);
|
||||
this.graphics.lineTo(x2, y2);
|
||||
this.graphics.close();
|
||||
this.graphics.stroke();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "020358be-0b18-47a4-ad46-a6972ff0ed99",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
87
tools/flashfin-rapier2d/assets/scripts/SceneMain.ts
Normal file
87
tools/flashfin-rapier2d/assets/scripts/SceneMain.ts
Normal file
@@ -0,0 +1,87 @@
|
||||
import { _decorator, Color, Component, instantiate, Label, Node, Prefab, Sprite } from 'cc';
|
||||
import * as cc from 'cc';
|
||||
|
||||
import { logger } from './Clogger';
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass('SceneMain')
|
||||
export class SceneMain extends Component {
|
||||
|
||||
@property(Node)
|
||||
node_fps:Node|null = null;
|
||||
|
||||
@property(Node)
|
||||
node_counts:Node|null = null;
|
||||
|
||||
@property(Prefab)
|
||||
prefab_item:Prefab|null = null;
|
||||
|
||||
@property(Node)
|
||||
container_balls:Node|null = null;
|
||||
|
||||
@property(cc.Node)
|
||||
node_switchscene:cc.Node|null = null;
|
||||
|
||||
private _timeAccumulator: any;
|
||||
private _countAcc: any;
|
||||
|
||||
private _listBalls: Node[] = [];
|
||||
|
||||
protected onLoad(): void {
|
||||
logger.log('dballs onLoad');
|
||||
|
||||
let p = cc.PhysicsSystem2D.instance;
|
||||
p.positionIterations = 4;
|
||||
p.velocityIterations = 2;
|
||||
|
||||
}
|
||||
start() {
|
||||
logger.log('dballs start');
|
||||
|
||||
// let n= this.node.getChildByName('ballitem')
|
||||
// let r = n.getComponent(cc.CircleCollider2D).radius
|
||||
// logger.log('radius:', r);
|
||||
|
||||
this.node_switchscene.on('click', (b:cc.Button) => {
|
||||
cc.director.loadScene('scene_rapier2d');
|
||||
});
|
||||
}
|
||||
|
||||
update(dt: number) {
|
||||
if (!this._timeAccumulator) {
|
||||
this._timeAccumulator = 0;
|
||||
}
|
||||
this._timeAccumulator += dt;
|
||||
|
||||
if (this._timeAccumulator >= 0.1) {
|
||||
this.node_fps.getComponent(Label)!.string = `FPS: ${Math.floor(1 / dt)}`;
|
||||
this._timeAccumulator = 0;
|
||||
}
|
||||
|
||||
if(Math.floor(1 / dt) < 30){
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this._countAcc) {
|
||||
this._countAcc = 0;
|
||||
}
|
||||
// this._countAcc += 1;
|
||||
//每秒实例化添加5个node_item 到场景中,并且显示当前场景中的node_item数量
|
||||
// if (this._countAcc >= 60/60) {
|
||||
for (let i = 0; i < 4; i++) {
|
||||
let node = instantiate(this.prefab_item);
|
||||
node.getComponent(Sprite).color = new Color(Math.random()*255, Math.random()*255, Math.random()*255);
|
||||
this.container_balls.addChild(node);
|
||||
let x = (Math.random()*2-1)*cc.view.getVisibleSize().width/2;;
|
||||
node.setPosition(x, 400);
|
||||
this._listBalls.push(node);
|
||||
}
|
||||
this.node_counts.getComponent(Label)!.string = `BALLS: ${this._listBalls.length}`;
|
||||
this._countAcc = 0;
|
||||
// }
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
9
tools/flashfin-rapier2d/assets/scripts/SceneMain.ts.meta
Normal file
9
tools/flashfin-rapier2d/assets/scripts/SceneMain.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "22878c0e-0345-4a10-896a-6c1520d22df5",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
180
tools/flashfin-rapier2d/assets/scripts/SceneRapier2d.ts
Normal file
180
tools/flashfin-rapier2d/assets/scripts/SceneRapier2d.ts
Normal file
@@ -0,0 +1,180 @@
|
||||
import { _decorator, Color, Component, instantiate, Label, Node, Prefab, Sprite } from 'cc';
|
||||
import * as cc from 'cc';
|
||||
|
||||
import RAPIER, { IntegrationParameters } from '@dimforge/rapier2d-compat';
|
||||
import { RAPIER_PTM_RATIO, RapierDebugRenderer } from './RapierDebugRenderer';
|
||||
import { logger } from './Clogger';
|
||||
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass('SceneRapier2d')
|
||||
export class SceneRapier2d extends Component {
|
||||
|
||||
@property(Node)
|
||||
node_fps:Node|null = null;
|
||||
|
||||
@property(Node)
|
||||
node_counts:Node|null = null;
|
||||
|
||||
@property(Prefab)
|
||||
prefab_item:Prefab|null = null;
|
||||
|
||||
@property(Node)
|
||||
container_balls:Node|null = null;
|
||||
|
||||
@property(cc.Node)
|
||||
node_switch:cc.Node|null = null;
|
||||
|
||||
@property(cc.Node)
|
||||
node_switchscene:cc.Node|null = null;
|
||||
|
||||
|
||||
private _timeAccumulator: any;
|
||||
private _countAcc: any;
|
||||
|
||||
|
||||
private world: RAPIER.World;
|
||||
private gravity = new RAPIER.Vector2(0, -10);
|
||||
private _initComplete: boolean = false;
|
||||
private _rigidBody: RAPIER.RigidBody;
|
||||
private _debugRenderer: RapierDebugRenderer;
|
||||
|
||||
|
||||
//将一个node和一个RigidBody绑定
|
||||
private _mapNodeBalls: Map<Node, RAPIER.RigidBody> = new Map<Node, RAPIER.RigidBody>();
|
||||
|
||||
|
||||
protected async onLoad(): Promise<void> {
|
||||
logger.log('dballs onLoad');
|
||||
|
||||
RAPIER.init().then(() => {
|
||||
logger.log('RAPIER.init success');
|
||||
this._initComplete = true;
|
||||
// 创建物理世界
|
||||
this.world = new RAPIER.World(this.gravity);
|
||||
this.fillWorld();
|
||||
this._debugRenderer = this.getComponent(RapierDebugRenderer)!;
|
||||
this._debugRenderer.setWorld(this.world);
|
||||
|
||||
this.afterInit();
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
afterInit() {
|
||||
|
||||
this.node_switch.children[0]!.getComponent(Label).string = this._debugRenderer.onoff ? 'debug:ON' : 'debug:OFF';
|
||||
this.node_switch.on('click', (b:cc.Button) => {
|
||||
this._debugRenderer.onoff = !this._debugRenderer.onoff;
|
||||
this._debugRenderer.clear();
|
||||
b!.node.children[0]!.getComponent(Label).string = this._debugRenderer.onoff ? 'debug:ON' : 'debug:OFF';
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
start() {
|
||||
logger.log('dballs start');
|
||||
|
||||
|
||||
|
||||
this.node_switchscene.on('click', (b:cc.Button) => {
|
||||
cc.director.loadScene('scene_box2d');
|
||||
});
|
||||
|
||||
// this.schedule((dt:number)=>{
|
||||
// if(!this._initComplete){
|
||||
// return;
|
||||
// }
|
||||
|
||||
// this.world.step();
|
||||
|
||||
// this._mapNodeBalls.forEach((rigidBody, node)=>{
|
||||
// let position = rigidBody.translation();
|
||||
// node.setPosition(position.x*RAPIER_PTM_RATIO, position.y*RAPIER_PTM_RATIO);
|
||||
// node.active = true;
|
||||
// });
|
||||
|
||||
|
||||
// }, 1/60, cc.macro.REPEAT_FOREVER, 0);
|
||||
|
||||
}
|
||||
|
||||
|
||||
fillWorld(){
|
||||
let world = this.world;
|
||||
let viewSize = cc.view.getVisibleSize();
|
||||
let groundRigidBody = world.createRigidBody(new RAPIER.RigidBodyDesc(RAPIER.RigidBodyType.Fixed));
|
||||
world.createCollider(RAPIER.ColliderDesc.cuboid(viewSize.width/2, 0.5).setTranslation(0,-viewSize.height/(2*RAPIER_PTM_RATIO)).setRestitution(1).setFriction(0.0), groundRigidBody);
|
||||
|
||||
let groundRigidBody1 = world.createRigidBody(new RAPIER.RigidBodyDesc(RAPIER.RigidBodyType.Fixed));
|
||||
world.createCollider(RAPIER.ColliderDesc.cuboid(0.5,viewSize.height/2 ).setTranslation(-viewSize.width/(2*RAPIER_PTM_RATIO),0).setRestitution(1).setFriction(0.0), groundRigidBody1);
|
||||
|
||||
let groundRigidBody2 = world.createRigidBody(new RAPIER.RigidBodyDesc(RAPIER.RigidBodyType.Fixed));
|
||||
world.createCollider(RAPIER.ColliderDesc.cuboid(0.5,viewSize.height/2 ).setTranslation(viewSize.width/(2*RAPIER_PTM_RATIO),0).setRestitution(1).setFriction(0.0), groundRigidBody2);
|
||||
|
||||
// let rigidBody = world.createRigidBody(new RAPIER.RigidBodyDesc(RAPIER.RigidBodyType.Dynamic).setTranslation(0.0, 5.0).setLinearDamping(0).setAngularDamping(0));
|
||||
// let collider = world.createCollider(RAPIER.ColliderDesc.ball(0.5).setDensity(1.0).setRestitution(1).setFriction(0.0), rigidBody);
|
||||
// this._rigidBody = rigidBody;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
update(dt: number) {
|
||||
if (!this._timeAccumulator) {
|
||||
this._timeAccumulator = 0;
|
||||
}
|
||||
this._timeAccumulator += dt;
|
||||
|
||||
// if (this._timeAccumulator >= 0.1) {
|
||||
this.node_fps.getComponent(Label)!.string = `FPS: ${Math.floor(1 / dt)}`;
|
||||
// this._timeAccumulator = 0;
|
||||
// }
|
||||
|
||||
if(Math.floor(1 / dt) < 30){
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this._countAcc) {
|
||||
this._countAcc = 0;
|
||||
}
|
||||
|
||||
//物理系统同步
|
||||
if(!this._initComplete){
|
||||
return;
|
||||
}
|
||||
this.world.step();
|
||||
this._mapNodeBalls.forEach((rigidBody, node)=>{
|
||||
let position = rigidBody.translation();
|
||||
node.setPosition(position.x*RAPIER_PTM_RATIO, position.y*RAPIER_PTM_RATIO);
|
||||
node.active = true;
|
||||
});
|
||||
|
||||
|
||||
// this._countAcc += 1;
|
||||
// if (this._countAcc >= 60/60) {
|
||||
for (let i = 0; i < 4; i++) {
|
||||
let node = instantiate(this.prefab_item);
|
||||
node.getComponent(Sprite).color = new Color(Math.random()*255, Math.random()*255, Math.random()*255);
|
||||
node.active = false;
|
||||
this.container_balls.addChild(node);
|
||||
let x = (Math.random()*2-1)*cc.view.getVisibleSize().width/2;
|
||||
let y = 400;
|
||||
|
||||
let r = (node.getComponent(cc.UITransform).width-2)/2 ;
|
||||
let rigidBody = this.world.createRigidBody(new RAPIER.RigidBodyDesc(RAPIER.RigidBodyType.Dynamic).setTranslation(x/RAPIER_PTM_RATIO, y/RAPIER_PTM_RATIO).setLinearDamping(0).setAngularDamping(0).setCanSleep(false));
|
||||
this.world.createCollider(RAPIER.ColliderDesc.ball(r/RAPIER_PTM_RATIO).setDensity(1.0).setRestitution(0.5).setFriction(0.0), rigidBody);
|
||||
this._mapNodeBalls.set(node, rigidBody);
|
||||
// node.setPosition(x, 400);
|
||||
// this._listBalls.push(node);
|
||||
|
||||
}
|
||||
this.node_counts.getComponent(Label)!.string = `BALLS: ${this.container_balls.children.length}`;
|
||||
// this._countAcc = 0;
|
||||
// }
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
{"ver":"4.0.24","importer":"typescript","imported":true,"uuid":"188ce8c7-8772-4533-8d62-ad630ea294eb","files":[],"subMetas":{},"userData":{}}
|
||||
9
tools/flashfin-rapier2d/assets/textures.meta
Normal file
9
tools/flashfin-rapier2d/assets/textures.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "1.2.0",
|
||||
"importer": "directory",
|
||||
"imported": true,
|
||||
"uuid": "01530936-dd18-4bfd-8c4b-7cb2ce4e87ed",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
BIN
tools/flashfin-rapier2d/assets/textures/ball1.png
(Stored with Git LFS)
Normal file
BIN
tools/flashfin-rapier2d/assets/textures/ball1.png
(Stored with Git LFS)
Normal file
Binary file not shown.
134
tools/flashfin-rapier2d/assets/textures/ball1.png.meta
Normal file
134
tools/flashfin-rapier2d/assets/textures/ball1.png.meta
Normal file
@@ -0,0 +1,134 @@
|
||||
{
|
||||
"ver": "1.0.27",
|
||||
"importer": "image",
|
||||
"imported": true,
|
||||
"uuid": "cd9e5dce-f1bc-4320-acc4-4acd8bb105e7",
|
||||
"files": [
|
||||
".json",
|
||||
".png"
|
||||
],
|
||||
"subMetas": {
|
||||
"6c48a": {
|
||||
"importer": "texture",
|
||||
"uuid": "cd9e5dce-f1bc-4320-acc4-4acd8bb105e7@6c48a",
|
||||
"displayName": "ball1",
|
||||
"id": "6c48a",
|
||||
"name": "texture",
|
||||
"userData": {
|
||||
"wrapModeS": "clamp-to-edge",
|
||||
"wrapModeT": "clamp-to-edge",
|
||||
"minfilter": "linear",
|
||||
"magfilter": "linear",
|
||||
"mipfilter": "none",
|
||||
"anisotropy": 0,
|
||||
"isUuid": true,
|
||||
"imageUuidOrDatabaseUri": "cd9e5dce-f1bc-4320-acc4-4acd8bb105e7",
|
||||
"visible": false
|
||||
},
|
||||
"ver": "1.0.22",
|
||||
"imported": true,
|
||||
"files": [
|
||||
".json"
|
||||
],
|
||||
"subMetas": {}
|
||||
},
|
||||
"f9941": {
|
||||
"importer": "sprite-frame",
|
||||
"uuid": "cd9e5dce-f1bc-4320-acc4-4acd8bb105e7@f9941",
|
||||
"displayName": "ball1",
|
||||
"id": "f9941",
|
||||
"name": "spriteFrame",
|
||||
"userData": {
|
||||
"trimThreshold": 1,
|
||||
"rotated": false,
|
||||
"offsetX": 0,
|
||||
"offsetY": 0,
|
||||
"trimX": 0,
|
||||
"trimY": 0,
|
||||
"width": 70,
|
||||
"height": 70,
|
||||
"rawWidth": 70,
|
||||
"rawHeight": 70,
|
||||
"borderTop": 0,
|
||||
"borderBottom": 0,
|
||||
"borderLeft": 0,
|
||||
"borderRight": 0,
|
||||
"packable": true,
|
||||
"pixelsToUnit": 100,
|
||||
"pivotX": 0.5,
|
||||
"pivotY": 0.5,
|
||||
"meshType": 0,
|
||||
"vertices": {
|
||||
"rawPosition": [
|
||||
-35,
|
||||
-35,
|
||||
0,
|
||||
35,
|
||||
-35,
|
||||
0,
|
||||
-35,
|
||||
35,
|
||||
0,
|
||||
35,
|
||||
35,
|
||||
0
|
||||
],
|
||||
"indexes": [
|
||||
0,
|
||||
1,
|
||||
2,
|
||||
2,
|
||||
1,
|
||||
3
|
||||
],
|
||||
"uv": [
|
||||
0,
|
||||
70,
|
||||
70,
|
||||
70,
|
||||
0,
|
||||
0,
|
||||
70,
|
||||
0
|
||||
],
|
||||
"nuv": [
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
1,
|
||||
1
|
||||
],
|
||||
"minPos": [
|
||||
-35,
|
||||
-35,
|
||||
0
|
||||
],
|
||||
"maxPos": [
|
||||
35,
|
||||
35,
|
||||
0
|
||||
]
|
||||
},
|
||||
"isUuid": true,
|
||||
"imageUuidOrDatabaseUri": "cd9e5dce-f1bc-4320-acc4-4acd8bb105e7@6c48a",
|
||||
"atlasUuid": "",
|
||||
"trimType": "none"
|
||||
},
|
||||
"ver": "1.0.12",
|
||||
"imported": true,
|
||||
"files": [
|
||||
".json"
|
||||
],
|
||||
"subMetas": {}
|
||||
}
|
||||
},
|
||||
"userData": {
|
||||
"type": "sprite-frame",
|
||||
"hasAlpha": true,
|
||||
"fixAlphaTransparencyArtifacts": false,
|
||||
"redirect": "cd9e5dce-f1bc-4320-acc4-4acd8bb105e7@6c48a"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user