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

Pages: [1] 2 3 ... 5
General / Re: Rotate against sprite
« on: March 21, 2016, 08:12:18 pm »
Well, it's not moving during your calculation for the current frame, so you take the two positions and calculate the appropriate angle, which is really a matter of trigonometry and not programming.

It's been a while for me, but there's a plethora of links to be found on Google on this topic.
Does something like this help you?

General / Re: Rotate against sprite
« on: March 21, 2016, 08:02:07 pm »

Graphics / Re: Size depending on pixels
« on: March 21, 2016, 07:52:19 pm »
i can't explain in the right way but i think this image will help

void sf::Sprite::setTextureRect(const IntRect & rectangle)

Audio / Re: Need help identifying the problem with my sounds.
« on: March 15, 2014, 09:08:10 pm »
Okay! Switching to a std::list to store the sf::Sound instances has solved the issue. I have no idea why though.  ;D

Audio / [Solved] Need help identifying the problem with my sounds.
« on: March 15, 2014, 05:59:43 pm »
I'm in dire need of help once more.  ::)
I have a small class that manages my sf::SoundBuffers and also sf::Sounds.

It contains this method right here, whose task is to first search for sounds that stopped playing and possibly remove them from a vector (of structs that contain the sound itself and a std::string), and continue by playing the desired sound.
As you can see, I search a vector of sf::SoundBuffers (same structure as above) for the name of the file, create a new sound instance, add it to the vector and play it. It works perfectly fine as long as sounds from different files are played at the same time. However, if I try to play the sound from a single file/buffer more than once at the same time, the first just stops abruptly.
If I play the same sound more than two times, it's a complete mess. Sometimes it works and some of the sounds play, sometimes all get cut off.
If I remove "this->sounds.back().sound.play();", everything seems to work (the cleanup gets triggered all the time, but only as expected).
It's obvious that I'm doing something wrong, but I simply can't figure it out.

void ac::SoundStorageDebug::play(std::string file)
    std::vector<ac::SoundStorageDebug::Sound>::iterator i = this->sounds.begin();
    while(i != this->sounds.end())
        if(i->sound.getStatus() != sf::Sound::Playing)
            std::cout << i->sound.getStatus() << std::endl;
            i = this->sounds.erase(i);
            std::cout << "sound removed" << std::endl;
    for(std::vector<ac::SoundStorageDebug::Buffer>::iterator i = this->buffers.begin(); i != this->buffers.end(); ++i)
        if(i->file.compare(file) == 0)
            ac::SoundStorageDebug::Sound tmp;
            std::cout << "sound created" << std::endl;

Graphics / Re: Acceleration-Effect with sprite-based cursor.
« on: March 13, 2014, 02:22:15 pm »
That's what I've been trying to say. ;)

Yes, of course. I was just writing down what I did in the mean-time, and the conclusion I got from it. Thinking out loud, in a way.
Your explanation was very helpful, thanks again.

Graphics / Re: Acceleration-Effect with sprite-based cursor.
« on: March 13, 2014, 01:52:15 pm »
Thanks for your quick reply. I'm aware of how the issue is generated. My main concern was that the user might click while moving the mouse and get an off result.

However, while eagerly waiting for a reply, something occured to me and I quickly added a second shape that would be drawn whereever the mouse was clicked. Now, the mechanics that caused the original problem cause the second shape to appear exactly where the first one is displayed. I suppose this means that it doesn't matter at all where the actual cursor is, since the lag applies to all drawn objects, doesn't it?
So the issue really is just a hypothetical one!

That only leaves the undesired visual effect of spongy cursor movement. I fear however, that I'd have to change the system cursor directly to counter that.

Graphics / Acceleration-Effect with sprite-based cursor.
« on: March 13, 2014, 01:03:02 pm »
Now that I've found the time to code again, I want to solve an issue that has bugged me ever since. I don't think the code is necessary, since all I'm doing is draw a shape and make it follow the cursor, but there you go.

The problem I have is, that there is an acellerated-mouse efect present when using a sprite-based custom cursor, that gets dramatically amplified by activating vsync. The video shows what I mean. While the effect may become less obvious when hiding the cursor, it is still bothersome.
(The effect with vsync turned off, or an uncapped framerate, however the movement is much more crisp.)

The little game I've set my mind to requires precise and quick mouse input, even while the cursor is moving. This issue however opens up the possibility of registering a click on a location that differs from the one of the cursor-sprite.
Also, but that's a personal opinion, I think the whole acceleration effect is just awful, even if deliberately built in.

