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

Pages: 1 [2] 3 4
16
Window / That annoying little window
« on: April 28, 2011, 02:21:03 am »
Quote from: "Mjonir"
My project is aimed at both scripters (who really need the console) and their end-users (who don't need/want to see the console). So at the moment I do have multiple build targets, but I'd be force to release two different versions of my program, one with the console and one without. If I could control that in the application itself, I could only give only one build and control that in the configuration file. It's not an absolute need, but it'd be neater if it's easy enough to control.

I'll have a look at Windows.h then. I hope it wouldn't break portability too much to do it this way though :?

It is probably not as easy as you wish. Once you have created a new console-window you  have for example to redirect the standard input and output streams to this window.
It is possible and described here, but it is rather complicated.

But I have an easy suggestion for you. Just create a console-application and if you don't want to show the console window, use
Code: [Select]

ShowWindow(GetConsoleWindow(), SW_HIDE);

to hide it(Further information).

I think hiding an existing console is easier than creating a new one ;).

17
Graphics / Re: Events
« on: April 27, 2011, 11:37:05 pm »
Quote from: "David"

Can you do this? :?
Code: [Select]

if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Shift)) {
    // Do here what you want to happen when the user presses shift
}



You can do it in a very similar way. Key Event has special variables to check, wether shift, control or alt was pressed or not.

Code: [Select]

if ((Event.Type == sf::Event::KeyPressed) && Event.Key.Shift )
{
    // Do here what you want to happen when the user presses shift
}

So this should work.

18
General discussions / Looking For Resources
« on: April 27, 2011, 06:09:58 pm »
I have learned SFML by reading the tutorials and mainly by reading the documentation. The documentation of the sfml is one of the best I have ever read. You will find many helpful examples, if you read it. Of course I am not using it as a bedtime reading, but if I need a function, I will have a look at the documentation first and will mostly find something that meets my requirements ;).
However my way to the sfml was not a common way. I came from 3D programming with Ogre3D, because of an 2D game idea and because I am not the best 3D modeller, so that my 3D games would not look better than my 2D games(though I am a bad drawer, too) ;).

But I also think there aren't many alternatives to the sfml. SDL and Allegro for example. And in comparision the SFML is in my opinion the most beginner friendly framwork.

19
General / Clamp to Screen
« on: April 27, 2011, 05:38:34 pm »
Are you using any views? So maybe your player is jsut going out of the view and not out of the window.

Make sure, that you do set the new player position. Maybe you forgot it and the correct position is computated, but not displayed.

But I can only guess. You have to give us more infos(as wizard mentioned: create a minimal application).

20
Graphics / Sprite Help
« on: April 27, 2011, 05:26:36 pm »
Have a look at this: http://www.sfml-dev.org/tutorials/1.6/window-events.php
There is everything explained what you want to know.

21
Graphics / draw a triangle..
« on: April 25, 2011, 07:47:55 pm »
Every circle has a center. So center_x is the x value of your center and center_y is your y value ;).
In your case it would be a circle around point A. So center_x is 0 and center_y is 0, too ;).

22
General discussions / Hey Laurent! SFML Uploads? ;)
« on: April 25, 2011, 01:07:30 am »
If it is just about uploading, I recommend Dropbox. Very easy to use for both uploaders(just put your files into a special (windows)-folder and it will be uploaded) and downloaders. So if someone needs free space(I use it also to sync my documents from different computers), he should have a look at it ;)

But of course a website which contains sfml-projects, snippets etc. would also be very cool.

23
Graphics / draw a triangle..
« on: April 25, 2011, 12:20:54 am »
I would set point A to (0|0). Point B is set at B(c|0)(c is opposite of point C. a opposite of A aHence the line between A and B. Now you have to find C. C is the intersection of a circle around point A with radius b and a circle around point B with radius a. So I would just step through all the points of a circle around point A with radius b and would check, wether the distance between this new point and B equals to line a.

To find all these points on a circle I would use:
x = center_x + r * cos phi
y = center_y + r * sin phi

24
SFML wiki / Creae a simple image manager
« on: April 23, 2011, 08:23:29 pm »
Thank you :).
I had a look on your Resource Manager yesterday. I think, this would be the next step. But my tutorial is for beginners and a look at your code tells me that it is not "beginner's code" ;).
Those options, you mentioned, are not implemented, because I think that the reader will be also a programmer and he might be able to set some "//" int front of the debug output(or just don't copy it^^). It isn't a real debug output anyway. It just shows you, that the image is not loaded again and again.

A strange mistake. This[/cpp] also tells me that there is no erase-function, which returns an iterator, but my Visual C++ compiler has one ;). So it works for me.
But of course I fixed it. And you're right. It won't be necesseray to search the whole map, if I find and appropriate entry, and I should leave it.
So it should be enough to use this, shouldn't it?
Code: [Select]

images_.erase(it)
return;

25
SFML wiki / Creae a simple image manager
« on: April 22, 2011, 07:44:19 pm »
Hello,
I decided to create a little tutorial on handling images, because often images and sprites are used together in the same object-class and so the image is often reloaded for all objects of the same type, what shouldn't be necessary.
You can read it here.

26
Window / Handling User Input
« on: April 22, 2011, 01:09:20 am »
Quote from: "Nexus"
You can map the different events like KeyPressed, MouseMoved etc. to callbacks.

Nice framework and nice system. I began to wrote a similar system(this is part of my new plan to implement an event-manager), because I didn't know that you've already done this ;). But my event-manager is supposed to bind callbacks to both keys and events(as you're planning^^). But many functions of our framework, I have already implemented by myself, because they're very usefull. So it is just natural, that you have already written an useful event-callback-manager ;).

