当前位置:网站首页>Egret P2 pit encountered by physical engine (1)
Egret P2 pit encountered by physical engine (1)
2022-06-30 06:59:00 【Zmmm Jun】
TypeError [ERR_INVALID_ARG_TYPE]: The "to" argument must be of type string. Received type object
at validateString (internal/validators.js:125:11)
at Object.relative (path.js:493:5)
at C:\Users\mi\AppData\Roaming\EgretLauncher\download\EgretCompiler\@egret\egret-webpack-bundler\lib\egretproject\data.js:149:34
at Array.map (<anonymous>)
at EgretProjectData.getModulesConfig (C:\Users\mi\AppData\Roaming\EgretLauncher\download\EgretCompiler\@egret\egret-webpack-bundler\lib\egretproject\data.js:145:51)
at Object.getLibsFileList (C:\Users\mi\AppData\Roaming\EgretLauncher\download\EgretCompiler\@egret\egret-webpack-bundler\lib\egretproject\index.js:8:24)
at EgretWebpackBundler.startDevServer (C:\Users\mi\AppData\Roaming\EgretLauncher\download\EgretCompiler\@egret\egret-webpack-bundler\lib\index.js:47:38)
at C:\Users\mi\Documents\EgretProjects\keli_go\scripts\plugins\webpack-plugin.ts:59:21
at new Promise (<anonymous>)
Cause analysis :
Generally, there is a problem with the path , Not configured correctly p2 Specific file path of the package **,to Input parameters receive object parameters
Solution :
Need to be in egretProperties.json The file configuration is specific path route , As follows : take physics.d.ts/physics.js/physics.min.js Put it in root directory /../physics Under the table of contents
And then egretProperties.json Add configuration item
{ "name":"physics", "path":"../physics" }
After modifying the configuration file and address, the compiler will not report an error , But in the browser create p2 Objects will still not be found p2 The problem with this object
Main.ts:89 Uncaught (in promise) ReferenceError: p2 is not defined at HelloWorld../src/Main.ts.HelloWorld.createWorld (Main.ts:89:22) at HelloWorld.<anonymous> (Main.ts:24:10) at step (main.js:80:19) at Object.next (main.js:61:49) at fulfilled (main.js:51:54)Solution :
Need to use `egret` Self contained `wing` The editor finds plug-in unit -Egret Project tools - Build engine Click to compile , After the compilation , Open the project again [ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-psPeBIZO-1644245149474)(9e3c157f63630e22e7e4397976151e41.png)] Or use code
egret build -eTry manual compilationThe symbol of successful compilation is [ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-PhCjBywC-1644245149480)(5bbf974a7f99351d79a4eff9391377c4.png)]

stay
libs/modules/There are compiled under the pathphysicsLibrary file directorywrold,plane( Horizon ), Objects have been set up and added to world in , But it doesn't show the pattern
[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-CIyCD3nt-1644245149483)(c296f933249546cf71c8cb00c2a9af08.png)]

Possible causes : No maps are bound to the objects in the relevant physics engine , Bind map through ,
p2.BodyObject'sdisplaysProperty to bind , Examplethis.display = new egret.Shape() this.display.x = 100 this.display.graphics.beginFill(0xff0000,1) this.display.graphics.drawCircle(0,0,(<p2.Box>boxShape).width) this.display.graphics.endFill() // this.display.width = (<p2.Box>bfoxShape).width // this.display.height = (<p2.Box>boxShape).height boxBody.displays = [this.display]After binding the map , You can see... In the physics engine
bodyRigid body objects also have corresponding mapsThe rigid body sets the material to STATIC, The collision of objects can still pass through the surface of objects
[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-DtOAIhqq-1644245149491)(89c0654d2e24bef4011e2aeeac1d8528.gif)]

The properties of the ground rigid body initialization are as follows
new p2.Body({
type:p2.Body.STATIC,
position:[0,stageHeight -100]
})
The properties of sphere rigid body initialization are as follows
new p2.Body({ mass: 1, position: [200, 200], angularVelocity: 1})
Here the rigid body type There are three types :
Dynamic : dynamic , Dynamic Type rigid bodies can interact with any type of rigid body , Can be moved .
STATIC: static state ,Static Type rigid bodies cannot be moved , But it can be done with dynamic Type rigid body interaction .
Kinematic: Dynamic rigid bodies ,Kinematic Type rigid bodies control by setting the speed , Others are similar to Static Rigid bodies are the same .
To be reasonable, here we set up STATIC It should not be worn out when it collides with objects
The first question is whether the sphere has no rigid body , Put the sphere's
typeAlso set toSTATICHave a try....emmm Find yourself mentally retarded , I just said
STATICType cannot be moved , Here's the picture , Not at all[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-WUd416oh-1644245149496)(e0c3c8afe4ec9ea01301f333d5355e0c.png)]

