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.

Topics - OutlawLee

Pages: [1] 2
SFML projects / [Beginner] 2d Tile Map Editor + source
« on: December 30, 2013, 03:31:00 pm »
Hello, i made a simple map editor that i wanted to share. Im a beginner in c++, and programming in general, so thats why i wanted a opinion on this code i wrote.

I attached a rar so u can download the program. And i attached another one with the code.

If you want to the code, you are free to use it as you wish.

I had to upload the rar with exe on other site since its too big for attachment.

--------------- GENERAL: HOW TO USE ----------------------



R - Create Layer
T - Delete layer
Q - Previous Layer
E - Next Layer

C - Set Tile Collision
X - Hide Tile Collision Indicators

G - Hide Tile (Set visibility)
H - Hide Layer (Set layer visibility)

L - Save Map

W A S D - move through palette
UP DOWN LEFT RIGHT - navigate through map

Map Editor

Good practices, avoiding bugs or unexpected behavior:

- Map size (x and y) should be dividable with the tile size.
- Saving often is advisible, and it only takes a fraction of a second.
- Found a bug ? Write/Report it immediatly.


- You can create unlimited number of tiles.
- All tiles in a newly created layer will be transparent but VISIBLE. (Transparent tile from tileset)
- You can only delete the last layer unlike creating, and the active layer has to be that one also.
- Hidden layer, hidden transparent tile might at first look can seem like something is bugged, but likely is not.
- Its save to close anyway once you save the map.

Known bugs:
- None found.

To-Do (top->down priority):