27
Window / Handling User Input
« on: April 21, 2011, 11:46:10 am »
Quote from: "Wizzard"
Futhermore, SFML runs the OnEvent callback of the Input class always. This means that you always have the SFML input manager running even when you're not using it.

That's a good point. Thank you. I probably will adjust my system to the event callback and integrate my own callback-system :). I do prefer this callback-system, because it is for example very easy to script and there is no difficulty to provide a custom assignment of keys.
But I think this is a matter of taste and I prefer the callback system.

28
Window / Handling User Input
« on: April 20, 2011, 11:12:33 am »
Megatron:
To handle the user inputs, I have two classes.
input_map contains maps for mouse and keyboard inputs
Code: [Select]

std::map<sf::Key::Code, boost::function<void()>> key_bindings;
std::map<sf::Mouse::Button, boost::function1<void, const sf::Input&>> mouse_bindings;

To use this map, I have to bind a key or a button to a function, which is supposed to be called, if the button/key is pressed(boost is very helpful ;)).
Code: [Select]

template<class T>
void register_input_id( sf::Key::Code key, void (T::*Func)(), T& obj)
{
key_bindings[key] = boost::bind(Func, boost::ref(obj));
}
template<class T>
void register_input_id( sf::Mouse::Button mouse, void (T::*Func)(const sf::Input&), T& obj)
{
mouse_bindings[mouse] = boost::bind(Func, boost::ref(obj), _1);
}

The scond class is an input-manager, which contains all the input-maps. At each update-step it checks, weather a key of an input-map is pressed and runs the function:
Code: [Select]

for( std::vector<input_map>::iterator action_it = input_maps_.begin();
action_it != input_maps_.end();
action_it++)
{
for( std::map<sf::Key::Code, boost::function<void()>>::iterator key_it = action_it->key_bindings.begin();
key_it != action_it->key_bindings.end();
key_it++)
{
if(input_.IsKeyDown(key_it->first))
key_it->second();
}

for( std::map<sf::Mouse::Button, boost::function1<void, const sf::Input&>>::iterator mouse_it = action_it->mouse_bindings.begin();
mouse_it != action_it->mouse_bindings.end();
mouse_it++)
{
if( input_.IsMouseButtonDown(mouse_it->first) && !mouse_button_pressed_.at( mouse_it->first ) )
{
mouse_it->second( input_ );
}
}
}


Well to use it, is very easy. An instance of an input-map is created in every class, where it is needed and some key events have to be registered:
Code: [Select]

input_map_.register_input_id( sf::Key::Back, &gs_game::exit_game, *this );
game_env_.input_manager.register_input_map( input_map_ );

And maybe my system is complicated, too, but it is also very easy to port and to use it with other input-frameworks(a few weeks ago I used it with OIS)

Quote from: "Wizzard"

If you want objects to be aware of input, just make the window's input globally accessable via a global variable, a function that returns a reference or pointer to the input, or via passing a reference or pointer to functions.

It's a very simple way indeed, but I wouldn't prefer it. If I got your point right, every single object(which is supposed to check inputs) has to get an input-variable and handle the input by itself. I don't think that this is a very good way, because I don't think that it is the business of every single class to handle their own inputs. And on the one hand you have to copy code and use the same code twice(or even more often) to process input for more than one object. If there is a mistake in your code, you will have to change it a couple of times. On the other hand I think that code, that is used more than once or twice, should be designed in another way, to use the same code for all instances. And this is what an input-manager does ;).

29
Feature requests / Unloadable Resources
« on: April 18, 2011, 10:48:23 am »
Quote from: "JayArby"
Sounds like a lot of you are coming from the Java viewpoint, especially with those static factory methods.

Are you talking with me? I am certainly not coming from Java. But I also like the way to use constructors to initialise my objects ;).

Quote from: "JayArby"
Again, I'm fine with the Java way or the C++ way, but mixing them doesn't seem like a good idea.

C++ offers pointer. So you aren't mixing anything. Avoiding dynamic memory allocation doesn't mean not to use it at all.

Quote from: "JayArby"

Well, here is my personal example: a static Image object is used to display a thumbnail view of the currently selected image in a list of image files. When no image is selected, there is no reason to keep the image in memory. So I want to unload the image so that the thumbnail display will automatically know, on checking the image, that nothing needs to be displayed. So I had to use pointers. No big deal, but it just doesn't seem like the Image class was really meant to be used like that. It would have been more elegant to use a stack allocated object.

I would prefer to keep the image in memory because unloading and loading images is probably not the best for your performance.
another way is to use an image loader. This image loader has a list, with all images, and if you need an image it checks if it is necessary to load the image or if the image is already in the list. If you don't need an image anymore, you can simply remove it from this list and you don't have any empty images.
but as I have already mentioned: I don't think that it is the fastest way, to unload and reload the images.

30
Feature requests / Unloadable Resources
« on: April 17, 2011, 05:21:14 pm »
I am sorry. I did not know that SFML doesn't crash, if you try to use an "empty" image(I never tried it ;)). Hence it wouldn't be that bad to use a cleared image.
And of course the user is able to misuse almost everything in C++, but that is not a reason to offer functions that are unnecessary and risky.

My point is that if a user want to use such a function his design is probably imperfect. Just deleting some image information, but keeping an empty variable, is in my eyes bad design. So I just want to warn not to change a system that it meets the needs, but to consider weather the own needs are sensible.
And for this reason I would not provide a function to clear an image, because in many cases it would be misused(in that way that it is used in a bad design).

Pages: 1 [2] 3 4