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 ... 30 31 [32] 33
466
General / Re: Tile map editor tiled
« on: June 03, 2013, 02:55:51 pm »
Tiled saves maps in an xml format with the extension .tmx. There's a class for loading these here:

http://en.sfml-dev.org/forums/index.php?topic=3023.msg81195#msg81195

467
General / Re: Problem SFML with Box2d
« on: May 30, 2013, 01:37:11 pm »
 #define PPM 30 // Pixel Per Meters

should really be

const int PPM = 30;

although looking at your code you don't seem to be multiplying your sizes by your scale anyway (the box2D manual / FAQ explains why trying to use 1 pixel per metre is a bad thing). Also box2D uses an inverted Y axis to SFML so you're setting your box rectangle 4 pixels from the top of the screen, but the box2D body 4 metres from the bottom. Oh and isn't

float timeStep = 1.0f / 300.0f; // 30fps

actually 300fps?

468
SFML projects / Re: 'Tiled' Tile-map Loader
« on: May 30, 2013, 01:21:02 pm »
Wasn't really sure if I should drag up this old topic or start a new one, but I've completely rewritten this class. I decided to post here to make sure the original author gets credit for his work which started the whole thing in the first place. I've written a post about it here which includes a download with some examples but for brevity here's the readme:

Code: [Select]
This class is designed to load TILED .tmx format maps, compatible with
TILED up to version 0.9.0

http://trederia.blogspot.co.uk/2013/05/tiled-map-loader-for-sfml.html


What's Supported
----------------

Uses pugixml (included) to parse xml
Supports orthogonal maps
Supports isometric maps
Supports conversion between orthogonal and isometric world coords
Parses all types of layers (normal, object and image), layer properties
Parses all type of object, object shapes, types, properties
Option to draw debug output of objects, grid and object names
Supports multiple tile sets, including tsx files
Supports all layer encoding and compression: base64, csv, zlib, gzip and xml (requires zlib library, see /lib directory)



What's not supported / limitations
----------------------------------

Parsing of individual tile properties
Flipping / rotation of sprites
Staggered isometric maps
Tile set images must be in the same directory as tmx/tsx files
To display object names when drawing object debug shapes then you must provide a font
and update MapObject.h


Usage
-----

To quickly get up and running create an instance of the MapLoader class

    tmx::MapLoader ml("path/to/maps");

load a map file

    ml.Load("map.tmx");

and draw it in your main loop

    ml.Draw(renderTarget);


Note that the constructor takes a path to the directory containing the map files as a parameter (with
or without the trailing '/') so that you only need pass the map name to MapLoader::Load(). Currently
all map files (tmx, tsx, images etc) must be in the diretory passed to the constructor.

New maps can be loaded simply by calling the load function again, existing maps will be automatically
unloaded. MapLoader::Load() also returns true on success and false on failure, to aid running the function
in its own thread for example. Conversion functions are provided for converting coordinate spaces between
orthogonal and isometric. For instance MapLoader::OthogonalToIsometric will convert mouse coordinates from
screen space:

    0--------X
    |
    |
    |
    |
    |
    Y

to Isometric space:

      0
     / \
    /   \
   /     \
  /       \
 Y         X

Layer information can be accessed through MapLoader::GetLayers()
   
    bool collision;
    for(auto layer = ml.GetLayers().begin(); layer != ml.GetLayers().end(); ++layer)
    {
        if(layer->name == "Collision")
        {
            for(auto object = layer->objects.begin(); object != layer->objects.end(); ++object)
            {
                collision = object->Contains(point);
            }
        }
    }


For more detailed examples see the source for the demos.



Requirements
------------

