It’s show how your object moving,Collision Rectangle,Performance Graph,Joint….
Therefore, we must need to use it ,Farseer Physics Engine support Debug View,so we need to use it to your project.
at previouse article:
Farseer Physis Engine- Tutorial:Basic.1
i already make it work.That’s begine how to use debugview:
1.Import file to LibraryProect:
In Offical Example. There are DebugView XNA Library Proect.
At you soluation Project,
mouse right click –>add project-> Choose Xna LibraryProject and Named:DebugView XNA
Copy offical Sample’s file call”DebugViewXNA.cs,PrimitiveBatch.cs”
to your DebugView XNA.
add Reference ‘Farsser Physics XNA’
then Compiler & fine.
2. add reference to your main project
Add reference ‘’ DebugView XNA” to your project.
3.Add code to your main screen class
using FarseerPhysics.DebugViews; //declare debug class protected DebugViewXNA DebugView = null;
At LoadContent Method:
public override void LoadContent() { if (DebugView == null) { //Give your world to debugView DebugView = new DebugViewXNA(world); //DebugView have many Property you can add DebugView.RemoveFlags(DebugViewFlags.Shape); DebugView.RemoveFlags(DebugViewFlags.Joint); DebugView.DefaultShapeColor = Color.LightPink; DebugView.SleepingShapeColor = Color.MediumPurple; //add your graphicsDevice & your ContentManager DebugView.LoadContent(GraphicsDevice , content); } }
also add your input to make it Keys work
public void InputHandle() { //Set your keys what your like if (Key press XX) { EnableOrDisableFlag(DebugViewFlags.DebugPanel); EnableOrDisableFlag(DebugViewFlags.PerformanceGraph); ... //also you can see there are many //property you can set //see the sample file "PhysicsGameScreen.cs" } }
and make EnaleOrDisableFlag stub:
private void EnableOrDisableFlag(DebugViewFlags flag) { if((DebugView.Flags & flag) == flag) { DebugView.RemoveFlags(flag); } else { DebugView.AppendFlags(flag); } }
Finally dont forget to Draw!
public override void Draw() { ... //we just declare two variable //for Temporary //at your gameplay you may //need to shift your camera Matrix view = Matrix.Identity; Matrix projection = Matrix.Identity; // that ready see result DebugView.RenderDebugData(ref projection , ref view); ... }
and ready see result.
No comments:
Post a Comment