public override void LoadContent() { base.LoadContent(); if (World == null) return; RenderView = new RenderXNAHelper(World); RenderView.AppendFlags(DebugViewFlags.TexturedShape); RenderView.RemoveFlags(DebugViewFlags.Shape); RenderView.RemoveFlags(DebugViewFlags.Joint); //DebugView.AppendFlags(DebugViewFlags.PolygonPoints); RenderView.DefaultShapeColor = Color.White; RenderView.SleepingShapeColor = Color.LightGray; RenderView.LoadContent(ScreenManager.GraphicsDevice, ScreenManager.ContentManager); ScreenManager.Camera.ProjectionUpdated += UpdateScreen; // Loading may take a while... so prevent the game from "catching up" once we finished loading ScreenManager.Game.ResetElapsedTime(); }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); // TODO: use this.Content to load your game content here map = Content.Load<Map>("Maps\\Map01"); mSpriteTexture = Content.Load<Texture2D>("golfball"); MyTexture = Content.Load<Texture2D>("blank"); world = new World(new Vector2(0, 15.0f)); RenderHelper = new RenderXNAHelper(world); RenderHelper.AppendFlags(DebugViewFlags.TexturedShape); RenderHelper.RemoveFlags(DebugViewFlags.Shape); RenderHelper.DefaultShapeColor = Color.White; RenderHelper.SleepingShapeColor = Color.LightGray; RenderHelper.LoadContent(GraphicsDevice, Content); BoxBody = BodyFactory.CreateBody(world); FixtureFactory.CreateRectangle(ConvertUnits.ToSimUnits(50), ConvertUnits.ToSimUnits(50), 10, Vector2.Zero, BoxBody); foreach (Fixture fixture in BoxBody.FixtureList) { fixture.Restitution = 1.0f; fixture.Friction = 0.5f; } BoxBody.BodyType = BodyType.Dynamic; BoxBody.Position = ConvertUnits.ToSimUnits(new Vector2(400, 25)); //Create Floor //Fixture floorFixture = FixtureFactory.CreateRectangle(world, ConvertUnits.ToSimUnits(800), ConvertUnits.ToSimUnits(10), 10); //floorFixture.Restitution = 0.5f; //Bounceability //floorFixture.Friction = 0.5f; //Friction //FloorBody = floorFixture.Body; //Get Body from Fixture //FloorBody.IsStatic = true; //FloorBody.Position = ConvertUnits.ToSimUnits(new Vector2(0, 400)); Layer layer = map.GetLayer("HitGround"); TileArray groundTiles = layer.Tiles; for (int x = 0; x < 800; x++) { for (int y = 0; y < 48; y++) { Tile tile = groundTiles[x, y]; if (tile != null) { Fixture smallBox = FixtureFactory.CreateRectangle(world, ConvertUnits.ToSimUnits(16), ConvertUnits.ToSimUnits(16), 10); smallBox.Restitution = 0.5f; //Bounceability smallBox.Friction = 0.5f; //Friction var smallBoxBody = smallBox.Body; //Get Body from Fixture smallBoxBody.IsStatic = true; smallBoxBody.Position = ConvertUnits.ToSimUnits(new Vector2(x * 16, y * 16)); MapBodies.Add(smallBoxBody); } } } Camera = new Camera2D(GraphicsDevice); Camera.TargetPosition = screenCenter; //Camera.TrackingBody = BoxBody; }