Quantcast
Channel: tIDE (Tilemap Integrated Development Environment)
Viewing all 173 articles
Browse latest View live

New Post: Index problem

$
0
0
I'm trying to make a collision system for my game, however I am encountering a problem when trying to get the layers of my map file.

I get an error at this line
collision = map.Layers[3];
It says "Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index"

I'm not sure why, I don't know if it's a problem with my map file or something in my code, any help would be great!

New Post: Getting Tile Info

$
0
0
Anyone have sample code of how to reference the tiles in the map for collision detection, I have yet to figure it out even with these examples. I have a 2 layers a "walls" layer and a "floor" layer. Just want to access the walls layer and detect if my player is colliding with any walls but how to access the tiles is the question?
Any helpful code with explanation would be greatly appreciated.
Thanks,

New Post: Index problem

$
0
0
Layer indices are zero-based. So if your map has, say, 3 layers, you can access them via indices 0, 1 and 2 (not 1, 2 and 3).

New Post: Getting Tile Info

$
0
0
There is a sample in this very thread if you look carefully enough. There are also plenty of answers throughout the forum.

New Post: Index problem

$
0
0
Yea, I figured it out, there was a problem somewhere else in my code causing that, thanks!

New Post: collision detection

$
0
0
I'm currently trying to make a 2D platformer game and I'm using a similar method of detecting collision as the ones discussed in these threads where define a newPosition and check the tile at the newPosition and if the tile is passable I move to the newPosition, and if not, I stay where I am.
However, this is causing problems with jumping involved and also moving left and right because I stick to walls and the floor since a collision is detected and my Position stays the same. I'm trying to separate the detection between horizontal collision and vertical collision but am having some trouble, any help would be appreciated.
I used the platformer starter kit for physics just for testing.

Here is my collision method
private bool HandleCollision(float newPositionX, float newPositionY)
        {
            Tile tile;
            Location tileLocation;
            isOnGround = false;

            //top left
            tileLocation = new Location((int)newPositionX / collision.TileWidth, (int)newPositionY / collision.TileHeight);
            tile = collision.Tiles[tileLocation];
            if (tile != null && tile.TileIndex == 263)
            {
                return true;
            }

            //top right
            tileLocation = new Location(((int)newPositionX + collisionBox.Width) / collision.TileWidth, (int)newPositionY / collision.TileHeight);
            tile = collision.Tiles[tileLocation];
            if (tile != null && tile.TileIndex == 263)
            {
                return true;
            }

            //bottom left
            tileLocation = new Location((int)newPositionX / collision.TileWidth, ((int)newPositionY + collisionBox.Height) / collision.TileHeight);
            tile = collision.Tiles[tileLocation];
            if (tile != null && tile.TileIndex == 263)
            {
                isOnGround = true;
                return true;
            }

            //bottom right
            tileLocation = new Location(((int)newPositionX + collisionBox.Width) / collision.TileWidth, ((int)newPositionY + collisionBox.Height) / collision.TileHeight);
            tile = collision.Tiles[tileLocation];
            if (tile != null && tile.TileIndex == 263)
            {
                isOnGround = true;
                return true;
            }

            return false;
        }
