Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - fallahn

Pages: 1 ... 32 33 [34]
496
SFML projects / Re: 'Tiled' Tile-map Loader
« on: October 10, 2012, 11:32:17 pm »
In the version I posted you can create 'solid' objects by going to edit->preferences->object types in Tiled and adding a new type called 'solid'. Then if you create a rectangular object in Tiled you can right click on it, go to properties and set its type to 'solid'. The map loader will then find any objects with this type and create a sf::rect with the object's dimensions and add it to a vector named m_solidObjects (this is all existing functionality, not anything I added and so should be valid in the 1.6 version). This you can iterate over and call each rectangle's contains() function passing a vector2f (player position or whatever) as a parameter to check for collision. I've more recently added a contains() function to the object class too, which will let you check any objects in the m_objects vector which contain a list of poly points to see if the polygonal shape contains a point specified via a vector2f:

Code: [Select]
bool Object::Contains(const sf::Vector2f point)
{
//only test if we have enough points to create at least a triangle
if(polypoints.size() < 3) return false;
//else see if the point is inside the poly
unsigned int i, j;
bool result = false;
for (i = 0, j = polypoints.size() - 1; i < polypoints.size(); j = i++)
{
if (((polypoints[i].y > point.y) != (polypoints[j].y > point.y)) &&
(point.x < (polypoints[j].x - polypoints[i].x) * (point.y - polypoints[i].y) / (polypoints[j].y - polypoints[i].y) + polypoints[i].x))
result = !result;
}
return result;
}

which works by casting a ray through the polygon and counting the number of times it enters and exits it. If the number is odd then the point is inside, even it's outside.

497
System / Re: Input/output with files help
« on: September 18, 2012, 10:11:20 pm »
You could create a struct to hold player data which you load from file at startup, modify during runtime, and write out to a file when necessary. This should be a good place to start.

498
SFML projects / Re: 'Tiled' Tile-map Loader
« on: September 18, 2012, 08:26:55 pm »
The object class just stores the data parsed from the object tags in the tmx file. All I've added to the original class is parsing of polygon and polyline points and storing them as sf::vector2i so you can draw out shapes or whatever you need using sfml. Now you mention it, no, it won't draw objects that contain pictures, although I did add parsing of objects with tile GIDs, so it wouldn't take much to update the draw method to draw the corresponding tile. This would probably be more useful if the class supported multiple tilemaps I guess. There is still much which could be added but I'm not sure if I'll do it myself unless I need something for a specific reason. I really just wanted to share the zlib compatibility as it was quite tricky to work out, and it's about time I gave something back to a very helpful community :)

499
SFML projects / Re: 'Tiled' Tile-map Loader
« on: September 18, 2012, 10:57:26 am »
I've been working on this for one of my own projects, so I thought I'd share what I've done:

Things it now does:
Works with SFML 2.0
Supports base64 and CSV encoded maps
Supports zlib and gzip compressed maps
Error handling when trying to find a non-existent object property
Error handling when trying to find a non-existent object
Support for *almost* all attribute tags in the latest version of the tmx format, including transparency colour, layer visibilty, margin and spacing (tested to work with the desert map example which comes with Tiled)
Object class now stores polygon and polyline objects as a vector of sf::vector2i points
Previously loaded maps are automatically cleared when loading a new map so a single instance of the class can be used to load multiple maps (successively, not at the same time)

What it still doesnt do:
No isometric map support - I'm not interested in this for my current project so unlikely I'll add it
No tsx tilemap support, only image file support - images must be in the same directory as the tmx file
Still only one tilemap currently supported
Not completely error safe because I haven't tested every outcome - missing attributes or corrupt tmx files may cause an assertion error.


To use zlib and gzip compressed maps you need to link the zlib library to your project. On debian you can apt-get install zlib1g-dev or download the source and configure/make/install (tested on Ubuntu 11.04 with zlib 1.2.7). Using VC on windows is a bit trickier but you can find a tutorial here (tested with VC10 on XP and Vista to work with static lib using 1.2.7). Presumably you can also do a configure/make/install with MinGW but I haven't tried.

