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 - OutlawLee

Pages: 1 [2] 3 4
16
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;
        myfile.close();
    }
    else
        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;
        }
        myfile.close();
    }
    else
        cout << "Unable to open file";
}

17
SFML projects / Re: 'Tiled' Tile-map Loader
« on: September 18, 2012, 06:13:31 pm »
Will this display objects that contain pictures ?
Im not sure how to use the objects.


Thanks man, this is a lot better than mine.


18
Graphics / Re: Trouble adding spacing and margin to Tiled map loader
« on: September 09, 2012, 09:36:00 pm »
@Tex Killer

That made my map look just like mine, just that every tile picture is messed up but the general look is alright.
It seems it cuts the sprite wrong, strange since when i tried without margins and spacing it worked.

Heres the picture:

http://i48.tinypic.com/mc4zy9.jpg

19
Graphics / Re: Trouble adding spacing and margin to Tiled map loader
« on: September 09, 2012, 05:28:23 pm »
Margins-Spacing vary for each tileset. Since this loader can load only one tileset margins-spacing are always the same(in a certain map). Margin-spacing are the ones from the image.

What i (walker) do here is load the tileset in to image apply a mask and then load it into a texture that loads in a sprite which is then being cut with this:

//Columns and rows (of tileset image)
    int columns = tilesetTexture.getSize().x / tileWidth;
    int rows = tilesetTexture.getSize().y / tileHeight;

    std::vector <sf::Rect<int> > subRects;//container of subrects (to divide the tilesheet image up)

    //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;
            rect.top = y * tileHeight;
            rect.height = y * tileHeight + tileHeight;
            rect.left = x * tileWidth;
            rect.width = x * tileWidth + tileWidth;
            subRects.push_back(rect);
        }
    }
 

Here you can see that it only cuts by the number of columns and rows, it doesnt take margins and spacing in account.

I hope i helped.

20
SFML projects / Re: 'Tiled' Tile-map Loader
« on: September 09, 2012, 04:31:52 pm »
Here is the SFML 2 version, works just like the 1.6.

level.h
http://pastebin.com/gwasT3hR

level.cpp
http://pastebin.com/U1NG8eKD

21
Graphics / Re: Trouble adding spacing and margin to Tiled map loader
« on: September 09, 2012, 04:22:24 pm »
Here it is, converted for sfml 2, everyone who wants can use it.

Margins exist on top, and on the left.
Spacing exists between every tile(not picture) which is defined with the width and height.

Both are integers.

level.h
http://pastebin.com/gwasT3hR

level.cpp
http://pastebin.com/U1NG8eKD

This is written by Walker for sfml 1.6:
http://en.sfml-dev.org/forums/index.php?topic=3023.0

I know VertexArrays are better for situations like this, but im inexperienced and will use this for now until i get some knownledge.

22
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.

23
Thanks Laurent, that fixed my problem. Didn't have it all.

24
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
{

public:
        enum MenuResult { Nothing, Exit, Play };

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

        MenuResult Show(sf::RenderWindow& window);

private:
        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;
        texture.loadFromFile("Backgrounds/titlescreen.png");
        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;

        _menuItems.push_back(playButton);
        _menuItems.push_back(exitButton);

        window.draw(sprite);
        window.display();

        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)
        {
        while(window.pollEvent(menuEvent))
                {
                        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 ?

25
SFML projects / Re: Map00(tile editor) - binary + source
« on: May 24, 2012, 02:04:54 pm »
Thanks, gonna try it now.

26
General / Re: Cant compile release mode
« on: May 17, 2012, 03:24:28 pm »
Fixed.

27
General / Re: Cant compile release mode
« on: May 17, 2012, 02:34:12 pm »
I didn't link tinyxml or anything. just included it, its still included but when i start typing #include "... it cant find it

28
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.

29
SFML projects / Re: SFGE - Simple & Fast Game Engine
« on: May 14, 2012, 10:03:50 pm »
Are you close to releasing it ? or something, i wanna use it :d

30
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;
level.LoadFromFile("Maps/spawn.tmx");

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,

level.LoadFromFile("example.tmx");

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

level.SetDrawingBounds(somesfview.GetRect());

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.

level.Draw(window);


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

Pages: 1 [2] 3 4