• (3 Pages)
  • +
  • 1
  • 2
  • 3

C++ Tile Engine from Scratch -- Part 4

#16 jaimcm  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 17-October 10

Posted 08 June 2011 - 02:48 AM

Hey Keelx,

Thanks for the confirmation. This is exactly how I had it imagined in my head.

So it's safe to say that the original code leaks and that calling AddTile could potentially make it worse.
Hopefully the author notices this discussion and updates it.

Cheers.
Was This Post Helpful? 0
  • +
  • -

#17 jaimcm  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 17-October 10

Posted 08 June 2011 - 02:59 AM

View Postkeelx, on 06 June 2011 - 10:49 PM, said:

void Level::deleteTile(int x, int y) 
{ 
    if (map[x][y] != NULL)
    {
        delete map[x][y];
        map[x][y] = NULL;
     }
}

//Change addTile to this:
void Level::addTile(int x, int y, Tile *tile)
{
    deleteTile(x, y);
    map[x][y] = tile;
}

//and the destructor:
void ~Level()
{
    for (int i; i<levelwidth; i++)
    {
        for (int j; j<levelheight; j++)
        {
            delete map[i][j];
        }
    }
}



One more thing, incase you update your code to use this.
Update the Destructor to to call 'this.deleteTile(i, j);' instead of 'delete map[i][j];' because the function does a NULL check. I suppose it's no big deal but just good practice...
Was This Post Helpful? 0
  • +
  • -

#18 TheWuurYar  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 09-June 11

Posted 09 June 2011 - 06:30 PM

Thank you for writing this tutorial, but I am getting an error with the code in the zip file.

It compiles fine, but when it tries to run, it gives me the following errors:
Unhandled exception at 0x7c812afb in Engine.exe: Microsoft C++ exception: std::basic_string<char,std::char_traits<char>,std::allocator<char> > at memory location 0x0011f7fc..
and points to the LoadLevel() function in the Level class

Unhandled exception at 0x0041dff1 in Engine.exe: 0xC0000005: Access violation reading location 0x00000020.
and points to rapidxml.hpp

I am a noob programmer, and I wanted to see if anyone knew how to fix this.
Was This Post Helpful? 0
  • +
  • -

#19 Mitix  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 16-June 11

Posted 16 June 2011 - 09:26 AM

Wonderful guide so far! Can't wait for more.

I'm wondering where the black borders around the tiles are coming from and how I might remove them for a more seamless looking tilemap. Are they pixels between the tiles, is the draw method creating the black on the tiles themselves, or is it something else? I've tried adjusting the x/y for the tiles to tighten them up, but that's had no effect.

Thanks
Was This Post Helpful? 0
  • +
  • -

#20 DarkGlitch  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 25
  • Joined: 24-July 11

Posted 26 July 2011 - 07:12 AM

I get an error saying this bit of code:

if((evt.Type == sf::Event::MouseButtonPressed) && (mouseDown == false))
		{
			int x = camera->GetPosition().x + window->GetInput().GetMouseX();
			int y = camera->GetPosition().y + window->GetInput().GetMouseY();
			camera->GoToCenter(x, y);
			mouseDown = true;
		}



Is broken. My compiler says sf::RenderWindow doesn't have any members named GetInput(). And it doesn't. When I open the file there is no GetInput member. Help?

I downloaded the attached code due to my problems I posted in the previous posts for this tutorial.
Was This Post Helpful? 0
  • +
  • -

#21 keelx  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 23-May 11

Posted 26 July 2011 - 07:46 PM

View PostDarkGlitch, on 26 July 2011 - 07:12 AM, said:

I get an error saying this bit of code:

if((evt.Type == sf::Event::MouseButtonPressed) && (mouseDown == false))
		{
			int x = camera->GetPosition().x + window->GetInput().GetMouseX();
			int y = camera->GetPosition().y + window->GetInput().GetMouseY();
			camera->GoToCenter(x, y);
			mouseDown = true;
		}



Is broken. My compiler says sf::RenderWindow doesn't have any members named GetInput(). And it doesn't. When I open the file there is no GetInput member. Help?

I downloaded the attached code due to my problems I posted in the previous posts for this tutorial.


Change window->GetInput to window->GetEvent.
Was This Post Helpful? 0
  • +
  • -

#22 DarkGlitch  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 25
  • Joined: 24-July 11

Posted 27 July 2011 - 02:47 AM

Ok just to be sure, this is using SFML 2.0 right? I downloaded and installed SFML 2.0 to use with this tutorial but there is no GetInput or GetEvent for that matter. There's a whole bunch of other Get's but none of them have anything to do with input.
Was This Post Helpful? 0
  • +
  • -

#23 DarkGlitch  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 25
  • Joined: 24-July 11

Posted 27 July 2011 - 03:05 AM

For some reason I can't edit my post so check this out: Changed what was there to this and now it compiles.

if((evt.Type == sf::Event::MouseButtonPressed) && (mouseDown == false))
		{
			int x = camera->GetPosition().x + evt.MouseMove.X;
			int y = camera->GetPosition().y + evt.MouseMove.Y;
			camera->GoToCenter(x, y);
			mouseDown = true;
		}