And my Physics method
public void ApplyPhysics(GameTime gameTime)
        {
            float elapsed = (float)gameTime.ElapsedGameTime.TotalSeconds;

            Vector2 newPosition = Position;

            //x velocity
            velocity.X += movement * MoveAcceleration * elapsed;
            velocity.X = MathHelper.Clamp(velocity.X, -MaxMoveSpeed, MaxMoveSpeed);

            //y velocity
            velocity.Y = Jump(velocity.Y, gameTime);
            velocity.Y = MathHelper.Clamp(velocity.Y + GravityAcceleration * elapsed, -MaxFallSpeed, MaxFallSpeed);
            
            // Apply pseudo-drag horizontally.
            if (isOnGround)
                velocity.X *= GroundDragFactor;
            else
                velocity.X *= AirDragFactor;

            //Apply velocity
            newPosition += velocity * elapsed;
            newPosition = new Vector2 ((float)Math.Round(newPosition.X), (float)Math.Round(newPosition.Y));

            if (!HandleCollision(newPosition.X, newPosition.Y))
            {
                Position = newPosition;
            }
            else
            {
                newPosition = Position;
                velocity = Vector2.Zero;
            }

New Post: tIDE maps now supported by libGDX

$
0
0
The libGDX desktop/Android/iOS/HTML5 Java game development framework now supports the .tide map format.

More details here.

New Comment on "xTile Engine Tutorial for Game Studio / XNA 4.0"

$
0
0
For those using express edition and unable to add solution folders you need to do the following: Copy "xTile.dll" and "xTile.Pipeline.dll" into your projects main directory(where the code is, not the content). After doing this you need to right click on each of them and select "Properties" which will bring up a new window. Near the bottom of the first tab you should see a button that says "Unblock" that you need to click. Next go into VS 2010 Express and add the references (xTile.dll under the project for code and xTile.Pipeline.dll under the Content project). Now if you already have a map and tilesheet in then next you need to select your map and go to it's properties(right click and select properties). In Content Importer it should be set to "tIDE Map Importer" and Content Processor should be set to "tIDE Map Processor" . That solves the issue of not having the importer/processor unavailable because of no solution folders in express editions.

New Post: Farseer Physics?

New Post: Farseer Physics?

New Post: Farseer Physics?

$
0
0
Oh wow thanks colinvella. I always heard about Farseer being a port of Box2d but I never paid much attention to it. After reading up on it now it all clicks about them using the same stuff Box2d uses. I dug through that sample I posted and it's just like wow trying to pick through it all.

New Post: OSX support

$
0
0
Hey

Are there any plans for supporting OSX?

If not, how trivial would it be to get it running on OSX? Any pointers?

Thanks

New Post: OSX support

$
0
0
I have no immediate plans for porting xTile to OSX myself, however I suggest checking out libGDX. It runs on OSX (and iOS, Android amongst others) and now supports Tide maps.

New Post: OSX support

$
0
0
Thanks for the reply. libGDX is not really viable I'm afraid as I'm working with Monogame and am looking for a decent tile library, rather than write my own.
I'm quite happy running tide and then compiling the maps to xnb's (until the monogame content pipeline supports other platforms) in a VM , but i'm doing my main development in osx.

I'll have a play around tonight and see if I can get xTile compiling under mono on my mac.

Cheers

New Post: OSX support

$
0
0
Someone did manage to get it to work with Monogame. Have a look at this thread.

New Post: OSX support

$
0
0
Coll, thanks, I'll take a go at that :)

New Post: Hey, I need help.

$
0
0
Hi, I write to you because I'm currently developing a videogame. I have tried to implement an scalating system on your DLL, but I always get this blury effect with the tiles. Could you help me make the borders look more sharp and the tiles more clear? Thanks. I'll leave the code arounde here:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using xTile.Dimensions;
using xTile.Tiles;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;

namespace xTile.Display
{
    /// <summary>
    /// XNA implementation of the display device. In this implementation,
    /// the tile sheet image sources are loaded from the content pipeline
    /// and alpha and additive blend modes are supported via dedicated
    /// sprite batch instances
    /// </summary>
    public class XnaDisplayDevice : IDisplayDevice
    {
        #region Public Properties

        /// <summary>
        /// Colour modulation property. This is set to White by default
        /// 
        /// NOTE: This property is specific to this implementation
        /// </summary>
        public Color ModulationColour
        {
            get { return m_modulationColour; }
            set { m_modulationColour = value; }
        }

        /// <summary>
        /// Spritebatch instance used for alpha blending
        /// </summary>
        public SpriteBatch SpriteBatchAlpha
        {
            get { return m_spriteBatchAlpha; }
        }

        /// <summary>
        /// Spritebatch instance used for additive blending
        /// </summary>
        public SpriteBatch SpriteBatchAdditive
        {
            get { return m_spriteBatchAdditive; }
        }

        #endregion

        #region Public Methods

        /// <summary>
        /// Constructs an XNA display device using the given content manager and
        /// XNA graphics device
        /// </summary>
        /// <param name="contentManager">Content manager to use for resource access</param>
        /// <param name="graphicsDevice">Underlying XNA graphics device</param>
        /// 
        public float Scal;
        public XnaDisplayDevice(ContentManager contentManager, GraphicsDevice graphicsDevice , float Scale)
        {
            Scal = Scale;
            m_contentManager = contentManager;
            m_graphicsDevice = graphicsDevice;
            m_spriteBatchAlpha = new SpriteBatch(graphicsDevice);
            m_spriteBatchAdditive = new SpriteBatch(graphicsDevice);
            m_tileSheetTextures = new Dictionary<TileSheet, Texture2D>();

            m_tilePosition = new Vector2();
            m_sourceRectangle = new Microsoft.Xna.Framework.Rectangle();
            m_modulationColour = Color.White;
        }

        /// <summary>
        /// Destructs the XNA display device
        /// </summary>
        ~XnaDisplayDevice()
        {
            Dispose(false);
        }

        /// <summary>
        /// Loads the given tile sheet. The image source is loaded from the
        /// content pipeline by stripping any extension from the image source
        /// and using the resulting path into the content pipeline
        /// </summary>
        /// <param name="tileSheet">Tile sheet to load</param>
        public void LoadTileSheet(TileSheet tileSheet)
        {
            Texture2D texture2D = m_contentManager.Load<Texture2D>(tileSheet.ImageSource);
            m_tileSheetTextures[tileSheet] = texture2D;
        }

        /// <summary>
        /// Frees the tile sheet resources
        /// </summary>
        /// <param name="tileSheet">Tile sheet to dispose</param>
        public void DisposeTileSheet(TileSheet tileSheet)
        {
            if (!m_tileSheetTextures.ContainsKey(tileSheet))
                return;

            m_tileSheetTextures.Remove(tileSheet);
        }

        /// <summary>
        /// Prepares the device for rendering
        /// </summary>
        public void BeginScene()
        {
            m_spriteBatchAlpha.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend);
            m_spriteBatchAdditive.Begin(SpriteSortMode.Deferred, BlendState.Additive);
        }

        /// <summary>
        /// Sets the viewport.
        /// 
        /// NOTE: This function is not supported on the Zune platform.
        /// </summary>
        /// <param name="viewport">Viewport to apply</param>
        public void SetViewport(xTile.Dimensions.Rectangle viewport)
        {
            // further clip region within display device's dimensions
            int nMaxWidth = m_graphicsDevice.PresentationParameters.BackBufferWidth;
            int nMaxHeight = m_graphicsDevice.PresentationParameters.BackBufferHeight;

            int viewportLeft = Clamp(viewport.X, 0, nMaxWidth);
            int viewportTop = Clamp(viewport.Y, 0, nMaxHeight);
            int viewportRight = Clamp(viewport.X + viewport.Width, 0, nMaxWidth);
            int viewportBottom = Clamp(viewport.Y + viewport.Height, 0, nMaxHeight);
            int viewportWidth = viewportRight - viewportLeft;
            int viewportHeight = viewportBottom - viewportTop;

            m_graphicsDevice.Viewport = new Viewport(
                viewportLeft, viewportTop, viewportWidth, viewportHeight);
        }

        /// <summary>
        /// Draws the given tile at the given location
        /// </summary>
        /// <param name="tile">Tile to draw</param>
        /// <param name="location">Drawing location</param>
        public void DrawTile(Tile tile, Location location)
        {
            if (tile == null)
                return;

            SpriteBatch spriteBatch = tile.BlendMode == BlendMode.Alpha
                ? m_spriteBatchAlpha : m_spriteBatchAdditive;


            xTile.Dimensions.Rectangle sourceRectangle
                = tile.TileSheet.GetTileImageBounds(tile.TileIndex);

            Texture2D texture2D = m_tileSheetTextures[tile.TileSheet];

            m_tilePosition.X = location.X*Scal ;
            m_tilePosition.Y = location.Y*Scal;

            m_sourceRectangle.X = sourceRectangle.X;
            m_sourceRectangle.Y = sourceRectangle.Y;
            m_sourceRectangle.Width = sourceRectangle.Width;
            m_sourceRectangle.Height = sourceRectangle.Height;

            spriteBatch.Draw(texture2D, m_tilePosition, m_sourceRectangle, m_modulationColour,0.0f, Vector2.Zero, Scal, SpriteEffects.None, 0);
        }

        /// <summary>
        /// Terminates rendering of the current frame and commits drawing instructions
        /// to the underlying XNA graphics pipeline
        /// </summary>
        public void EndScene()
        {
            m_spriteBatchAlpha.End();
            m_spriteBatchAdditive.End();
        }

        #endregion

        #region Private Methods

        private int Clamp(int nValue, int nMin, int nMax)
        {
            return Math.Min(Math.Max(nValue, nMin), nMax);
        }

        #endregion

        #region Private Variables

        private ContentManager m_contentManager;
        private GraphicsDevice m_graphicsDevice;
        private SpriteBatch m_spriteBatchAlpha;
        private SpriteBatch m_spriteBatchAdditive;
        private Dictionary<TileSheet, Texture2D> m_tileSheetTextures;
        private Microsoft.Xna.Framework.Vector2 m_tilePosition;
        private Microsoft.Xna.Framework.Rectangle m_sourceRectangle;
        private Color m_modulationColour;

        #endregion

        /// <summary>
        /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
        /// </summary>
        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }

        /// <summary>
        /// Releases unmanaged and - optionally - managed resources
        /// </summary>
        /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
        private void Dispose(bool disposing)
        {
            if (!disposing)
                return;

            if (m_spriteBatchAlpha != null)
            {
                m_spriteBatchAlpha.Dispose();
                m_spriteBatchAlpha = null;
            }

            if (m_spriteBatchAdditive != null)
            {
                m_spriteBatchAdditive.Dispose();
                m_spriteBatchAdditive = null;
            }
            m_tileSheetTextures.Clear();
        }

    }
}

