This project has moved. For the latest updates, please go here.

Texture2d & fpe3.0

Sep 5, 2010 at 11:23 AM
Edited Sep 7, 2010 at 7:59 PM

pls can you help me ? how will i use my textures in fpe 3.0 ?

gravity and world.step lines dont work accordingly

i know i am doing something(s) wrong

pls genbox i am still thinking in fpe 2.x logic..

can u adapt the code for fpe 3.0 ? i just want to move my textures on the screen with correct fpe 3.0 code.


using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;
using FarseerPhysics;
using FarseerPhysics.Dynamics;
using FarseerPhysics.Factories;

namespace arkanoid_farseer_3
    /// <summary>
    /// This is the main type for your game
    /// </summary>
    public class Game1 : Microsoft.Xna.Framework.Game
        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;
        private World _world = new World(new Vector2(0,100));
        private Fixture fr;
        private Texture2D tex;

      public Game1()
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";

        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
            // TODO: Add your initialization logic here


        /// <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);
            tex = Content.Load<Texture2D>("St1");

            fr = FixtureFactory.CreateCircle(_world, 25, 1,new Vector2(300,50));
            fr.Body.BodyType = BodyType.Dynamic;
            // TODO: use this.Content to load your game content here

        /// <summary>
        /// UnloadContent will be called once per game and is the place to unload
        /// all content.
        /// </summary>
        protected override void UnloadContent()
            // TODO: Unload any non ContentManager content here

        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)

            // TODO: Add your update logic here
            _world.Step((float)gameTime.ElapsedGameTime.Milliseconds* .001f);

        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
            spriteBatch.Draw(tex,fr.Body.Position, Color.AliceBlue);
            // TODO: Add your drawing code here


Sep 7, 2010 at 8:33 PM

In FPE 3.0 we don't use pixels anymore. We use the Meter-Kilo-Second system instead. When you position your circle at (300,50), you will move it 300 meters on the x-axis and 50 meters on the y-axis - that is very far in the eyes of the physics engine.

What you need to do is to create a View and Projection matrix. You essentially need a camera that can scale your graphics so that one meter equals x number of pixels. In Farseer Physics Engine 2.x you had a 1:1 scale. The physics world was exactly the same as the drawn world - this is no longer the case: you can have a very tiny physics world and draw it in a decent scale on the screen.

Learn about how to draw using matrices in XNA. You could start out by using this this thread.