(It doesn't even look that bad in the video. But especially when moving in a constant motion, the sprite clearly lags behind. )

#include <SFML/Graphics.hpp>

int main()
    sf::RenderWindow window(sf::VideoMode(1280, 720), "Title");
    sf::CircleShape shape(10.f);
    shape.setOrigin(10, 10);

    while (window.isOpen())
        sf::Event event;
        while (window.pollEvent(event))
            if (event.type == sf::Event::Closed)


    return 0;

I have considered alternatives already, like using windows-functionality like "LoadCursorFromFile()", but then I'd have to look for equivalent functions on other Platforms, or lose portability (I'd like to avoid both). Also, I'm wondering if getting the input from a different thread would help. (I have yet to try the latter, as I haven't worked with threads before)

Anyway, any input is very welcome!

General / Re: Finding script files
« on: July 28, 2013, 06:04:44 pm »
This is what I was using to solve a similar problem. I didn't see any reason to use a full-blown file system api, just to get the files in a specific directory.

#include <dirent.h>

DIR *dir;
struct dirent *ent;
if ((dir = opendir ("c:\\src\\")) != NULL) {
  /* print all the files and directories within directory */
  while ((ent = readdir (dir)) != NULL) {
    printf ("%s\n", ent->d_name);
  closedir (dir);
} else {
  /* could not open directory */
  perror ("");
  return EXIT_FAILURE;

Also happens to be the very first result from a google search on "list files in directory c++".

Thank you, but that isnt what I want to do exactly.

I dont want to mantain a specific size (for example, 800x600), but to resize mantaining the proportion, in that case 4:3, and just filling with black what dont fit. (As in the images I put in the post).


Actually, Nexus reply contained the answer to your question. The part in the view-tutorial you'd want to look at is called "Defining how the view is viewed".

General discussions / Re: SFML 2 and its new website released
« on: April 30, 2013, 03:10:47 am »
Fancy, and a nice surprise indeed! Congrats!

Graphics / Re: Background Image Not Loading
« on: April 25, 2013, 04:38:23 pm »
So I have to set the texture before I create the window?

EDIT: Did that and it works fine. I guess initializing the graphics before trying to draw them would be smart.  :-\

bool Engine::Initialize()
    window = new sf::RenderWindow(sf::VideoMode(800, 612, 32), "BattleGame - V2");
        return false;
    // Let's create the background image here, where everything initializes.
        throw "Failure!";
    return true;

Graphics / Re: sprites are white rectangles
« on: April 25, 2013, 02:05:11 pm »
is there some way to get the velocity of the puck ??

Since v=s/t the velocity is nothing more than pixels (in this case) per unit of time (s/ms/whatever) So you measure the distance the mouse is moved in a certain period, and voila, you've got your velocity.

Network / Re: What do I need to send?
« on: March 09, 2013, 03:21:17 pm »
I'd only send the following in the most basic setup:
Player starts moving bar up.
Player starts moving bar down.
Player stops moving bar.
Point is made.

That of course doesn't include a lot like setting up a game, ending a game or general communication to keep everything working as well as fancy stuff like changing speeds and alike. The idea would be that the clients and the server calculate the movement of the ball simultaniously (using exactly the same algorithm, and only input (moving stopping) and made points are being sent. You'd get practically no traffic and the game stays smooth.

//Game starts: Ball direction is sent to both players.
//Player 1 moves his bar by pressing UP: Only one single packet is sent to the server containing that the player moves his bar. Gets sent to Player 2 by the server.
//Player 1 stops his bar by releasing UP: Only one single packet is sent to the server containing that. Gets sent to Player 2 by the server.
//Ball hits Player 1s bar: No communication. Both clients know where the ball is and where it will move to, and the server knows as well.
//Player 2 dosen't do anything and therefore ball hits border. Server detects that and tells both clients that point was made. Clients may detect it as well, but only to stop ball-movement or any other visual changes.

I've never done anything like that, so it's just a basic idea. It doesn't take varying latency into account as well as lag on any of the machines which would make the movement of anything out of sync, or anything else you'd have to think of.

Graphics / Re: how to draw like this?
« on: November 19, 2012, 07:59:04 pm »
The way you're trying to achieve this would take away a lot of resources.
Better create (or load) 2-3 (I don't think you need more than three) "random noise" textures and cycle through them. Randomly creating screen-filling noise in every frame would be waaay too heavy.

So what you can do is create those frames at program start or when you need them (still, only once, and keep them in memory if you need it more often), by filling each pixel of each frame with a random value. You could also just create those textures in some image manipulation software that offers a noise-filter and load them as textures.

Then you cycle through those few frames, it's unlikely that anyone will notice that you're using the same non-random textures over and over again.

At least that's how I would do it.

I only took a quick glance at your code, but when you call sf::Texture::loadFromImage(), you're not adding something to your Texture, but resetting it. That's why you only draw one of your dots each frame. (Also there are other ways to properly do this, but you should rather do something like mentioned above.)

Also you should read about the difference of Events and Input using sf::Keyboard and alike, it's not supposed to be inside the event loop. I suppose the tutorials would be a good start.

Pages: [1] 2 3 ... 5