New Post: Hey, I need help.

$
0
0
If you're scaling up you cannot really avoid the blurring. I would suggest developing large graphic assets and only scale down as necessary.

Also, I think your code can introduce gaps or overlaps between tiles. I would suggest creating a new XNA rendering device (start off with the one in xTile but give it a new name like ScaledXnaDisplayDevice). You could have it render to a target texture and then render that texture scaled to the required size.

New Post: Hey, I need help.

$
0
0
I solved the problem. I'll leave the code around here, in case you want to use it in you project.
/////////////////////////////////////////////////////////////////////////////
//                                                                         //
//  LICENSE    Microsoft Public License (Ms-PL)                            //
//             http://www.opensource.org/licenses/ms-pl.html               //
//                                                                         //
//  AUTHOR     Colin Vella                                                 //
//                                                                         //
//  CODEBASE   http://tide.codeplex.com                                    //
//                                                                         //
/////////////////////////////////////////////////////////////////////////////

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using xTile.Dimensions;
using xTile.Tiles;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;

namespace xTile.Display
{
    /// <summary>
    /// XNA implementation of the display device. In this implementation,
    /// the tile sheet image sources are loaded from the content pipeline
    /// and alpha and additive blend modes are supported via dedicated
    /// sprite batch instances
    /// </summary>
    public class XnaDisplayDevice : IDisplayDevice
    {
        #region Public Properties

