bluewood's Profile
Reputation: 0
Apprentice
- Group:
- New Members
- Active Posts:
- 2 (0 per day)
- Joined:
- 28-July 11
- Profile Views:
- 172
- Last Active:
Aug 23 2011 01:57 PM- Currently:
- Offline
Previous Fields
- Dream Kudos:
- 0
Posts I've Made
-
In Topic: C++ Tile Engine from Scratch -- Part 3
Posted 28 Jul 2011
Your tutorial is nice, but you're missing some potential pitfalls:
- you create several instances of Tile objects dynamically, but you never delete them anywhere in your code, which could lead to memory leaks;
- let's say we have a map smaller than the screen we're using (like in Pokemon, for example) - the draw tiles loop in Engine::RenderFrame() doesn't take into account the actual size of the map (which could be really small), only the screen resolution - you'll be accessing invalid memory regions;
- you don't place restrictions on the Camera target values - if someone tried to click "indefinitely" to reach the edge of the map, eventually target values become invalid and you'll be accessing invalid memory regions.
More than code about tiling engines, I think everyone would appreciate if you put code that avoids problems like memory leaks and accessing invalid memory addresses.
But keep up the good work. Started this tutorial yesterday and I can't wait for the other parts
PS: Try replacing the operator[] with function Vector::at() when you're accessing vector positions. Invalid memory access errors aren't masked this way and are easier to detect. - you create several instances of Tile objects dynamically, but you never delete them anywhere in your code, which could lead to memory leaks;
-
In Topic: C++ Tile Engine from Scratch -- Part 4
Posted 28 Jul 2011
keelx, on 26 July 2011 - 07:46 PM, said:
DarkGlitch, 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
) 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.
My Information
- Member Title:
- New D.I.C Head
- Age:
- Age Unknown
- Birthday:
- Birthday Unknown
- Gender:
Contact Information
- E-mail:
- Click here to e-mail me
Friends
bluewood hasn't added any friends yet.
|
|


Find Topics
Find Posts
View Reputation Given
|
Comments
bluewood has no profile comments yet. Why not say hello?