on 28-08-2012 10:33 AM
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?
Solved! Go to Solution.
on 28-08-2012 02:23 PM
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,
on 28-08-2012 03:11 PM
Hi:
Use sceneBodies[numBody].clear(); and then sceneBodies[numBody] = null; The GC will take care of memory.
cheers,
on 29-08-2012 12:05 PM
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.
on 29-08-2012 12:16 PM
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;
}
}
on 29-08-2012 03:10 PM
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,
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を一度ログアウトし、再度ログインしてください。


Website ©2013 Sony Computer Entertainment Europe
All content, game titles, trade names and/or trade dress, trademarks, artwork and associated imagery are trademarks and/or copyright material of their respective owners. All rights reserved. [more info]
%%http://community.eu.playstation.com/t5/Announcements/Beta-Trial-Information/td-p/11386362
best_shooter.png%%http://community.eu.playstation.com/t5/Announcements/Introducing-Best-of-PlayStation/td-p/13741979
best_driver.png%%http://community.eu.playstation.com/t5/Announcements/Introducing-Best-of-PlayStation/td-p/13741979
best_performer.png%%http://community.eu.playstation.com/t5/Announcements/Introducing-Best-of-PlayStation/td-p/13741979
best_footballer.png%%http://community.eu.playstation.com/t5/Announcements/Introducing-Best-of-PlayStation/td-p/13741979
best_fighter.png%%http://community.eu.playstation.com/t5/Announcements/Introducing-Best-of-PlayStation/td-p/13741979
best_creator.png%%http://community.eu.playstation.com/t5/Announcements/Introducing-Best-of-PlayStation/td-p/13741979
best_action_player.png%%http://community.eu.playstation.com/t5/Announcements/Introducing-Best-of-PlayStation/td-p/13741979
dev2.png%%http://community.eu.playstation.com/t5/Website-and-Forum-Help-Feedback/Producer-and-Developer-Ranks/td-p/18407352
trophy.gif%%http://community.eu.playstation.com/t5/Website-and-Forum-Help-Feedback/The-Community-Awards-FAQ/td-p/18407096
PSlogoSM.png%%http://community.eu.playstation.com/t5/Website-and-Forum-Help-Feedback/Online-Support-Coordinator-rank/td-p/18414870