/// <summary> /// Cleans up. /// </summary> public virtual void CleanUp() { Camera2D.CleanUp(); foreach (var item in Objects.ToArray()) { this.RemoveObject(item); } if (CleanUpObjectsOnDispose) { foreach (var item in Objects) { item.CleanUp(graphicsFactory); } } foreach (var item in SoundEmiters2D.ToArray()) { this.RemoveSoundEmitter(item); } foreach (var item in SoundEmiters2D) { item.CleanUp(graphicsFactory); } Objects.Clear(); Camera2D = null; Dummies.Clear(); SoundEmiters2D.Clear(); particleManager = null; PhysicWorld = null; this.culler = null; }
/// <summary> /// Called once to load content /// </summary> /// <param name="GraphicInfo"></param> /// <param name="factory"></param> /// <param name="contentManager"></param> protected override void LoadContent(PloobsEngine.Engine.GraphicInfo GraphicInfo, PloobsEngine.Engine.GraphicFactory factory, PloobsEngine.SceneControl.IContentManager contentManager) { ///load background texture tile = factory.GetTexture2D("Textures/tile"); //add the 2d primitive draw component lines = new Lines(); Primitive2DDraw.Add2DPrimitive(lines); ///recover the physic world reference FarseerWorld fworld = this.World.PhysicWorld as FarseerWorld; ///Ground 1 Vertices verts = PolygonTools.CreateRectangle(GraphicInfo.BackBufferWidth, 100); { IModelo2D model = new SpriteFarseer(factory, verts, Color.Red); Basic2DTextureMaterial mat = new Basic2DTextureMaterial(); FarseerObject fs = new FarseerObject(fworld, model, 1, BodyType.Static); I2DObject o = new I2DObject(fs, mat, model); ///the origin of the created object will be in the center of it, this mean: if we draw it, the center of mass of it will be on the midle of the screen ///We need to translate it a bit down o.PhysicObject.Position = new Vector2(0, 250); this.World.AddObject(o); } ///Ground 2 verts = PolygonTools.CreateRectangle(GraphicInfo.BackBufferWidth, 100); { IModelo2D model = new SpriteFarseer(factory, verts, Color.Green); Basic2DTextureMaterial mat = new Basic2DTextureMaterial(); FarseerObject fs = new FarseerObject(fworld, model, 1, BodyType.Static); I2DObject o = new I2DObject(fs, mat, model); ///the origin of the created object will be in the center of it, this mean: if we draw it, the center of mass of it will be on the midle of the screen ///We need to translate it a bit down o.PhysicObject.Position = new Vector2(GraphicInfo.BackBufferWidth, 250); this.World.AddObject(o); } ///Ground 3 verts = PolygonTools.CreateRectangle(GraphicInfo.BackBufferWidth, 100); { IModelo2D model = new SpriteFarseer(factory, verts, Color.Yellow); Basic2DTextureMaterial mat = new Basic2DTextureMaterial(); FarseerObject fs = new FarseerObject(fworld, model, 1, BodyType.Static); I2DObject o = new I2DObject(fs, mat, model); ///the origin of the created object will be in the center of it, this mean: if we draw it, the center of mass of it will be on the midle of the screen ///We need to translate it a bit down o.PhysicObject.Position = new Vector2(GraphicInfo.BackBufferWidth * 2, 250); this.World.AddObject(o); } ///Support verts = PolygonTools.CreateRectangle(50, 200); { IModelo2D model = new SpriteFarseer(factory, verts, Color.Yellow); Basic2DTextureMaterial mat = new Basic2DTextureMaterial(); FarseerObject fs = new FarseerObject(fworld, model, 1, BodyType.Static); I2DObject o = new I2DObject(fs, mat, model); ///the origin of the created object will be in the center of it, this mean: if we draw it, the center of mass of it will be on the midle of the screen ///We need to translate it a bit down o.PhysicObject.Position = new Vector2(0, 100); this.World.AddObject(o); } ///plataform 1 verts = PolygonTools.CreateRectangle(50, 200); { IModelo2D model = new SpriteFarseer(factory, verts, Color.Green); Basic2DTextureMaterial mat = new Basic2DTextureMaterial(); FarseerObject fs = new FarseerObject(fworld, model, 1, BodyType.Dynamic); I2DObject o = new I2DObject(fs, mat, model); ///the origin of the created object will be in the center of it, this mean: if we draw it, the center of mass of it will be on the midle of the screen ///We need to translate it a bit down o.PhysicObject.Position = new Vector2(GraphicInfo.BackBufferWidth * 1.5f, 100); this.World.AddObject(o); } ///plataform 2 verts = PolygonTools.CreateRectangle(50, 200); { IModelo2D model = new SpriteFarseer(factory, verts, Color.Green); Basic2DTextureMaterial mat = new Basic2DTextureMaterial(); FarseerObject fs = new FarseerObject(fworld, model, 1, BodyType.Dynamic); I2DObject o = new I2DObject(fs, mat, model); ///the origin of the created object will be in the center of it, this mean: if we draw it, the center of mass of it will be on the midle of the screen ///We need to translate it a bit down o.PhysicObject.Position = new Vector2(GraphicInfo.BackBufferWidth * 1.6f, 100); this.World.AddObject(o); } ///plataform 3 verts = PolygonTools.CreateRectangle(200, 50); { IModelo2D model = new SpriteFarseer(factory, verts, Color.Green); Basic2DTextureMaterial mat = new Basic2DTextureMaterial(); FarseerObject fs = new FarseerObject(fworld, model, 1, BodyType.Dynamic); I2DObject o = new I2DObject(fs, mat, model); ///the origin of the created object will be in the center of it, this mean: if we draw it, the center of mass of it will be on the midle of the screen ///We need to translate it a bit down o.PhysicObject.Position = new Vector2(GraphicInfo.BackBufferWidth * 1.55f, -100); this.World.AddObject(o); } ///objective { Texture2D tex = factory.GetTexture2D("Textures//goo"); tex = factory.GetScaledTexture(tex,new Vector2(2)); IModelo2D model = new SpriteFarseer(tex); Basic2DTextureMaterial mat = new Basic2DTextureMaterial(); FarseerObject fs = new FarseerObject(fworld, model); goo = new I2DObject(fs, mat, model); goo.PhysicObject.Position = new Vector2(GraphicInfo.BackBufferWidth * 1.55f, -175); this.World.AddObject(goo); } ///Ball CircleShape circle = new CircleShape(50, 1); { IModelo2D model = new SpriteFarseer(factory, circle, Color.Orange); Basic2DTextureMaterial mat = new Basic2DTextureMaterial(); FarseerObject fs = new FarseerObject(fworld, model); ball = new I2DObject(fs, mat, model); ball.PhysicObject.Position = new Vector2(0, -25); ball.OnUpdate += new PloobsEngine.SceneControl._2DScene.OnUpdate(ball_OnUpdate); this.World.AddObject(ball); } ///the basic ortographic 2D camera Camera2D Camera2D = new Camera2D(GraphicInfo); Camera2D.Position = new Vector2(GraphicInfo.BackBufferWidth * 1.6f, 0); ///teleport to the given position Camera2D.Jump2Target(); this.World.Camera2D = Camera2D; ///go to the desired position but without teleport =P Camera2D.IntertiaController = 0.09f; Camera2D.Position = new Vector2(0, 0); Camera2D.EnablePositionTracking = true; Camera2D.ReachedTheTrackingPosition += new Action<PloobsEngine.SceneControl._2DScene.Camera2D>(Camera2D_ReachedTheTrackingPosition); base.LoadContent(GraphicInfo, factory, contentManager); }
void Camera2D_ReachedTheTrackingPosition(Camera2D obj) { SimpleConcreteGestureInputPlayable SimpleConcreteMouseBottomInputPlayable1 = new SimpleConcreteGestureInputPlayable(Microsoft.Xna.Framework.Input.Touch.GestureType.FreeDrag, (sample) => { mousepressed = true; } ); this.BindInput(SimpleConcreteMouseBottomInputPlayable1); SimpleConcreteGestureInputPlayable SimpleConcreteMouseBottomInputPlayable = null; SimpleConcreteMouseBottomInputPlayable = new SimpleConcreteGestureInputPlayable(Microsoft.Xna.Framework.Input.Touch.GestureType.DragComplete, (sample) => { mousepressed = false; lines.isEnabled = false; fired = true; Vector2 mpos = new Vector2(Mouse.GetState().X, Mouse.GetState().Y); Vector2 wpos = this.World.Camera2D.ConvertScreenToWorld(mpos); Vector2 force = (ball.PhysicObject.Position - wpos) * 30; ball.PhysicObject.ApplyForce(force); this.RemoveInputBinding(SimpleConcreteMouseBottomInputPlayable); this.RemoveInputBinding(SimpleConcreteMouseBottomInputPlayable1); (this.World.Camera2D as Camera2D).TrackingBody = ball; (this.World.Camera2D as Camera2D).IntertiaController = 1; } ); this.BindInput(SimpleConcreteMouseBottomInputPlayable); }