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

Pages: [1]
1
General discussions / How to make music/sound, easily?
« on: July 12, 2012, 06:02:46 pm »
Hello guys.

I know, that this question has nothing to do with SFML at all, so sorry about that.
I need a software for creating music. So far, I'm playing around with Rosegarden with the Musica Theora soundfont, which is nice and all, and if I click here and there, and press some buttons on my keyboard, I can generate some noise. In other words, it is not what I'm looking for. What I want is something really simple, and easy to use stuff, because I have no idea how to compose music.
This software should be really, really cheap, preferably for free (no trial, and shareware, and of course no illegal stuff), and I should be able to create some basic music in a matter of minutes, without any musical knowledge.

Also looking for something to create sound effects. Like explosions, shooting and so on.

Any suggestions ?

2
General discussions / SFML and C++0x; "error: use of deleted function"
« on: October 26, 2011, 08:49:52 pm »
Hi there!

As some of you may know I'm still a beginner with C++, so sometimes I got newbie questions.
Let's suppose, I have this object:

Code: [Select]
class aClass
{
public:
   aClass () { // initialize stuff }

    void Update () { // update stuff, not relevant }

    void Draw (const sf::RenderTarget& target)
    {
         Sprite.Draw(target);
    }

private:
    sf::Sprite Sprite;
};


I have a few of this object in a vector:
Code: [Select]
std::vector<aClass> vec;

So, I was experimenting with for_each and std::mem_fun_ref, and I came up with this:

Code: [Select]

// win is a sf::RenderWindow object
for_each(vec.begin(), vec.end(), std::mem_fun_ref(&aClass::Update));

for_each(vec.begin(), vec.end(), std::bind(std::mem_fun_ref(&aClass::Draw), win));


I compile it with -std=c++0x using g++ (4.6, so it supports C++0x), under Linux, and I got a nice error message, "error: use of deleted function" at the second line. After a bit of Google, I really didn't get a good answer. I think, it is because the sf::RenderWindow is a non-copyable class, which is the base class of sf::RenderTarget. Is this correct ? Or I'm doing it in a wrong way ?
Because, if I use a "classic" for loop, it compiles just fine. (note: the first line compiles without any error, and does what it should do in both cases)
Code: [Select]

std::vector<aClass>::iterator iter;
for (iter = vec.begin(); iter != vec.end(); ++iter)
{
   iter->Draw(win);
}

3
General discussions / Design flaw in my game ?
« on: August 15, 2011, 06:11:12 pm »
Hi there

I hope, this is the right place to ask this.

I got really stuck with my project. I think I have a nice flaw in my design, or maybe I simply lack of proper knowledge of C++.

Right, so I have a game engine. It handles different game states. Something like this:

Code: [Select]

// main.cpp

// include things

int main ()
{
  Engine* MyEngine = Engine::GetInstance();
 
  // declare game states
  PtrToGameState Title(new TitleState(TITLE_STATE));
  PtrToGameState Map(new MapState(MAP_STATE));
 
  MyEngine->AddState(Title);
  MyEngine->AddState(Map);
 
  MyEngine->Init(...);
  MyEngine->Run(...);
 
  return 0;
}


The engine stores the game state objects in a vector, and when it's running it iterates through this vector and calls some function:
Code: [Select]

// hopefully this piece of code is easy to understand...
while (running && lState != EXIT_STATE)
{
  for (iter = states.begin(); iter != states.end(); ++iter)
  {
    if ((*iter)->GetState() == lState)
    {
      (*iter)->Init();
      lState = (*iter)->Mainloop();
    }
  }
}


So, with this I have a nice state manager-like thing, which handles various states I create, as long as I inherit from an abstract base class called, GameState.
However, the state objects can't communicate with eachother. I try to explain what I mean, and want to achieve.
I start a new game, and I'm playing it for 2 hours, then decide to call it a day. So I want to save my progress. But with this code I can't do that!
The TitleState don't know where I am in the MapState, so even though TitleState has a Save Game function, it doesn't know what I want to save. (And the engine only knows the GameState base class.)

I hope you understand my problem, and give me some advice on what should I modify in my design. Because I am out of ideas.

4
Graphics / Strange window resize behaviour
« on: August 07, 2011, 08:52:10 pm »
Hi there!

I created a nice main menu class last week, and today I expanded it with mouse events. It works nicely. But only in my test program. If I try to
use it in my game, it works, but sf::Text.SetPosition() doesn't set the position how I want it. Interestingly the GetRect() returns the correct
position.

I try to show how I use it.

test program
Code: [Select]

// include things

MenuSystem menu;

void init ()
{
// get font file from disk
menu.SetFont(font);
menu.SetPos(50, 100);
}

int main ()
{
sf::RenderWindow App(sf::VideoMode(800, 600m 32), "Menu test 2", sf::Style::Close);

init();

menu.AddEntry("New", NEW);
menu.AddEntry("Load Game", LOAD);
// etc...

while (App.IsOpened())
{
MenuLabel choice = NONE;
// process sf::Event::Closed here

choice = menu.OnEvent(App);

menu.UpdateEntries(); // this just sets the color of the text

App.Clear(sf::Color::Black);

menu.DrawEntries(App); // draw them

App.Display();
}

return 0;
}

This works perfectly like I said before.

And my game...
Code: [Select]

void MenuState::Init ()
{
// load font
mMenu.SetPos(50, 100);
mMenu.SetFont(font);

mMenu.AddEntry("New Game", NEW);
// .... like above
}

State MenuState::Mainloop (sf::RenderWindow& win)
{
while (mRunning)
{
mRunning = EventHandler(win);

Update();

Render(win);
}

return mNextState;
}

bool MenuState::EventHandler (sf::RenderWindow& win)
{
switch(mMenu.OnEvent(win))
{
// ... not relevant
// but if the player selects a menu it returns false
}

return true;  // if no menu was clicked
}

void MenuState::Update ()
{
mMenu.UpdateEntries();
}

void MenuState::Render (sf::RenderWindow& win)
{
// clear screen and draw stuff, not relevant
}


Basically, I use it in the same way in both cases, but the outcome is different. In my test program the text is in the right place, in my game it is not. Even if I tell it the exact position, the text is rendered somewhere else, but GetRect() gives back the right position.

EDIT:
Okay, I just tested it with sf::Style::Fullscreen, and it works like I intended.

EDIT2:
:) I think I figured out what the problem is. Apparently if I set sf::Style::Resize, then position is not correct. So, the problem is with my system, to be exact how it handles the windows. (I use XFCE)
Sorry about this silly topic  :oops:

5
General / Theory behind a simple GUI
« on: July 30, 2011, 10:26:28 pm »
Hi there everybody!
This might be a trivial question or problem. But I have a hard time figuring it out.

Actually I will just copy-paste (really) an e-mail adressed to Nexus, and I hope he doesn't mind it.

Here I go:

Quote
"Hi Nexus!

Let me introduce myself. I am Peter, unranked86 on the sfml forums. I'm a beginner at C++, and SFML, yet I find them very powerful.
I'm sorry to bother you in this way, and sorry about my english. Well, I shall get to point, I think.
Your work on Thor truly amazes me. It is a very good library, and I'm thinking about using it in my future projects.
But, something I really want to ask you is, how should I write a very basic GUI. By very basic, I mean, some menu entries, some buttons, and windows (widgets ?) What I'm interested is in, not concrete code, but some starting point.

What I have so far in theory, is something like this:

MenuSystem class, which manages all the MenuEntries, probably a std::vector or std::list. This class should allow me to add and remove MenuEntry objects, and control the behaviour of them. But, how can I achieve that ? I mean, I obviously can add and remove new items to a std::vector, but how can I make them to execute a certain "command". For example there is a menu with Newgame, Loadgame and Exitgame objects. Like the names suggests Newgame starts a new game, Loadgame loads a game, and Exitgame quits the application. These MenuEntries are just sf::Text objects basicaly wrapped in a class like this (not real code):

class MenuEntry
{
public:
 MenuEntry (unsigned int x, unsigned y, std::string label); // sets the sf::Text object's parameters
 ~MenuEntry ();
 virtual void Execute () = 0; // run the wanted code, like creating a new game
private:
 sf::Text mLabel;
};

This is just a base class, and I derive more classes from this. But my real problem is, which gives me a hard time, how do I tell the MenuSystem class about how to execute the right "command" in the Execute() function ? And how does it know which MenuEntry is selected ? Well, yes, the MenuEntry class needs an accessor funciotn 'bool IsSelected ()', which is true when the user selects it, but how does the code know this ?
I don't know if I'm clear enough. Actually I checked the source of cpGUI, but gained almost nothing from it."

Pages: [1]