Comments (6)
Hi, as you 've closed this I'll assume you found a solution - there are a couple of links you can check out though:
http://trederia.blogspot.co.uk/2013/10/collision-detection-with-tiled-maps.html
http://trederia.blogspot.co.uk/2016/02/2d-physics-101-pong.html
Alternatively my SFML frame work xygine has built in tmx/collision support (check the 2D tilemap demo in the included example)
from sfml-tmxloader.
Yeah, I solved it and thanks for the links 👍 But if you solve one problem, another one pops up, hehe...
So, right now it's detecting colission with the player sprite and the platforms, so I can jump on them and everything works fine that way. But, as it seems, the colission is constantly checking all of the objects in the layer, something which could be fixed by using a quadtree, which you mentioned in your blog and on the homepage of this repository.
So I simply did:
ml.UpdateQuadTree(sf::FloatRect(0.f, 0.f, 800.f, 600.f));
std::vector<tmx::MapObject*> objects = ml.QueryQuadTree(player.getPlayer().getGlobalBounds());
and then I check for colission with the objects in the layer. But it seems like it's not working as expected as the debug text prints out a mix of 'true' (if colission occur) and 'false' (colission didn't occur), when it should printout only 'true' (if I'm intersecting with a platform) as I should only be checking with each platform at a time.
//Check for colission
for (auto& layer : layers)
{
if (layer.type == tmx::ObjectGroup)
{
for (auto& obj : layer.objects)
{
if (layer.name == "Collide")
{
if (obj.GetAABB().intersects(player.getPlayer().getGlobalBounds()))
{
std::cout << "True" << std::endl;
whileJump = false;
player.accelarationValue = 0;
}
else
std::cout << "False" << std::endl;
}
}
}
}
Do you have any ideas? @fallahn
from sfml-tmxloader.
No, that sound right. If a layer or quad tree query returns 3 platforms and you only intersect one, then the output would be
true
false
false
or similar, as you're only colliding with one of the 3 platforms. Try also outputting the layer object count, and see if it matches up with the number of true/false statements in the console
from sfml-tmxloader.
Hmm, oh that sounds quite right, yeah. But still, I'm having an issue how to make the player unable to continue walking when he's actually in midair, which is actually why I wanted it to only print 'true' when I was intersecting with one platform. Because if it would, I could have a boolean in there which would turn true if I was intersecting and then false if I wouldn't intersect. Then I could use this boolean to restrict the player movement and simply let the player fall free if not on the platform. But as it is now, this boolean would switch from true to false even if I was on one single platform, making this approach useless. What would be the recommended approach? :) @fallahn
from sfml-tmxloader.
This might help :)
from sfml-tmxloader.
Yep, I have to look into the art of game design a bit more. Thanks for the help anyways and the effort you put into the library.
from sfml-tmxloader.
Related Issues (20)
- Thanks Matt! HOT 3
- No compatibility with AnimatedSprite class? HOT 2
- MapObject setVisible ? HOT 3
- Terrain Tiled tmx load HOT 3
- Strange culling HOT 4
- Collision issues HOT 7
- Animated Tile with Tiled Editor HOT 4
- layer->tiles doesn't give tiles from layers HOT 3
- GetLayers() doesn't work as spected HOT 4
- Simple test fails: call for help
- Unresolved external symbol HOT 12
- Can't draw map properly if it wasn't the the first one the maploader loaded. HOT 4
- Collisions detected incorrectly due to AABB having incorrect height (2x what it should be) HOT 1
- Isometric causing weird issues HOT 5
- unresolved symbol sf::Sprite::Draw in MapLoaderPublic.obj? HOT 1
- Isometric Layering offset not happening? HOT 22
- Missing vtable HOT 3
- Can not build tmxsfml project as I've set link options correctly HOT 1
- Doesn't build woth MinGW Makefiles HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sfml-tmxloader.