- Fix new bugs if found.
- Make it more exepction-safe. (e.g. typing the map name with space inbetween will not crash the editor
- New brushes for faster editing. (Rectangle 2x2 and bigger sizes)

Pls try to explain the mistakes i made, tell me if i made some grave mistakes that i should fix.

im also having trouble finding the right coding style (cant decide if i should put an underscore in parameters and similar)

code can crash if u do something you re not supposed, or type random stuff in console when asked something else.


Graphics / Best way to draw projectiles ? [SOLVED]
« on: October 19, 2012, 10:43:17 pm »
Im making a game like space invaders, you fly a spaceship and destroy enemies. I got the player spaceship loading and displaying and moving. Now i want to make projectiles, but i cant get it to work, how should i do it ?
projectiles from your spaceship obviously.

I tried something but kinda failed:

Inside of a class:

static sf::Texture _projectileTexture;
static sf::Sprite _projectileSprite[30];

inside of a .cpp

for(int n = 0; n < 30; n++)

for(int n = 0; n < curProjectile;  n++)

how i try to make new projectiles:

if(inProjectile == true)
        curProjectile ++;
        _projectileSprite[curProjectile].setPosition(pProjectile[curProjectile].posX, pProjectile[curProjectile].posY);

General declarations:

int curProjectile = -1;

struct Projectile
        float posX;
        float posY;
        bool alive;
Projectile *pProjectile = new Projectile[30];

running in main so i can initialize

for(int n(0); n < 30; n++)
        pProjectile[n].posX = 20;
        pProjectile[n].posY = 20;

suggestions please :D

Let me explain here what i did:

1. Load the projectile .png into a texture.
2. Load the texture into 30 sprite projectiles. (hoping that it will be enough)
3. Create with the Struct 30 projectiles.
4. Create/Set position of each one as they get shot.

System / Input/output with files help
« on: September 18, 2012, 06:30:26 pm »
I am trying to save player data to a txt file in the follownig format, but the problem is that i dont know how to save a single stat(ex. playerclass), and i dont know how to load into variables. Help!!

void Engine::SaveCharacterData(string PlayerName, int PlayerGender, int PlayerClass, int PlayerSkin)
    ofstream myfile ("Player1.txt");
    if (myfile.is_open())
        myfile <<"Name:"<< PlayerName;
        myfile <<"Gender:"<< PlayerGender;
        myfile <<"Class:"<< PlayerClass;
        myfile <<"Skin:"<< PlayerSkin;
        cout << "Unable to open file";

void Engine::SaveCharacterClass(int PlayerClass)
    string curLine;

    ofstream myfile ("Resources/Saved_data/Player1.txt");
    if (myfile.is_open())
        getline(myfile, curLine);
        if(curLine == "Class=")
            myfile << PlayerClass;
        cout << "Unable to open file";

Graphics / Trouble adding spacing and margin to Tiled map loader
« on: September 09, 2012, 04:13:08 pm »
I took "Tiled Map Loader" from Walker which is 1.6 and converted it to sfml 2. Works perfectly but now i want to implement spacing margin of the tileset.

int columns = tilesetTexture.getSize().x / tileWidth;
    int rows = tilesetTexture.getSize().y / tileHeight;

tilesetTexture is obviously the texture i loaded my tileset image into.
Now i should somehow add spacing and margin into consideration.

I managed to load spacing and margins from xml file into two variables: spacing, margin. But how to implement them into the calculations ? Somekind of for loop ? Plz show me how.

obj\Release\game.o:game.cpp|| undefined reference to `TitleScreen::Show(sf::RenderWindow&)'|
||=== Build finished: 1 errors, 0 warnings ===|

#pragma once
#include "SFML\Window.hpp"
#include "SFML\Graphics.hpp"
#include <list>

class MainMenu

        enum MenuResult { Nothing, Exit, Play };

        struct MenuItem
                        sf::Rect<int> rect;
                        MenuResult action;

        MenuResult Show(sf::RenderWindow& window);

        MenuResult GetMenuResponse(sf::RenderWindow& window);
        MenuResult HandleClick(sf::Vector2i position);
        std::list<MenuItem> _menuItems;

#include "titlemenu.h"

MainMenu::MenuResult MainMenu::Show(sf::RenderWindow& window)

        //Load menu image from file
        sf::Texture texture;
        sf::Sprite sprite(texture);

        //Setup clickable regions

        //Play menu item coordinates
        MenuItem playButton;
        playButton.rect.top= 145;
        playButton.rect.height = 380;
        playButton.rect.left = 0;
        playButton.rect.width = 1023;
        playButton.action = Play;

        //Exit menu item coordinates
        MenuItem exitButton;
        exitButton.rect.top = 383;
        exitButton.rect.height = 560;
        exitButton.rect.left = 0;
        exitButton.rect.width = 1023;
        exitButton.action = Exit;



        return GetMenuResponse(window);

MainMenu::MenuResult MainMenu::HandleClick(sf::Vector2i position)
        std::list<MenuItem>::iterator it;

        for ( it = _menuItems.begin(); it != _menuItems.end(); it++)
                sf::Rect<int> menuItemRect = (*it).rect;
                if( menuItemRect.height > position.y
                        && menuItemRect.top < position.y
                        && menuItemRect.left < position.x
                        && menuItemRect.width > position.x)
                                return (*it).action;

        return Nothing;

MainMenu::MenuResult  MainMenu::GetMenuResponse(sf::RenderWindow& window)
        sf::Event menuEvent;
        sf::Mouse mouse;
        sf::Vector2i position = mouse.getPosition(window);
        while(42 != 43)
                        if (mouse.isButtonPressed(mouse.Left))
                                return HandleClick(position);
                        if(menuEvent.type == sf::Event::Closed)
                                return Exit;

I can remove the problem by return 1 instead of Handle Click(position);
return HandleClick(position);

Where is the problem ?

General / Cant compile release mode
« on: May 16, 2012, 09:03:33 pm »
I was doing everything in debug and then i saw some topic where laurent says that the release mode is faster so i changed everything to release mode.
(removed the -d from libs, set the include and lib folder again)
Everything would work normally if i didnt have tinyxml but i have it:
Code: [Select]
1>------ Build started: Project: LegendsReborn, Configuration: Release Win32 ------
1>  level.cpp
1>level.cpp(148): warning C4244: 'argument' : conversion from 'double' to 'sf::Uint8', possible loss of data
1>level.obj : error LNK2001: unresolved external symbol "private: static struct TiXmlString::Rep TiXmlString::nullrep_" (?nullrep_@TiXmlString@@0URep@1@A)
1>level.obj : error LNK2001: unresolved external symbol "public: class TiXmlElement const * __thiscall TiXmlNode::NextSiblingElement(char const *)const " (?NextSiblingElement@TiXmlNode@@QBEPBVTiXmlElement@@PBD@Z)
1>level.obj : error LNK2001: unresolved external symbol "public: class TiXmlElement const * __thiscall TiXmlNode::FirstChildElement(char const *)const " (?FirstChildElement@TiXmlNode@@QBEPBVTiXmlElement@@PBD@Z)
1>level.obj : error LNK2001: unresolved external symbol "public: virtual __thiscall TiXmlNode::~TiXmlNode(void)" (??1TiXmlNode@@UAE@XZ)
1>level.obj : error LNK2001: unresolved external symbol "public: virtual void __thiscall TiXmlDocument::Print(struct _iobuf *,int)const " (?Print@TiXmlDocument@@UBEXPAU_iobuf@@H@Z)
1>level.obj : error LNK2001: unresolved external symbol "public: __thiscall TiXmlDocument::TiXmlDocument(char const *)" (??0TiXmlDocument@@QAE@PBD@Z)
1>level.obj : error LNK2001: unresolved external symbol "public: bool __thiscall TiXmlDocument::LoadFile(enum TiXmlEncoding)" (?LoadFile@TiXmlDocument@@QAE_NW4TiXmlEncoding@@@Z)
1>level.obj : error LNK2001: unresolved external symbol "public: char const * __thiscall TiXmlElement::Attribute(char const *)const " (?Attribute@TiXmlElement@@QBEPBDPBD@Z)
1>level.obj : error LNK2001: unresolved external symbol "public: virtual char const * __thiscall TiXmlDocument::Parse(char const *,class TiXmlParsingData *,enum TiXmlEncoding)" (?Parse@TiXmlDocument@@UAEPBDPBDPAVTiXmlParsingData@@W4TiXmlEncoding@@@Z)
1>level.obj : error LNK2001: unresolved external symbol "protected: virtual class TiXmlNode * __thiscall TiXmlDocument::Clone(void)const " (?Clone@TiXmlDocument@@MBEPAVTiXmlNode@@XZ)
1>level.obj : error LNK2001: unresolved external symbol "public: virtual bool __thiscall TiXmlDocument::Accept(class TiXmlVisitor *)const " (?Accept@TiXmlDocument@@UBE_NPAVTiXmlVisitor@@@Z)
1>MSVCRT.lib(crtexew.obj) : error LNK2001: unresolved external symbol _WinMain@16
1>C:\Users\Outlaw\Documents\Visual Studio 2010\Projects\LegendsReborn\Release\LegendsReborn.exe : fatal error LNK1120: 12 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

note: the code performed alright in the debug mode, everxthing was working like intended.
ignore the first warning

Thanks ? :d This probably isnt related to SFML, but i would be thankful it would be fixed.

Graphics / SetDrawingBounds help
« on: May 13, 2012, 12:21:55 pm »
I was working on Tiled system, and i managed to convert it to 2.0, but now the only problem is

Code: [Select]
Level level;

sf::FloatRect rect2(0, 0, 2048, 1536);
level.SetDrawingBounds(rect2); // THIS

The tutorial said differently:
Code: [Select]
Create an instance of Level.

Level level;

To load a map file,


You MUST set drawing bounds before attempting to display the level.


I recommend using an sf::View to "scroll" the map, rather than moving the map itself. This way you don't have to worry about objects (NPCs etc) on your map moving (or not) correctly.
You will find you need to implement some system to only move the view by whole numbers, otherwise you will see gaps between tiles.

Then to draw you simply pass your renderwindow to the Draw function.


Can someone write me with sf::View ? I dont know how to since there isnt a GetRect() anymore.

General / How to debugging
« on: May 13, 2012, 12:02:48 pm »
Hi guys, i tried debugging and this is what i get:

Code: [Select]
The thread 'Win32 Thread' (0x674) has exited with code 0 (0x0).
The thread 'Win32 Thread' (0x22c) has exited with code 0 (0x0).
The program '[2308] LegendsReborn.exe: Native' has exited with code 0 (0x0).

Can anyone tell me what it means ?

General discussions / Can someone make a tile system tutorial ?
« on: May 12, 2012, 07:11:41 pm »
Hi guys, i was desperatly trying to learn sfml, and i learned a lot but i still cant create a good tile system engine that loads maps from xml files.
Will anyone be kind to make me one ?

Im using SFML 2.0 RC, since 1.6 seems bad

p.s. a tutorial section would be cool

Graphics / Problem with tile system
« on: May 12, 2012, 11:29:45 am »
Hi guys, im trying to load a map with rapidxml, it compiles alright but when i call the function , i get a error.

Here is the code:

Code: [Select]
void LoadMap(std::string mapname, Block *blocks[] )
//Loads a level from xml file
//Load the file
std::ifstream mapFile(mapname);

throw "Could not load tileset: " + mapname;

//Dump contents of file into a string
std::string xmlContents;

//Blocked out of preference
std::string line;
while(std::getline(mapFile, line))
xmlContents += line;

//Convert string to rapidxml readable char*
std::vector<char> xmlData = std::vector<char>(xmlContents.begin(), xmlContents.end());

//Create a parsed document with &xmlData[0] which is the char*
rapidxml::xml_document<> doc;

//Get the root node
rapidxml::xml_node<>* root = doc.first_node();

std::string imagepath;

//Load each necessary tileset
rapidxml::xml_node<>* tileset = root->first_node("tileset");
imagepath = tileset->first_attribute("name")->value();
sf::Texture texture;

//Columns and rows (of tileset image)
    int columns = texture.getSize().x / 32;
    int rows = texture.getSize().y / 32;

std::vector <sf::Rect<int> > subRects;
    for (int y = 0; y < rows; y++)
        for (int x = 0; x < columns; x++)
            sf::Rect <int> rect;
            rect.top = y * 32;
            rect.height = y * 32 + 32;
            rect.left = x * 32;
            rect.width = x * 32 + 32;
rapidxml::xml_node<>* tile = root->first_node("tile");
int block_type = -1;
int x = 0;
int y = 0;
int n = 0;

block_type = atoi(tile->first_attribute("gid")->value());

blocks[n] = new Block( n, block_type, x, y);

x += 32;

cout<<"ID: "<<n<<" Block type: "<<block_type<<" X,Y: "<<x<<","<<y;

        if( x >= SCREEN_WIDTH)
            x = 0;
            y += 32;

tile = tile->next_sibling("tile");

This is how i call it:

Block* blocks[TOTAL_TILES];
LoadMap("spawn.tmx", blocks);

Debug error: R6010
-abort() has been called

and i can only click abort, retry and ignore

this is what he gets:
Code: [Select]
the instruction at "0x004f53cc" referenced memory at "0x027581c8". The memory could not be "read". Click on OK to terminate the program
But i close it, it closes normally

while (App.isOpen())
                while (App.pollEvent(Event))
                        if (Event.type == sf::Event::Closed)
                return 0;

Graphics / Switching from image to textures.
« on: May 09, 2012, 02:17:12 pm »
I want to load a  texture onto a texture. (before i loaded a image and a image with copy)

or should i can i make image onto a texture ? which is better ?
btw this is my TextureManager.cpp (changed from ImageManager.cpp)

I used to have:

sf::Image tileset;
sf::Image tileImage;
tileImage.Copy(tileset, 0, 0, sf::IntRect(x * tileSize, y * tileSize, frames * tileSize, tileSize), true);

But now i switched my code all to sfml 2.0 and i dont know the function that copies in sfml 2.0.

i want something like this:
sf::Image tileset;
sf::Texture tileTexture;
tileTexture.Copy(tileset, 0, 0, sf::IntRect(x * tileSize, y * tileSize, frames * tileSize, tileSize), true);


I searched a bit, and i think i could use loadFromImage but im not sure how. An example with the code above would be appriciated.


Maybe this ? but im lacking the 0,0 position, maybe texture.update ?
tileTexture.loadFromImage(tileset, sf::IntRect(x * tileSize, y * tileSize, frames * tileSize, tileSize));


I managed to fix the errors. Can someone tell if this code does like the past one ?

sf::Image tileset;

sf::Texture tileTexture;
tileTexture.create(tileSize, tileSize);
tileTexture.loadFromImage(tileset, sf::IntRect(x * tileSize, y * tileSize, frames * tileSize, tileSize));
tileTexture.update(tileset, 0, 0);

I have the correct tileSize declaration. i dont get any errors when compile.


Graphics / Real time input, input box
« on: May 08, 2012, 11:16:09 pm »
I want to write out the text as something types it on the keyboard. So basically a input box without the box  :o

Is there any function like GetPressedKey() ????

Graphics / sf::Text Same variable for many uses ? How to unload ?
« on: May 08, 2012, 05:10:20 pm »
So at the beginning i made sf::Text and set the string to example1. Then i changed the position and the string to example2. But when i do App.Display() i get both. Do i have to make a new sf::Text, or can i somehow unload the example1.

Does making a new variable impact my code in the long run ? (if i continue making new sf::Text for every text)

Graphics / sf::Text help, formatting the setString
« on: May 07, 2012, 11:50:14 pm »
My plan is to add a menu listing feature like:

Code: [Select]
text[id].setString(text[id].getString() +  " >"); obviously doesnt work since i wanted to show you what im trying to do.

the ">" what indicate what option is currently selected.

got this, can i somehow add on the ">" sign on the end of text[id] string ?

example: if the string was "car" it would be "car >".

Code: [Select]
void Option::Set_Option (int id)


Pages: [1] 2