pugixml (included)
zlib (http://zlib.net/)
SFML 2.0 (http://sfml-dev.org)


as well as being a rewrite, it contains quite a few enhancements / new features.


This may be a stupid question but SetDrawingBounds does that limit the tilemap to only be drawn on those specific sections of the tilemap itself or with regards to how it is drawn on the screen?

SetDrawingBounds is used to define which tiles are visible, to save drawing tiles which don't need to be drawn. In the new version it is called automatically by Draw using the view of the supplied renderTarget.

469
You could draw the text to a renderTexture the size of the clipping rectangle, then create a sprite from that to draw it to the screen

470
System / Re: Removing a sprite from vector
« on: May 09, 2013, 02:24:31 pm »
But eventually, you still don't want to store a lot of dead objects. Especially in bigger projects, where processing speed and memory usage might become a bottleneck, you want to minimize the amount of active objects.

This is a very good point - I didn't think of that. I was working on the assumption that at the end of a round each invader may be reset to Alive for the beginning of a new round. A good example of why making assumptions is bad :)


471
System / Re: Removing a sprite from vector
« on: May 09, 2013, 09:18:50 am »
Presumably you want to remove the sprite because the invader is 'dead'. Perhaps try using a different approach with a state based class - something like:


enum State
{
    Alive,
    Dying,
    Dead
};

class Invader
{
public:
    State state;
    sf::Sprite sprite;
    Invader(sf::Texture& texture) : state(Alive)
    {
        //set sprite texture
    }

    Update()
    {
        switch state
        {
         case Alive:
         //do sprite movement and collision detection
         case Dying:
         //maybe play a death animation
         case Dead:
        }
    }
};

 

then:

sf::Texture texture;
texture.loadFromFile("texture.png");
std::vector<sf::Sprite>invaders(10, Invader(texture));

for(auto i = invaders.cbegin(); i != invaders.cend(); ++i)
{
    Invader& invader = *i;
    invader.Update();
    if(invader.state != Dead) renderTarget.draw(invader.sprite);
}
 

472
General / Re: Simple Problem With Sprites And Display
« on: April 06, 2013, 04:41:40 pm »
There are prebuilt binaries of the release candidate of SFML2 on the download page if you scroll down below the 1.6 downloads, and a guide to setting up VS here. If you want to build the latest version (which is more or less the finished version of SFML 2) you will have to use CMake, but it's actually pretty easy to use and worth learning. There is a CMake guide on the tutorials page, and CMake will output a VS project file which you can use to compile SFML in Visual Studio.

473
General / Re: Gravity
« on: April 06, 2013, 09:01:36 am »
Gravity is a constant which needs to be applied to your vertical velocity while in the air. You could do something like this:

const float maxY = 50f;
const sf::vector2f gravity(0.f, 5.f);
sf::vector2f velocity(2.f, 5.f);
 

And in your update loop:

if(playerInAir)
{
    player.move(velocity);
    if(velocity.y < maxY) velocity += gravity;
}
 

I've just made the values up as an example, you'll have to match those to your own timescale.
HTH.

474
General / Re: Simple Problem With Sprites And Display
« on: April 06, 2013, 08:43:54 am »
Is there a particular reason you are using 1.6? If you are starting out I highly recommend using SFML2. CircleShape and Sprite both inherit from sf::Drawable. Any classes which inherit from Drawable can be drawn the same way via RenderTarget::Draw(drawable).

475
General / Re: Simple Problem With Sprites And Display
« on: April 05, 2013, 11:20:10 am »
Rendering to the screen works on the principle of page flipping. You have 2 render destinations, one visible on screen, and one off screen. You first clear any existing data from your off screen target (RenderTarget::Clear()), then perform any draw calls (rt.draw(spr1); rt.draw(spr2) etc) before finally flipping or switching the two targets which is done with RenderTarget::Display(). The target you have just drawn to now becomes visible on screen, and the previously visible target is now ready to be cleared and drawn to. SFML / OpenGL handles this all internally so you only need (but are not restricted to) one RendwerWindow object to perform this.

For timing issues you need to look into game loop methods. This is a good starting point but I highly recommend doing some in-depth research via Google before you decide on what would best suit your project. Another version of the game loop could be based on delta time for example, which is often used in games with a lot of physics simulations.

You can also avoid event polling for player input as SFML2 lets you read the state of joysticks and keyboards directly (but you should still poll for window events such as minimize/maximize/close).

476
General / Re: Simple Problem With Sprites And Display
« on: April 03, 2013, 05:07:52 pm »
You need to clear your target each time before you draw to it and display it again

http://www.sfml-dev.org/documentation/1.6/classsf_1_1RenderTarget.php#a125645088d7b2df07599ea36fbb8b87e

477
SFML projects / Re: Threat Level 2.0
« on: March 09, 2013, 09:03:34 am »
Thanks for the replies!

Wow, that is an annoying bug :) I'm guessing the 7570M is the mobile / laptop version of the chipset? I've tested the game on a range of AMD and nVidia desktop cards, but the only laptop version I've tried is my 3560M which won't render the game faster than about 5fps unless I turn the shader off altogether - so I'm guessing it's something to do with mobile chipsets. As far as I can tell what I'm seeing here is that the shader which extracts and blurs the light is rendering to the texture buffer ok, but when rendering the buffer back over the top of the scene either the shader which blends the two images is not working, or the original scene is not being rendered at all. I'm not sure how to debug this without hardware which replicates the problem.

The starfield on the main menu is actually based on this article so, no, it's not created with Thor.

I've updated my original post with a link to a normal zip archive as well as an installer. As for the escape key - if I'm honest I often have my projects set like that so when I do a sneaky bit of coding at work I can quickly close the window if necessary ;) You can still get back to the main menu by pausing the game with P (or Start on the controller) and selecting Quit.

478
SFML projects / Re: Threat Level 2.0
« on: March 08, 2013, 09:35:49 pm »
It's a shader based on this article:
http://fabiensanglard.net/lightScattering/index.php

479
SFML projects / Threat Level 2.0
« on: March 08, 2013, 07:20:57 pm »
This is a remake of one of my first projects using SFML 2.0. Nothing ground breaking, and probably full of bugs but I'm bored of working on it now so I thought I'd share. Uses Thor for particle effects and TGUI for the UI, so credit to the authors of those libraries.

Video:


Download Windows installer.

480
SFML projects / Re: 'Tiled' Tile-map Loader
« on: February 24, 2013, 01:29:26 pm »
Just move the sf::view around your world as you normally would then use TileMap::SetDrawingBounds() to set the drawing rectangle to that of your current view

Pages: 1 ... 30 31 [32] 33
anything