However, now I get a bad pointer error. The debugger says xmlContents is a bad pointer. Why would it say that if that isn't a pointer at all?
Was This Post Helpful? 0
  • +
  • -

#24 keelx  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 23-May 11

Posted 27 July 2011 - 07:16 AM

View PostDarkGlitch, on 27 July 2011 - 03:05 AM, said:

For some reason I can't edit my post so check this out: Changed what was there to this and now it compiles.

if((evt.Type == sf::Event::MouseButtonPressed) && (mouseDown == false))
		{
			int x = camera->GetPosition().x + evt.MouseMove.X;
			int y = camera->GetPosition().y + evt.MouseMove.Y;
			camera->GoToCenter(x, y);
			mouseDown = true;
		}


However, now I get a bad pointer error. The debugger says xmlContents is a bad pointer. Why would it say that if that isn't a pointer at all?

Hm... I really can't be sure. I'm using SFML 1.6, and it with a few changes (i think this tutorial uses 1.3 or 1.4), it worked just fine... Can you print out the exact error message?
Was This Post Helpful? 0
  • +
  • -

#25 bluewood  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 28-July 11

Posted 28 July 2011 - 05:18 AM

View Postkeelx, on 26 July 2011 - 07:46 PM, said:

View PostDarkGlitch, on 26 July 2011 - 07:12 AM, said:

I get an error saying this bit of code:

if((evt.Type == sf::Event::MouseButtonPressed) && (mouseDown == false))
		{
			int x = camera->GetPosition().x + window->GetInput().GetMouseX();
			int y = camera->GetPosition().y + window->GetInput().GetMouseY();
			camera->GoToCenter(x, y);
			mouseDown = true;
		}



Is broken. My compiler says sf::RenderWindow doesn't have any members named GetInput(). And it doesn't. When I open the file there is no GetInput member. Help?

I downloaded the attached code due to my problems I posted in the previous posts for this tutorial.


Change window->GetInput to window->GetEvent.


I suppose you're talking about evt.MouseButton. Put it like this and it should work (I used another method on part 3, but tested and seemed fine).
if((evt.Type == sf::Event::MouseButtonPressed) && (mouseDown == false))
{
	int x = camera->GetPosition().x + evt.MouseButton.X;
	int y = camera->GetPosition().y + evt.MouseButton.Y;
	camera->GoToCenter(x, y);
	mouseDown = true;
}



There is also another solution. I had this problem on part 3, so I read the documentation for SFML 2.0 here (bro tip, always read the documentation first when searching for an API function :P) and there is another way (this is what I'm currently using):
if((evt.Type == sf::Event::MouseButtonPressed) && (mouseDown == false))
{
	sf::Vector2i mousePos = sf::Mouse::GetPosition(*window);
	int x = camera->getPosition().x + mousePos.x;
	int y = camera->getPosition().y + mousePos.y;
	camera->goToCenter(x, y);
	mouseDown = true;
}



Also, don't know if anyone else noticed it too but the tutorial doesn't warn about scrolling near the map limits. Be sure to handle that or you'll be having some unexpected crashes.
Was This Post Helpful? 0
  • +
  • -

#26 DarkGlitch  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 25
  • Joined: 24-July 11

Posted 28 July 2011 - 07:27 AM

That call I posted was found in the SFML 2.0 API. I searched under sf::Event since I assumed thats what the OP was trying to use.
Was This Post Helpful? 0
  • +
  • -

#27 sl14k  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 11-August 11

Posted 16 August 2011 - 06:01 PM

Hi ,

Great tutorial im using it for help with my msc dissertation. I wanted to ask if the next part will be coming any time soon.
Please keep up the good work its great help for people like me ive been programming since a year.


Thanks
Was This Post Helpful? 0
  • +
  • -

#28 SinisterRainbow  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 29-August 11

Posted 29 August 2011 - 08:28 AM

I really hope the author continues this as well, it's a great starting point for would-be gamers and is well written. There are so few modern game intros that are done even remotely well, and this could be tops if it were maintained/responded to.
Was This Post Helpful? 0
  • +
  • -

#29 sNIk  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 22-September 11

Posted 22 September 2011 - 03:37 AM

good work! looking forward for part 5. :)
Was This Post Helpful? 0
  • +
  • -

#30 TheKaosNano  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 18-July 12

Posted 18 July 2012 - 04:59 PM

View PostTheWuurYar, on 09 June 2011 - 06:30 PM, said:

Thank you for writing this tutorial, but I am getting an error with the code in the zip file.

It compiles fine, but when it tries to run, it gives me the following errors:
Unhandled exception at 0x7c812afb in Engine.exe: Microsoft C++ exception: std::basic_string<char,std::char_traits<char>,std::allocator<char> > at memory location 0x0011f7fc..
and points to the LoadLevel() function in the Level class

Unhandled exception at 0x0041dff1 in Engine.exe: 0xC0000005: Access violation reading location 0x00000020.
and points to rapidxml.hpp

I am a noob programmer, and I wanted to see if anyone knew how to fix this.



I need help with this too, its urgent, please help ASAP.
Was This Post Helpful? 0
  • +
  • -

  • (3 Pages)
  • +
  • 1
  • 2
  • 3