        /// <summary>
        /// Colour modulation property. This is set to White by default
        /// 
        /// NOTE: This property is specific to this implementation
        /// </summary>
        public Color ModulationColour
        {
            get { return m_modulationColour; }
            set { m_modulationColour = value; }
        }

        /// <summary>
        /// Spritebatch instance used for alpha blending
        /// </summary>
        public SpriteBatch SpriteBatchAlpha
        {
            get { return m_spriteBatchAlpha; }
        }

        /// <summary>
        /// Spritebatch instance used for additive blending
        /// </summary>
        public SpriteBatch SpriteBatchAdditive
        {
            get { return m_spriteBatchAdditive; }
        }

        #endregion

        #region Public Methods

        /// <summary>
        /// Constructs an XNA display device using the given content manager and
        /// XNA graphics device
        /// </summary>
        /// <param name="contentManager">Content manager to use for resource access</param>
        /// <param name="graphicsDevice">Underlying XNA graphics device</param>
        /// 
        public float Scal;
        public XnaDisplayDevice(ContentManager contentManager, GraphicsDevice graphicsDevice , float Scale)
        {
            Scal = Scale;
            m_contentManager = contentManager;
            m_graphicsDevice = graphicsDevice;
            m_spriteBatchAlpha = new SpriteBatch(graphicsDevice);
            m_spriteBatchAdditive = new SpriteBatch(graphicsDevice);
            m_tileSheetTextures = new Dictionary<TileSheet, Texture2D>();
            m_tilePosition = new Vector2();
            m_sourceRectangle = new Microsoft.Xna.Framework.Rectangle();
            m_modulationColour = Color.White;
        }

