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

Pages: 1 ... 119 120 [121] 122 123
1801
General / Re: Need help understanding how this code works.
« on: August 30, 2012, 10:23:20 am »
It's not needed but macros(something that was in C so you know it means trouble..) don't respect namespaces so they have to be something extremely ugly/stand out a lot so that you're unlikely to use it in normal code. So include guard usually contain name of file because it's unique but can have even more to be safer. sfml include guards are SFML_filename_HPP

'#define' is 'macro'
the '#ifndef' '#endif' blocks are used to do something called 'conditional compilation'
macros and #ifndef #endif blocks used like that are called 'include guards'
In vc++ you can use #pragma once (it works a bit differently and supposedly faster during compilation than include guards but in the end the effect is same) at the beggining of a header but it's not guaranteed to be on every compiler.

1802
General / Re: Need help understanding how this code works.
« on: August 29, 2012, 05:55:00 pm »
Quote
That's just bad/lazy programming from the creator of that (one year old) tutorial. You should always seperate the decleration (in .hpp file) and the definition (in .cpp file).  ;)
Unless you don't have definitions. :D (Only a sith deals in absolutes)

Show us the code you ported to sf 2.0, only thing that comes to mind is that your two screens aren't derieved from that base screen somehow but that'd quite unlikely.

1803
General discussions / Re: SFML v SDL?
« on: August 29, 2012, 08:44:53 am »
Quote
There have been several great games with SFML (some even commercially),
The way I found SFML was reading blog of creator of Atom Zombie Smasher few months ago about his engine where he mentioned 1.5 and 1.6.
Quote
One often overlooked feature of SFML, I feel, is the ability to simply look at its code.
The amount of layers of abstraction in SFML code and the polymorphic drawable class are just.. wow..
There could be no texts, sprites, shapes and vertex arrays and anyone could easily write them without opengl knowledge because of the way draw methods, vertices, transforms and states work.

1804
General discussions / Re: SFML v SDL?
« on: August 28, 2012, 10:36:08 pm »
Quote
So basically, you pick SDL because it's more popular.
More power to him if he can make it through but I can't believe how popular SDL is considering it's C. Who'd want that instead of sweet, sweet, sweet OOD of SFML.
On the wiki SDL has huge list of games it's in and own page while the SFML has link to non-existent page about Laurent and states that 'the team' is working on 2.0 and that 2.0 rc is only for OCaml so far(?!?!?!?).
Quote
where SFML more assumes that the user has a certain level of C++ knowledge and doesn't provide tutorials to learn coding in C++ with SFML from the ground up
I.e. questions about std, unintended integer divisions and polymorphism.  ;D

1805
General / Re: Another problem with SFML and Box2d! :)
« on: August 28, 2012, 08:00:33 pm »
How am I supposed to know what is happening from a still image, show the code.

1806
System / Re: Using std::map and sf::Vector as key?
« on: August 28, 2012, 02:08:44 pm »
You need to create and pass a 3rd template parameter that will be a comparsion class functor because <(default if you don't pass 3rd parameter to map) is not overloaded for Vector3i.

1807
General / Re: Need help understanding how this code works.
« on: August 28, 2012, 01:49:13 pm »
That actually came up in my code while tying something to box2d but could come up when tying box2d and sfml because physical bodies and fixtures(and joints) can hold void* pointer and attempting to cast directly from sprite/text/whatever pointer to void* and then later casting from void* to drawable* and trying to draw it would cause that error.

1808
General / Re: Need help understanding how this code works.
« on: August 28, 2012, 01:34:07 pm »
I'm not sure but I think bad(and cool  ;D) things happen if you mix void* with polymorhpism like that without many casts:
std::vector<void*> yay;
myclass1 one;//derieved from baseclass which has virtual method ouch()
yay.push_back(&one);//should be static_cast<void*>(static_cast<baseclass*>(&one))
baseclass * ptr =static_cast<baseclass*>(yay[0]);
ptr->ouch();
 
One of last two lines(I think last) would cause extremely interesting error.

1809
General / Re: Need help understanding how this code works.
« on: August 28, 2012, 12:41:42 pm »
It's polymorphism, you should look that up.
The vector stores the cScreen pointer so that method Run() can be called, because cScreen objects and their derieved objects have that method.

1810
General / Re: Another problem with SFML and Box2d! :)
« on: August 28, 2012, 05:22:53 am »
May or may not be it : add .f to every int constant that you use as float.
Every time you do something like 500/30 or 75/2/30 it performs on integers, in order from left to right and truncs evrything.
500/30 is 16, 75/2 is 37, these are small enough errors.
75/2/30 is 1, not 1.25, that's 25% size difference.

