Tutorial for WP7 Silverlight and XNA application

Dec 9, 2011 at 12:33 PM
Edited Dec 9, 2011 at 12:35 PM

I've created a small tutorial how to use xTile Engine in WP7 Silverlight and XNA project. http://www.vihrearobotti.com/wp7/gametilebox1

Coordinator
Dec 9, 2011 at 4:34 PM

Thank you very much for sharing this!

Dec 11, 2011 at 2:50 PM

no prbs, thanks for great project :)

Feb 7, 2012 at 7:32 PM
Edited Feb 7, 2012 at 7:33 PM

Hey, thanks a lot for your tutorial noxo!

I've just registered to say thanks (and thanks colinvella for this great tool!). I'm a bit stuck and need some help. If I run your tutorial on wp7 with landscape orientation, the ball collision will break, it won't collide with the terrain/hidden layer anymore, the ball just falls off from the world, even tho the tile map and hidden layer draws correctly (landscaped). I can't seem to get around this. I think it has something to do with the collision area defined from the tile map to Box2d, tiles positions are not the same when in landscape? Should I do some positions conversions? not sure how... Here is the pice of code that reads the ground layer tiles from the map and makes up the body:

          // Add the ground and water hit area rectables to Box2D world
           // Each tile is 16x16 pixels

            TileArray groundTiles = map.GetLayer("HitGround").Tiles;
            TileArray waterTiles = map.GetLayer("HitWater").Tiles;

            for (int y = 0; y < 48; y++)
            {
                for (int x = 0; x < 800; x++)
                {

                    Tile tgroup = groundTiles[x, y];
                    Tile twater = waterTiles[x, y];

                    if (tgroup != null)
                    {
                        physics.addRect(x * 16, y * 16, 16, 16, Physics.TYPE_GROUND);
                    }

                    if (twater != null)
                    {
                        physics.addRect(x * 16, y * 16, 16, 16, Physics.TYPE_WATER);
                    }

                }
            }

 

 

//---------- physics::addRect -- int PTM=32

  public void addRect(float x, float y, float width, int height, object type)
        {

            PolygonShape ps = new PolygonShape();
            ps.SetAsBox(width / PTM / 2, height / PTM / 2);

            FixtureDef fd = new FixtureDef();
            fd.shape = ps;
            fd.restitution = 0.0f;
            fd.friction = 0.8f;
            fd.density = 1.0f;

            BodyDef bd = new BodyDef();
            bd.type = BodyType.Static;
            bd.position = new Vector2(x/PTM,y/PTM);
            bd.userData = type;

            Body body = world.CreateBody(bd);
            body.CreateFixture(fd);

        }

//-----------------------------------------

 

Above works as expected if wp7 is in portrait, but not on landscape.

Any suggestions on how should I handle landscape in your sample? I'm a newbie, any help will be appreciated.

Thank you.