        /// <summary>
        /// Destructs the XNA display device
        /// </summary>
        ~XnaDisplayDevice()
        {
            Dispose(false);
        }

        /// <summary>
        /// Loads the given tile sheet. The image source is loaded from the
        /// content pipeline by stripping any extension from the image source
        /// and using the resulting path into the content pipeline
        /// </summary>
        /// <param name="tileSheet">Tile sheet to load</param>
        public void LoadTileSheet(TileSheet tileSheet)
        {
            Texture2D texture2D = m_contentManager.Load<Texture2D>(tileSheet.ImageSource);
            m_tileSheetTextures[tileSheet] = texture2D;
        }

        /// <summary>
        /// Frees the tile sheet resources
        /// </summary>
        /// <param name="tileSheet">Tile sheet to dispose</param>
        public void DisposeTileSheet(TileSheet tileSheet)
        {
            if (!m_tileSheetTextures.ContainsKey(tileSheet))
                return;

            m_tileSheetTextures.Remove(tileSheet);
        }

        /// <summary>
        /// Prepares the device for rendering
        /// </summary>
        public void BeginScene()
        {
            m_spriteBatchAlpha.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.None, RasterizerState.CullCounterClockwise);
            m_spriteBatchAdditive.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.None, RasterizerState.CullCounterClockwise);
        }
        /// <summary>
        /// Sets the viewport.
        /// 
        /// NOTE: This function is not supported on the Zune platform.
        /// </summary>
        /// <param name="viewport">Viewport to apply</param>
        public void SetViewport(xTile.Dimensions.Rectangle viewport)
        {
            // further clip region within display device's dimensions
            int nMaxWidth = m_graphicsDevice.PresentationParameters.BackBufferWidth;
            int nMaxHeight = m_graphicsDevice.PresentationParameters.BackBufferHeight;

            int viewportLeft = Clamp(viewport.X, 0, nMaxWidth);
            int viewportTop = Clamp(viewport.Y, 0, nMaxHeight);
            int viewportRight = Clamp(viewport.X + viewport.Width, 0, nMaxWidth);
            int viewportBottom = Clamp(viewport.Y + viewport.Height, 0, nMaxHeight);
            int viewportWidth = viewportRight - viewportLeft;
            int viewportHeight = viewportBottom - viewportTop;

            m_graphicsDevice.Viewport = new Viewport(
                viewportLeft, viewportTop, viewportWidth, viewportHeight);
        }

        /// <summary>
        /// Draws the given tile at the given location
        /// </summary>
        /// <param name="tile">Tile to draw</param>
        /// <param name="location">Drawing location</param>
        public void DrawTile(Tile tile, Location location)
        {
            if (tile == null)
                return;

            SpriteBatch spriteBatch = tile.BlendMode == BlendMode.Alpha
                ? m_spriteBatchAlpha : m_spriteBatchAdditive;


            xTile.Dimensions.Rectangle sourceRectangle
                = tile.TileSheet.GetTileImageBounds(tile.TileIndex);

            Texture2D texture2D = m_tileSheetTextures[tile.TileSheet];

            m_tilePosition.X = location.X*Scal ;
            m_tilePosition.Y = location.Y*Scal;

            m_sourceRectangle.X = sourceRectangle.X;
            m_sourceRectangle.Y = sourceRectangle.Y;
            m_sourceRectangle.Width = sourceRectangle.Width;
            m_sourceRectangle.Height = sourceRectangle.Height;

            spriteBatch.Draw(texture2D, m_tilePosition, m_sourceRectangle, m_modulationColour,0.0f, Vector2.Zero, Scal, SpriteEffects.None, 0);
        }

        /// <summary>
        /// Terminates rendering of the current frame and commits drawing instructions
        /// to the underlying XNA graphics pipeline
        /// </summary>
        public void EndScene()
        {
            m_spriteBatchAlpha.End();
            m_spriteBatchAdditive.End();
        }

        #endregion

        #region Private Methods

        private int Clamp(int nValue, int nMin, int nMax)
        {
            return Math.Min(Math.Max(nValue, nMin), nMax);
        }

        #endregion

        #region Private Variables

        private ContentManager m_contentManager;
        private GraphicsDevice m_graphicsDevice;
        private SpriteBatch m_spriteBatchAlpha;
        private SpriteBatch m_spriteBatchAdditive;
        private Dictionary<TileSheet, Texture2D> m_tileSheetTextures;
        private Microsoft.Xna.Framework.Vector2 m_tilePosition;
        private Microsoft.Xna.Framework.Rectangle m_sourceRectangle;
        private Color m_modulationColour;

        #endregion

        /// <summary>
        /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
        /// </summary>
        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }

        /// <summary>
        /// Releases unmanaged and - optionally - managed resources
        /// </summary>
        /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
        private void Dispose(bool disposing)
        {
            if (!disposing)
                return;

            if (m_spriteBatchAlpha != null)
            {
                m_spriteBatchAlpha.Dispose();
                m_spriteBatchAlpha = null;
            }

            if (m_spriteBatchAdditive != null)
            {
                m_spriteBatchAdditive.Dispose();
                m_spriteBatchAdditive = null;
            }
            m_tileSheetTextures.Clear();
        }

    }
}
If you want to know the solution you need to change the method "BeginScene" to " this:
   public void BeginScene()
        {
            m_spriteBatchAlpha.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.None, RasterizerState.CullCounterClockwise);
            m_spriteBatchAdditive.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.None, RasterizerState.CullCounterClockwise);
        }
Thanks for the help.

New Post: Help with collision

$
0
0
I have this error tile index out of bound
I use this code
  public bool getCollision(Vector2 posf,Layer Collision,int TileIndex,float scale, vars v)
        {

            tileLocation = new Location((int)((int)posf.X / 8*3 ), (int)posf.Y / 8*3);
                t = Collision.Tiles[tileLocation];
            //    if (t.TileIndex == 0)
              //      return true;

                return false;
        
           
what is the error?
Viewing all 173 articles
Browse latest View live


Latest Images