GameEngine2D

Reply

Member

Member
nautilusnsk
Posts: 4
Registered: ‎28-08-2012
Message 1 of 6 (235 Views)
Accepted Solution

Removing objects?

Hi!

I'm new in C# and in Playstation Mobile. I know that i can add physic object to world like this:

 

sceneBodies[numBody] = new PhysicsBody(sceneShapes[0], 1.0f);

numBody++;

 

But how can I remove an object from the physic world?

 

 

Please use plain text.

Re: Removing objects?

Hello,

 

I think that frequent insertion and deletion of object may decrease the simulation performance.

( It requires re-order of objects including joints)


Object is ignored when it is put outside of the simulation area until the scene is changed.

TutorialScene/SimulationAreaScene.cs shows how the simulation area works.

 

When you change the scene,  you can construct your scene again from the scratch.

 

Thanks,

 

Please use plain text.

Re: Removing objects?

Hi:

 

Use sceneBodies[numBody].clear(); and then sceneBodies[numBody] = null; The GC will take care of memory.

 

cheers,

Please use plain text.

Member

Member
nautilusnsk
Posts: 4
Registered: ‎28-08-2012
Message 4 of 6 (210 Views)

Re: Removing objects?

Thank you for the answers.

But my game uses physics engine and supposes deletion of object. When some object connected by joint is removed it should have adequate behaviour.

 

I tried to use a solution from AlexMcDev.  It works, but as I understand I should watch that PhysicsBody elements in the sceneBodies array were located one by one. I mean there shouldn't be null in the 2-nd index if we have 1-st and 3-rd.

Please use plain text.

Re: Removing objects?

If you're removing a body from the middle of the array, do as AlexMcDev says, but then shift the following ones down by one each

 

sceneBodies[numBody].clear();
sceneBodies[numBody] = null;

for ( var body= numBody; body < totalNumberOfBodies; body++)
{
	if( (body+ 1) < totalNumberOfBodies)
{
		sceneBodies[ body ] = sceneBodies[ body + 1 ];
	}
	else
	{
		sceneBodies[ body].Clear();
		sceneBodies[body] = null;
}

 

Please use plain text.

Re: Removing objects?

Hi:

 

Sophie_89_2 it's right if you want to maintain the coherence in the array you must reorder it. I'm not sure because I'm not using the PhysicsEngine but you could try some kind of List node structure to avoid reordering it but the access time is slower than index array.

 

Cheers,

Please use plain text.
Announcements

Welcome to the PlayStation Mobile Developer Forums


This is a community for the discussion of technical topics with other developers and SCE engineers. Posting ideas/requests are also appreciated. Join the discussion!

PlayStation®Mobile開発者フォーラムでは世界中の開発者の皆様と一緒に、議論や情報交換が可能です。SCEも議論に参加し、皆様の開発をサポートします。アイデアやリクエストも大歓迎です。ぜひご参加ください。

PSM Developer Registration (for free) on PSM DevPortal is required to post on the forum.
Please sign out then sign in again to the forum and PSM DevPortal after you have completed the registration.

フォーラムへ投稿をするにはPSM DevPortalへの登録(無料)が必要です。
登録後はフォーラムと PSM DevPortalを一度ログアウトし、再度ログインしてください。