protected override void LoadContent(PloobsEngine.Engine.GraphicInfo GraphicInfo, PloobsEngine.Engine.GraphicFactory factory, PloobsEngine.SceneControl.IContentManager contentManager) { tile = factory.GetTexture2D("Textures/tile"); FarseerWorld fworld = this.World.PhysicWorld as FarseerWorld; ///Ground 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); } ///animated sprite { ///loading the texture Texture2D tex = factory.GetTexture2D("Textures//DudeSheet"); ///scale the texture (this is not good specially with animated texture, cause the whole texture is being scalled) tex = factory.GetScaledTexture(tex, new Vector2(2)); ///Loading the Sprite and extracting the frames ///8 = Maximum number of frames in the horizontal ///2 = Number of animation ///See the texture DudeSheet to undertand SpriteAnimated sa = new SpriteAnimated(tex, 8, 2); ///Specify the first animation (First "line" of the texture) -- see the extra parameters in addAnimation sa.AddAnimation("ANIM1", 1, 8, 0); ///Specify the Second animation (Second "line" of the texture) sa.AddAnimation("ANIM2", 2, 4, 0); ///Create the Material Basic2DTextureMaterial mat = new Basic2DTextureMaterial(); ///To create the physic object, we extract one frame from the image and use it to be our physic body =P Texture2D frame = factory.GetTexturePart(tex, sa.GetFrameRectangle("ANIM1", 0)); FarseerObject fs = new FarseerObject(fworld, frame); sheet = new I2DObject(fs, mat, sa); sheet.PhysicObject.Position = new Vector2(0,0); this.World.AddObject(sheet); } ///camera this.World.Camera2D = new Camera2D(GraphicInfo); base.LoadContent(GraphicInfo, factory, contentManager); ///when double tap, perform the following action this.BindInput(new SimpleConcreteGestureInputPlayable(Microsoft.Xna.Framework.Input.Touch.GestureType.DoubleTap, (a) => { animationIndex = (animationIndex + 1) % 2; (sheet.Modelo as SpriteAnimated).ChangeAnimation(animations[animationIndex]); ///you can play, pause, change ..... using the SpriteAnimated object. } )); }
/// <summary> /// Initializes a new instance of the <see cref="IObject"/> class. /// </summary> /// <param name="Material">The material.</param> /// <param name="Modelo">The modelo.</param> /// <param name="PhysicObject">The physic object.</param> public ISpriteObject(IMaterial Material, SpriteAnimated Modelo, CharacterObject PhysicObject, float animationSpeed = 20) { System.Diagnostics.Debug.Assert(Modelo != null); System.Diagnostics.Debug.Assert(Material != null); System.Diagnostics.Debug.Assert(PhysicObject != null); this.CharacterObject = PhysicObject; this.Material = Material; this.Modelo = null; this.SpriteAnimated = Modelo; this.PhysicObject = PhysicObject; IObjectAttachment = new List<IObjectAttachment>(); Name = null; TaskResult = BehaviorTrees.TaskResult.Success; anims = new String[Modelo.NumberAnimations]; for (int i = 0; i < Modelo.NumberAnimations ; i++) { String name = i.ToString(); SpriteAnimated.AddAnimation(name, i + 1, Modelo.Frame, 0, true, animationSpeed); anims[i] = name; } }
protected override void LoadContent(PloobsEngine.Engine.GraphicInfo GraphicInfo, PloobsEngine.Engine.GraphicFactory factory, PloobsEngine.SceneControl.IContentManager contentManager) { tile = factory.GetTexture2D("Textures/tile"); FarseerWorld fworld = this.World.PhysicWorld as FarseerWorld; ///border border = new Border(fworld, factory, GraphicInfo, factory.CreateTexture2DColor(1, 1, Color.Red)); ///from texture { Texture2D tex = factory.GetTexture2D("Textures//goo"); IModelo2D model = new SpriteFarseer(tex); Basic2DTextureMaterial mat = new Basic2DTextureMaterial(); FarseerObject fs = new FarseerObject(fworld, model); I2DObject o = new I2DObject(fs, mat, model); o.PhysicObject.Position = new Vector2(200, 0); this.World.AddObject(o); } ///from texture, scale usage sample { 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); I2DObject o = new I2DObject(fs, mat, model); o.OnHasMoved += new PloobsEngine.SceneControl._2DScene.OnHasMoved(o_OnHasMoved); this.World.AddObject(o); } ///rectangle Vertices verts = PolygonTools.CreateRectangle(50, 50); { IModelo2D model = new SpriteFarseer(factory, verts, Color.Orange); Basic2DTextureMaterial mat = new Basic2DTextureMaterial(); FarseerObject fs = new FarseerObject(fworld, model); I2DObject o = new I2DObject(fs, mat, model); o.PhysicObject.Position = new Vector2(-200, 0); this.World.AddObject(o); } ///circle CircleShape circle = new CircleShape(50, 1); { IModelo2D model = new SpriteFarseer(factory, circle, Color.Orange); Basic2DTextureMaterial mat = new Basic2DTextureMaterial(); FarseerObject fs = new FarseerObject(fworld, model); I2DObject o = new I2DObject(fs, mat, model); o.PhysicObject.Position = new Vector2(200, -100); this.World.AddObject(o); } ///animated sprite { Texture2D tex = factory.GetTexture2D("Textures//DudeSheet"); SpriteAnimated sa = new SpriteAnimated(tex, 8, 2); sa.AddAnimation("ANIM1", 1, 8, 0); sa.AddAnimation("ANIM2", 2, 4, MathHelper.PiOver2); Basic2DTextureMaterial mat = new Basic2DTextureMaterial(); Texture2D frame = factory.GetTexturePart(tex, sa.GetFrameRectangle("ANIM1", 0)); FarseerObject fs = new FarseerObject(fworld, frame); //GhostObject fs = new GhostObject(Vector2.Zero); sheet = new I2DObject(fs, mat, sa); sheet.PhysicObject.Position = new Vector2(500, 0); this.World.AddObject(sheet); } { PointLight2D l = new PointLight2D(new Vector2(-GraphicInfo.BackBufferWidth / 4, -GraphicInfo.BackBufferWidth / 4), Color.Red, 1); this.World.AddLight(l); } { SpotLight2D l = new SpotLight2D(new Vector2(+GraphicInfo.BackBufferWidth / 4, -GraphicInfo.BackBufferWidth / 4), Color.Blue, new Vector2(0, 1), MathHelper.ToRadians(45)); this.World.AddLight(l); } { SimpleConcreteKeyboardInputPlayable sc = new SimpleConcreteKeyboardInputPlayable(StateKey.PRESS, Keys.Space); sc.KeyStateChange += new KeyStateChange(sc_KeyStateChange); this.BindInput(sc); } ///camera this.World.Camera2D = new Camera2D(GraphicInfo); DPFSParticleSystem ps = new DPFSParticleSystem("TESTE", new SpriteParticleSystem(null)); this.World.ParticleManager.AddAndInitializeParticleSystem(ps); ///add a post effect =P //this.RenderTechnic.AddPostEffect(new WigglePostEffect()); ///updateable JointUpdateable ju = new JointUpdateable(this, fworld, this.World.Camera2D); base.LoadContent(GraphicInfo, factory, contentManager); { NeoforceGui guiManager = this.Gui as NeoforceGui; System.Diagnostics.Debug.Assert(guiManager != null); // Create and setup Window control. Window window = new Window(guiManager.Manager); window.Init(); window.Text = "Getting Started"; window.Width = 480; window.Height = 200; window.Center(); window.Visible = true; // Create Button control and set the previous window as its parent. Button button = new Button(guiManager.Manager); button.Init(); button.Text = "OK"; button.Width = 72; button.Height = 24; button.Left = (window.ClientWidth / 2) - (button.Width / 2); button.Top = window.ClientHeight - button.Height - 8; button.Anchor = Anchors.Bottom; button.Parent = window; // Add the window control to the manager processing queue. guiManager.Manager.Add(window); } }
protected override void LoadContent(PloobsEngine.Engine.GraphicInfo GraphicInfo, PloobsEngine.Engine.GraphicFactory factory, PloobsEngine.SceneControl.IContentManager contentManager) { tile = factory.GetTexture2D("Textures/tile"); FarseerWorld fworld = this.World.PhysicWorld as FarseerWorld; //ground { Vertices Vertices = new Vertices(3); Vertices.Add(new Vector2(-200, 0)); Vertices.Add(new Vector2(0, 200)); Vertices.Add(new Vector2(200, 0)); SpriteFarseer SpriteFarseer = new SpriteFarseer(factory, Vertices, Color.Red); Basic2DTextureMaterial mat = new Basic2DTextureMaterial(); FarseerObject fs = new FarseerObject(fworld, SpriteFarseer, 1, BodyType.Static); I2DObject o = new I2DObject(fs, mat, SpriteFarseer); this.World.AddObject(o); } ///from texture { Texture2D tex = factory.GetTexture2D("Textures//goo"); IModelo2D model = new SpriteFarseer(tex); Basic2DTextureMaterial mat = new Basic2DTextureMaterial(); FarseerObject fs = new FarseerObject(fworld, tex); I2DObject o = new I2DObject(fs, mat, model); this.World.AddObject(o); } ///rectangle Vertices verts = PolygonTools.CreateRectangle(50, 50); { IModelo2D model = new SpriteFarseer(factory, verts, Color.Red); model.LayerDepth = 0; Basic2DTextureMaterial mat = new Basic2DTextureMaterial(); FarseerObject fs = new FarseerObject(fworld, model, 1, BodyType.Static); I2DObject o = new I2DObject(fs, mat, model); this.World.AddObject(o); } //rectangle //cria em Display verts = PolygonTools.CreateRectangle(50, 50); { IModelo2D model = new SpriteFarseer(factory, verts, Color.Green); model.LayerDepth = 1; Basic2DTextureMaterial mat = new Basic2DTextureMaterial(); FarseerObject fs = new FarseerObject(fworld, model, 1, BodyType.Static); I2DObject o = new I2DObject(fs, mat, model); o.PhysicObject.Position = new Vector2(50, 50); this.World.AddObject(o); } ///rectangle verts = PolygonTools.CreateRectangle(50, 50); { IModelo2D model = new SpriteFarseer(factory, verts, Color.Orange); model.LayerDepth = 0; Basic2DTextureMaterial mat = new Basic2DTextureMaterial(); FarseerObject fs = new FarseerObject(fworld, model, 1, BodyType.Static); I2DObject o = new I2DObject(fs, mat, model); o.PhysicObject.Position = new Vector2(-GraphicInfo.BackBufferWidth / 2, 0); this.World.AddObject(o); } ///circle CircleShape circle = new CircleShape(50, 1); { IModelo2D model = new SpriteFarseer(factory, circle, Color.Yellow); Basic2DTextureMaterial mat = new Basic2DTextureMaterial(); FarseerObject fs = new FarseerObject(fworld, model); I2DObject o = new I2DObject(fs, mat, model); o.PhysicObject.Position = new Vector2(0, -GraphicInfo.BackBufferHeight / 2); this.World.AddObject(o); } ///animated sprite { Texture2D tex = factory.GetTexture2D("Textures//DudeSheet"); SpriteAnimated sa = new SpriteAnimated(tex, 8, 2); sa.AddAnimation("ANIM1", 1, 8, 0); sa.AddAnimation("ANIM2", 2, 4, MathHelper.PiOver2); Basic2DTextureMaterial mat = new Basic2DTextureMaterial(); Texture2D frame = factory.GetTexturePart(tex, sa.GetFrameRectangle("ANIM1", 0)); FarseerObject fs = new FarseerObject(fworld, frame); I2DObject sheet = new I2DObject(fs, mat, sa); sheet.PhysicObject.Position = new Vector2(100, 100); this.World.AddObject(sheet); } Primitive2DDraw.Add2DPrimitive(lines); ///camera this.World.Camera2D = new Camera2D(GraphicInfo); base.LoadContent(GraphicInfo, factory, contentManager); }
/// <summary> /// Load content for the screen. /// </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, IContentManager contentManager) { ///must be called before all base.LoadContent(GraphicInfo, factory, contentManager); ///Uncoment to Add an object /////Create a simple object /////Geomtric Info and textures (this model automaticaly loads the texture) //SimpleModel simpleModel = new SimpleModel(factory, "Model FILEPATH GOES HERE", "Diffuse Texture FILEPATH GOES HERE -- Use only if it is not embeded in the Model file"); /////Physic info (position, rotation and scale are set here) //TriangleMeshObject tmesh = new TriangleMeshObject(simpleModel, Vector3.Zero, Matrix.Identity, Vector3.One, MaterialDescription.DefaultBepuMaterial()); /////Shader info (must be a deferred type) //DeferredNormalShader shader = new DeferredNormalShader(); /////Material info (must be a deferred type also) //DeferredMaterial fmaterial = new DeferredMaterial(shader); /////The object itself //IObject obj = new IObject(fmaterial, simpleModel, tmesh); /////Add to the world //this.World.AddObject(obj); { SimpleModel simpleModel = new SimpleModel(factory, "Model//block"); simpleModel.SetTexture(factory.CreateTexture2DColor(1, 1, Color.Red), TextureType.DIFFUSE); BoxObject tmesh = new BoxObject(Vector3.Zero, 1, 1, 1, 10, new Vector3(500, 5, 500), Matrix.Identity, MaterialDescription.DefaultBepuMaterial()); tmesh.isMotionLess = true; ForwardXNABasicShader shader = new ForwardXNABasicShader(ForwardXNABasicShaderDescription.Default()); ForwardMaterial fmaterial = new ForwardMaterial(shader); IObject obj = new IObject(fmaterial, simpleModel, tmesh); this.World.AddObject(obj); } { SimpleModel simpleModel = new SimpleModel(factory, "Model//block"); simpleModel.SetTexture(factory.CreateTexture2DColor(1, 1, Color.Yellow), TextureType.DIFFUSE); GhostObject go = new GhostObject(Vector3.Zero, Matrix.Identity, new Vector3(1, 100, 1)); ForwardXNABasicShader shader = new ForwardXNABasicShader(ForwardXNABasicShaderDescription.Default()); ForwardMaterial fmaterial = new ForwardMaterial(shader); BaseObject obj = new BaseObject(fmaterial, simpleModel, go); obj.Name = "TORRE1"; this.World.AddObject(obj); //entityFactory.CreateShooterTower(obj, 3, 2, 100); } { Texture2D tex = factory.GetTexture2D("Textures//spriteteste"); SpriteAnimated SpriteAnimated = new PloobsEngine.Modelo2D.SpriteAnimated(tex, 9, 8); SpriteAnimated.PlayCurrentAnimation(); CharacterObject Characterobj = new CharacterObject(new Vector3(25, 15, 25), Matrix.Identity, 10, 5, 10, 1f, Vector3.One, 5); Sprite3DShader Sprite3DShader = new Sprite3DShader(Vector2.One); ForwardMaterial fmaterial = new ForwardMaterial(Sprite3DShader); ISpriteObject obj = new ISpriteObject(fmaterial, SpriteAnimated, Characterobj); obj.Name = "Enemy"; this.World.AddObject(obj); obj.OnUpdate += new OnUpdate(obj_OnUpdate); } ///Add some directional lights to completely iluminate the world #region Lights DirectionalLightPE ld1 = new DirectionalLightPE(Vector3.Left, Color.White); DirectionalLightPE ld2 = new DirectionalLightPE(Vector3.Right, Color.White); DirectionalLightPE ld3 = new DirectionalLightPE(Vector3.Backward, Color.White); DirectionalLightPE ld4 = new DirectionalLightPE(Vector3.Forward, Color.White); DirectionalLightPE ld5 = new DirectionalLightPE(Vector3.Down, Color.White); float li = 0.4f; ld1.LightIntensity = li; ld2.LightIntensity = li; ld3.LightIntensity = li; ld4.LightIntensity = li; ld5.LightIntensity = li; this.World.AddLight(ld1); this.World.AddLight(ld2); this.World.AddLight(ld3); this.World.AddLight(ld4); this.World.AddLight(ld5); #endregion ///Add a AA post effect this.RenderTechnic.AddPostEffect(new AntiAliasingPostEffect()); ///add a camera this.World.CameraManager.AddCamera(new CameraFirstPerson(GraphicInfo)); }
protected override void LoadContent(PloobsEngine.Engine.GraphicInfo GraphicInfo, PloobsEngine.Engine.GraphicFactory factory, PloobsEngine.SceneControl.IContentManager contentManager) { tile = factory.GetTexture2D("Textures/tile"); FarseerWorld fworld = this.World.PhysicWorld as FarseerWorld; ///border border = new Border(fworld, factory, GraphicInfo, factory.CreateTexture2DColor(1, 1, Color.Red)); ///from texture { Texture2D tex = factory.GetTexture2D("Textures//goo"); IModelo2D model = new SpriteFarseer(tex); Basic2DTextureMaterial mat = new Basic2DTextureMaterial(); FarseerObject fs = new FarseerObject(fworld, model); I2DObject o = new I2DObject(fs, mat, model); o.PhysicObject.Position = new Vector2(200, 0); this.World.AddObject(o); } ///from texture, scale usage sample { 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); I2DObject o = new I2DObject(fs, mat, model); o.OnHasMoved += new PloobsEngine.SceneControl._2DScene.OnHasMoved(o_OnHasMoved); this.World.AddObject(o); } ///rectangle Vertices verts = PolygonTools.CreateRectangle(50, 50); { IModelo2D model = new SpriteFarseer(factory, verts, Color.Orange); Basic2DTextureMaterial mat = new Basic2DTextureMaterial(); FarseerObject fs = new FarseerObject(fworld, model); I2DObject o = new I2DObject(fs, mat, model); o.PhysicObject.Position = new Vector2(-200, 0); this.World.AddObject(o); } ///circle CircleShape circle = new CircleShape(50, 1); { IModelo2D model = new SpriteFarseer(factory, circle , Color.Orange); Basic2DTextureMaterial mat = new Basic2DTextureMaterial(); FarseerObject fs = new FarseerObject(fworld, model); I2DObject o = new I2DObject(fs, mat, model); o.PhysicObject.Position = new Vector2(200, -100); this.World.AddObject(o); } ///animated sprite { Texture2D tex = factory.GetTexture2D("Textures//DudeSheet"); SpriteAnimated sa = new SpriteAnimated(tex, 8, 2); sa.AddAnimation("ANIM1", 1, 8,0); sa.AddAnimation("ANIM2", 2, 4, MathHelper.PiOver2); Basic2DTextureMaterial mat = new Basic2DTextureMaterial(); Texture2D frame = factory.GetTexturePart(tex,sa.GetFrameRectangle("ANIM1",0)); FarseerObject fs = new FarseerObject(fworld, frame); //GhostObject fs = new GhostObject(Vector2.Zero); sheet = new I2DObject(fs, mat, sa); sheet.PhysicObject.Position = new Vector2(500, 0); this.World.AddObject(sheet); } { PointLight2D l = new PointLight2D(new Vector2(-GraphicInfo.BackBufferWidth / 4, -GraphicInfo.BackBufferWidth / 4), Color.Red, 1); this.World.AddLight(l); } { SpotLight2D l = new SpotLight2D(new Vector2(+GraphicInfo.BackBufferWidth / 4, -GraphicInfo.BackBufferWidth / 4), Color.Blue, new Vector2(0, 1), MathHelper.ToRadians(45)); this.World.AddLight(l); } { SimpleConcreteKeyboardInputPlayable sc = new SimpleConcreteKeyboardInputPlayable(StateKey.PRESS,Keys.Space); sc.KeyStateChange+=new KeyStateChange(sc_KeyStateChange); this.BindInput(sc); } ///camera this.World.Camera2D = new Camera2D(GraphicInfo); DPFSParticleSystem ps = new DPFSParticleSystem("TESTE", new SpriteParticleSystem(null)); this.World.ParticleManager.AddAndInitializeParticleSystem(ps); ///add a post effect =P //this.RenderTechnic.AddPostEffect(new WigglePostEffect()); ///updateable JointUpdateable ju = new JointUpdateable(this, fworld, this.World.Camera2D); base.LoadContent(GraphicInfo, factory, contentManager); }