Doubt the sphere
shapeThere is a problem with the shape , The current setup is like thisvar boxShape:p2.Shape = new p2.Box({width:20,height:20})Not solved yet , It's a little late today , Ready for a break
world and Horizon , The balls are all set , Or how to make the physics engine move
[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-UtgJ15jf-1644245149500)(332c851fec7c82243b9fe45404bb6046.png)]

There are several possible situations
- Set the... Of the rigid body
typeTypes arestatic, A static rigid body cannot have displacement - There is no tone
world.step()Step function , Make the physical world follow the formula track , Use timer , Or inegretFrame refresh event bindingstepfunction , And refresh in the functionegret View location// Frame event , Step function private update() { this.world.step(1); var l = this.world.bodies.length; for (var i:number = 0; i < l; i++) { var boxBody:p2.Body = this.world.bodies[i]; var box:egret.DisplayObject = boxBody.displays[0]; if (box) { // Assign the coordinates and angles of the rigid body to the display object box.x = boxBody.position[0]; box.y = boxBody.position[1]; // If the current state of the rigid body is sleep , The picture alpha Set to 0.5, Otherwise 1 if (boxBody.sleepState == p2.Body.SLEEPING) { box.alpha = 0.5; } else { box.alpha = 1; } } } } Main function , Monitoring events this.addEventListener(egret.Event.ENTER_FRAME,this.update,this); - The object is not set
massWeight attribute , Or there is a problem with the view binding
边栏推荐
- Basic fragmentary thoughts
- ftplib+ tqdm 上传下载进度条
- Records of problems solved (continuously updated)
- First experience of Galaxy Kirin
- Porting RT thread to s5p4418 (V): thread communication
- 【模糊神经网络】基于模糊神经网络的移动机器人路径规划
- RT thread Kernel Implementation (II): critical area, object container
- 免实名域名是什么意思?
- RT thread Kernel Implementation (IV): multi priority
- Cluster distributed
猜你喜欢

相关数据库问题提问。

Introduction to neural networks

Steps for formulating class or file templates in idea

Assembly language learning I (with stack co process, 32-bit registers and related instructions, to be continued 06/29)

Win10踩坑-开机0xc0000225

First line of code (Third Edition) learning notes

Google Earth engine (GEE) - Murray global tidal wetland change V1 (1999-2019) data set

1.7 - CPU performance indicators
![[docsify basic use]](/img/9d/db689f5f13708f3e241474afeca1d0.png)
[docsify basic use]
![[my advanced OpenGL learning journey] about the access methods of vector and matrix classification of OpenGL shaders: xyzw/rgba/stpq and array subscripts](/img/ed/76db436ab5e35fba742dc287402fe3.png)
[my advanced OpenGL learning journey] about the access methods of vector and matrix classification of OpenGL shaders: xyzw/rgba/stpq and array subscripts
随机推荐
Mysql5.7 compressed version installation tutorial
Rising posture series: fancy debugging information
oracle
Cluster distributed
Assembly language learning I (with stack co process, 32-bit registers and related instructions, to be continued 06/29)
Cmake post makefile:32: * * * missing separator Stop.
【json-tutorial】第一章学习笔记
RT thread Kernel Implementation (V): timer
MySQL中的InnoDB引擎
leetcode:98. Validate binary search tree
RT thread Kernel Implementation (I): threads and scheduling
Which securities company is good for opening a mobile account? Also, is it safe to open an account online?
明天!“移动云杯”大赛空宣会开播!
Jingwei Hengrun won the 10ppm quality award of paccar group again
Linu基础-分区规划与使用
MySQL Optimization: from more than ten seconds to 300 milliseconds
RT thread migration to s5p4418 (I): scheduler
The 40g high-efficiency cloud disk purchased by Alibaba cloud is only 20g attached
【Hot100】15. 三数之和
Google Earth engine (GEE) - Murray global tidal wetland change V1 (1999-2019) data set