1811
Graphics / Re: Problem with image loading with arrays.
« on: August 27, 2012, 08:55:49 am »
Global variables and doing initialization and clean up with global functions looks C. That's what classes, ctors and dtors are for.

1812
General / Re: Clock controlled loop, delayed text output
« on: August 27, 2012, 06:01:34 am »
This is probably overkill and nooby but maybe you can reverse-engineer something out of this:
header:
class EEDelayedText : public sf::Text
{
private:
        sf::Clock m_Clock;
        sf::Time m_time,m_delay;
        std::string m_string,m_buffer;
        unsigned int current;
public:
        EEDelayedText(const std::string& gstring,const sf::Font& gfont,unsigned int gsize);
        ~EEDelayedText(void);
        void setString(const std::string& string);//covering text's setter
        void setDelay(sf::Time gtime);
        const EEDelayedText& update(void);
};
source:
#include "EEDelayedText.h"
EEDelayedText::EEDelayedText(const std::string& gstring,const sf::Font& gfont,unsigned int gsize):
sf::Text("",gfont,gsize),//can be changes probably, my sfml 2.0 is not latest so I miss some ctors
current(0),
m_string(gstring)
{
}
EEDelayedText::~EEDelayedText(void)
{
}
void EEDelayedText::setString(const std::string& gstring)
{
        m_buffer.clear();
        m_string=gstring;
        current=0;
}
void EEDelayedText::setDelay(sf::Time gtime)
{
        m_delay=gtime;
}
const EEDelayedText& EEDelayedText::update(void)
{
        m_time+=m_Clock.restart();
        while (m_time>=m_delay)
        {
                m_time-=m_delay;
                if(current<m_string.length())
                {
                        m_buffer+=m_string[current];
                        ++current;
                }
        }
        sf::Text::setString(m_buffer);//text's setString is covered, must call this way
        return *this;
}
use:
   
sf::RenderWindow app(sf::VideoMode(600,600),"EEDelayedText");
        sf::Font font;
        font.loadFromFile("Resources/Main/arial.ttf");
        EEDelayedText txt("Gott mit uns!",font,25);
        txt.setDelay(sf::seconds(1.f/10.f));
        while(1)
        {      
                app.clear();
                app.draw(txt.update());
                app.display();
        }
 
Add includes for sftext/whatever as needed, vc++ is a bit weird about that so there might be some missing.
This class is kind of ugly tbh, especially that lolzy .update() returning reference that window can use for drawing and that's about what you can do with it really because it's const reference.
Don't blame me if something explodes. :)

1813
Graphics / Re: Problem with image loading with arrays.
« on: August 27, 2012, 03:09:36 am »
Use vectors, use raii, what you do is not c++ way and this problem is not sfml one.
imgTile = new sf::Image[tileCount];
 
Allocate array from 0 to tileCount-1.
for (int i = 1; i <= tileCount; i++)
Use elements from 1 to tileCount.
How could that work?

1814
General / Re: sf::Seconds delay?
« on: August 24, 2012, 02:52:37 am »
Your rects are all wrong.
Your spirte has no texture assigned to it so it quits it's drawing call without drawing anything.

1815
General / Re: box2d
« on: August 22, 2012, 11:12:37 am »
That's your choice to make. Depends on the game/billion other things. Just try to follow everything recommended in box2d user manual.

Pages: 1 ... 119 120 [121] 122 123