You can download the files here.

500
Graphics / Re: Trouble adding spacing and margin to Tiled map loader
« on: September 17, 2012, 10:36:46 am »
Hey. I've been working on this class for one of my own projects to add fuller support for the tmx format. Currently I have most of the tags supported (transparency, visibilty, spacing etc), base64 decoding and zlib compression - when I have support for polygons completed I shall share what I have. To solve the margin problem I did this:

Code: [Select]
//check tileset spacing if it exists
m_spacing = (tilesetElement->Attribute("spacing")) ? atoi(tilesetElement->Attribute("spacing")) : 0;
m_margin = (tilesetElement->Attribute("margin")) ? atoi(tilesetElement->Attribute("margin")) : 0;

    //tiles/subrects are counted from 0, left to right, top to bottom
    for (int y = 0; y < rows; y++)
    {
        for (int x = 0; x < columns; x++)
        {
            sf::Rect <int> rect; //must account for any spacing or margin on the tileset
            rect.top = y * (m_tileHeight + m_spacing);
    rect.top += m_margin;
    rect.height = m_tileHeight;
            rect.left = x * (m_tileWidth + m_spacing);
    rect.left += m_spacing;
            rect.width = m_tileWidth;
            subRects.push_back(rect);
        }
    }

HTH

501
SFML projects / Re: Thor 2.0
« on: May 08, 2012, 05:06:04 pm »
I've been thinking about passing RenderStates via the draw method, and I thought maybe it would be better to pass a pointer to a RenderStates object at construction of a particle system (like you currently do with a texture). That way you can set the texture/blendmode/shader once for the whole particle system, and don't have to worry about overriding the texture when drawing. For instance I use BlendAdd for fire particles, BlendMultiply for a smoke particle system and I could also create a system with a glow shader for making lasers and things. Just an idea.

I'm going to try deriving my own affector tonight too... I had an idea for one which scales particles based on their velocity so slower particles look smaller and therefore further away - a kind of fake 'depth' effect.  We'll see how it goes :)

502
SFML projects / Re: Thor 2.0
« on: May 05, 2012, 09:20:43 pm »
OK, I shall have a think about how I might do it. I didn't define any of my own distributions (yet) but I like the concept - it's a great way to quickly and easily add variations to a particle system. It definitely beats any of my personal solutions which would involve things like
#define RANDOM_SPREAD rand() % screenWidth, rand() % screenHeight
(ok not a great example but you see what I mean) which I'd normally come up with - I'm a C programmer really, mainly doing embedded software and I'm using SFML to write *fun* things and learn C++ :)  It's a very elegant solution.

503
SFML projects / Re: Thor 2.0
« on: May 05, 2012, 05:51:00 pm »
I was just wondering - is it possible to tie emitters to particles? For example if I wanted to explode a vehicle could I use a particle system to emit 4 or 5 particles as 'chunks' of the vehicle, then have each of those particles emit their own smoke and flame? Perhaps this is a reason to use GetPosition() on particles? :) I really like the idea of Distributions by the way, I've created some really good looking (if I say so myself ;) ) smoke effects this afternoon

504
SFML projects / Re: Thor 2.0
« on: May 05, 2012, 11:26:14 am »
Hey there!
I downloaded Thor yesterday and have been playing with it for a while, it's a great lib :) One thing that struck me though was that I felt it was a bit inflexible to render particle systems to a RenderWindow only, so I changed
Code: [Select]
ParticleSystem::draw(sf::RenderWindow& renderWindow) to
Code: [Select]
ParticleSystem::draw(sf::RenderTarget& renderTarget, sf::RenderStates& renderStates)This way I can render a particle system to a RenderTexture as well as a RenderWindow, change the BlendMode and use shaders for post FX during off screen rendering. Sorry if I've missed something and there's already a better way to do this, but I've only been using Thor for a few hours. I will definitely being using this lib a lot :D

Pages: 1 ... 32 33 [34]
anything