Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


Key

Member Since 12 Jul 2011
Offline Last Active Aug 08 2012 11:15 PM

Topics I've Started

Code not running and image not loading

08 August 2012 - 12:26 PM

I posted my problem over at stackoverflow, but haven't found the solution yet.

private void LoadImageList()
    {
	    string filepath = Application.StartupPath + @"\Content\Textures\Tiles\PlatformTiles.png";
	    Bitmap tileSheet = new Bitmap(filepath);
	    int tilecount = 0;
	    for (int y = 0; y < tileSheet.Height / TileGrid.TileHeight; y++)
	    {
		    for (int x = 0; x < tileSheet.Width / TileGrid.TileWidth; x++)
		    {
			    Bitmap newBitmap = tileSheet.Clone(
				    new System.Drawing.Rectangle(
					    x * TileGrid.TileWidth,
					    y * TileGrid.TileHeight,
					    TileGrid.TileWidth,
					    TileGrid.TileHeight),
					    System.Drawing.Imaging.PixelFormat.DontCare);
			    imgListTiles.Images.Add(newBitmap);
			    string itemName = "";
			    if (tilecount == 0)
			    {
				    itemName = "Empty";
			    }
			    if (tilecount == 1)
			    {
				    itemName = "White";
			    }
			    listTiles.Items.Add(new ListViewItem(itemName, tilecount++));
		    }
	    }
    }

All I did was update PlatformTiles.png with a newer one and the next time I ran the program it doesn't load. I placed a breakpoint at int tilecount = 0; and it doesn't ever reach it. Everything after it doesn't run either. Any ideas? I used the original PlaformTiles.png and it doesn't work either.

Help with isometric tile movement

07 July 2012 - 08:32 PM

I've been trying to move a sprite on a tile map, but I'm having some difficulty working things out. I want the sprite to move from tile to tile.

Problems:
  • Sprite moves in a zig-zag manner in-between tiles
  • I can move the sprite on the x or y axis in a straight line, but I can't get it to move on the x axis then on the y axis, ie. moving a tile below would require moving either on the x towards the right or on the y towards the left then move on y towards left or on the x towards the right respectively
Code:
public void HandleInput(TileGrid grid, SpriteAnimation playerSprite, InputHandler input)
		{
			Vector2 selectionLocation = Camera.ScreenToWorld(new Vector2(Mouse.GetState().X, Mouse.GetState().Y));
			Point selectionPoint = grid.WorldToMapCell(new Point((int)selectionLocation.X, (int)selectionLocation.Y));
			int selectionOffset = 0;
			if ((selectionPoint.Y) % 2 == 1)
				selectionOffset = Tile.OddRowOffset;
			if (input.leftClick() && canMove == true)
			{
				desiredPosition.X = (selectionPoint.X * 64) + 32 + selectionOffset;
				desiredPosition.Y = (selectionPoint.Y * 16) + 48;
			}
			if (playerSprite.Position != desiredPosition)
			{
				canMove = false;
				if ((playerSprite.Position.X > desiredPosition.X) && (playerSprite.Position.Y > desiredPosition.Y))
				{
					MoveNorthWest();
				}
				else if ((playerSprite.Position.X > desiredPosition.X) && (playerSprite.Position.Y < desiredPosition.Y))
				{
					MoveSouthWest();
				}
				else if ((playerSprite.Position.X < desiredPosition.X) && (playerSprite.Position.Y > desiredPosition.Y))
				{
					MoveNorthEast();
				}
				else if ((playerSprite.Position.X < desiredPosition.X) && (playerSprite.Position.Y < desiredPosition.Y))
				{
					MoveSouthEast();
				}		  
			}
			else
			{
				moveDir = Vector2.Zero;
			}
			if (grid.GetCellAtWorldPoint(playerSprite.Position + moveDir).Collidable == true)
			{
				moveDir = Vector2.Zero;
			}
			if (Math.Abs(grid.GetOverallDepth(playerSprite.Position) - grid.GetOverallDepth(playerSprite.Position + moveDir)) > 10)
			{
				moveDir = Vector2.Zero;
			}
			if (moveDir.Length() != 0)
			{
				playerSprite.MoveBy((int)moveDir.X, (int)moveDir.Y);
				if (playerSprite.CurrentAnimation != animation)
					playerSprite.CurrentAnimation = animation;
			}
			else
			{
				playerSprite.CurrentAnimation = "Idle" + playerSprite.CurrentAnimation.Substring(4);
				canMove = true;
			}
		}


		public void MoveNorthEast()
		{
			moveDir = new Vector2(2, -1);
			animation = "WalkNorthEast";
		}

		public void MoveNorthWest()
		{
			moveDir = new Vector2(-2, -1);
			animation = "WalkNorthWest";
		}

		public void MoveSouthEast()
		{
			moveDir = new Vector2(2, 1);
			animation = "WalkSouthEast";
		}

		public void MoveSouthWest()
		{
			moveDir = new Vector2(-2, 1);
			animation = "WalkSouthWest";
		}

Creating a camera class

04 June 2012 - 02:15 PM

I'm in the process of porting my C#/XNA game to Java/LWJGL, but a few things I can't figure out.
I'm using a Vector2f from LWJGL for a Vector2, but what are the equivalents of a Vector2 and the get/set accessors and the keyword value in Java with LWJGL?


		#region Declarations
		private static Vector2 position = Vector2.Zero;
		private static Vector2 viewPortSize = Vector2.Zero;
		private static Rectangle worldBoundary = new Rectangle(0, 0, 0, 0);
		#endregion
		#region Properties
		public static Vector2 Position
		{
			get { return position; }
			set
			{
				position = new Vector2(
					MathHelper.Clamp(value.X, worldBoundary.X, worldBoundary.Width - ViewPortWidth),
					MathHelper.Clamp(value.Y, worldBoundary.Y, worldBoundary.Height - ViewPortHeight));
			}
		}

Converting C# to Java

02 June 2012 - 07:04 PM

I'm attempting to convert my C# project that I have been working on to Java.
I'll have more questions as I am converting it, but what is the Java equivalent of a Vector2 in C#? Will it require a framework or API?

Best approach to loading and saving game data?

05 April 2012 - 12:40 PM

I've been doing some research on ways to read and write data but don't know which is the best way to go about it.

As for the writing data how do I go about saving? I went and looked through other game's save files. Why are some not in plain text? I assume they're encrypted or need to be opened with an appropriate editor.

For loading from a file, I could create some values in a text file and have it read to the game but what if I wanted to add descriptions or commentary to the file so I know what values are which and not have it read by the game? I thought about using Regular Expressions to cut out the stuff I don't need when the game is reading but is that doing more than I really need to? I'm just throwing ideas around and hoping to get some feedback.

PARTNERS