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

Pages: [1] 2
1
Graphics / Re: Strange behaviour with setTextureRect flip
« on: June 12, 2016, 05:52:30 pm »
Yeah, it's set to false.

2
Graphics / Strange behaviour with setTextureRect flip
« on: June 11, 2016, 07:02:55 pm »
I found a strange bug while working on my game today.
I had to flip my sprites for different directions. I used to use setScale with (-1,1) and it worked great, but I had to manage positions etc. I then found out about negative width on the setTextureRect function and started using it.

Here's the problem (SFML 2.3).
When drawing a flipped sprite ( SPR.setTextureRect(sf::IntRect(width, 0, -width, height); ) and setting this sprite's position to a half pixel (0.5f, 1.5f ... X.5f) does not use the correct rectangle. It actually offsets it one pixel to the right, but ONLY at half pixel positions. I assume this is some kind of rounding error.

But why would the sprite's position have any impact on the texture rectangle?
I temporarily fixed it by casting my sprite's x position to int. You can't draw to half pixels anyway.

3
General / 'sf::Key' has not been declared
« on: December 18, 2011, 02:46:04 pm »
Thanks, it totally works now.
The examples should probably be updated.

4
General / 'sf::Key' has not been declared
« on: December 18, 2011, 02:15:48 pm »
So I just recently built SFML2 and wanted to familiarize myself with the new stuff.
There I was, making a super simple program when it started complaining about sf::Key not being declared. I just thought that I made a typo or something but then I copy-pasted the code from here and it still complained.

What's the deal?

Here's what I got so far.

Code: [Select]

#include <SFML/System.hpp>
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>

#include <iostream>




int main(){


    sf::RenderWindow mainWindow(sf::VideoMode(800, 600,32), "SFML window");
    mainWindow.Clear(sf::Color(46,40,35));


    sf::Text text;
    text.SetString("TEXT FOR THE SCREEN");
    text.SetPosition(200,200);

    mainWindow.Draw(text);
    mainWindow.Display();

    while(true){
        sf::Event currentEvent;
        mainWindow.PollEvent(currentEvent);
        if(currentEvent.Type == sf::Event::Closed){
            return EXIT_FAILURE;
        }

        if ((currentEvent.Type == sf::Event::KeyPressed) && (currentEvent.Key.Code == sf::Key::Escape)){ // here's the problem
            printf("%i\n", currentEvent.Key.Code);
            return EXIT_SUCCESS;
        }
    }


    return EXIT_SUCCESS;

}

5
SFML projects / [RELEASED] SFMLUploads.Org
« on: August 26, 2011, 11:39:49 am »
I like the idea of it but really, why is there no way to browse uploads?

6
General discussions / List of modifications from SFML 1.6 to 2.0
« on: August 04, 2011, 12:10:15 pm »
Quote from: "Laurent"
...Excellent information...

Wow, I'm an idiot. I understand now. I learned threads from Java, and it was a few years ago.
Thanks

7
General discussions / Re: List of modifications from SFML 1.6 to 2.0
« on: August 04, 2011, 11:53:48 am »
Quote from: "Nexus"
Quote from: "hagel"
For someone trying to program as object oriented as possible?
Code doesn't automatically become more object oriented the more classes it uses. Inheritance to extend functionality is the Java approach, C++ additionally provides many (often better) alternatives. There is no reason why a thread cannot be a global function.

Of couse more classes aren't always more OOP but in my case, the code was for a server thread. The class will exist.

After finding the 2.0 documentation and looking at the examples I found that all three of them use an instance of sf::Thread.
Before I had a server object in my game class. Now I need a server object and a thread object. I know, not a big deal, but still.

Also, why remove the functionality of inheritance? Because of clashing with the other new functionality?

I'll have to experiment a bit with this.

8
General discussions / Re: List of modifications from SFML 1.6 to 2.0
« on: August 03, 2011, 04:14:30 pm »
Quote from: "Nexus"

System package
  • sf::Thread works now with function objects, no more inheritance

So no more of this?
Code: [Select]

class MyClass : public sf::Thread{
private :
    virtual void Run(){
        for (int i = 0; i < 10; ++i)
            std::cout << "I'm the thread number 2" << std::endl;
    }
};
myClass.Launch();

Oh man. That will mess up my code.
What will the alternatives be? For someone trying to program as object oriented as possible?

9
Graphics / Help with game and sprite movement
« on: May 19, 2011, 03:37:28 pm »
What you want to do is move it until
 player.x % (TILE_SIZE + (GRID_SIZE/2)) == 0
I think. Well, I know you gotta use % to check if your dude went as far as it should've.

I don't know if it's just an image that looks like a grid, if so. It's just
 player.x % TILE_SIZE == 0

10
Network / TCP Server, Wait() + Send
« on: January 22, 2011, 09:45:10 pm »
Working with threads right now. I have the "normal main thread" and a client/serverReceiver thread.
Although, I got one problem. I need to share objects, more specifically the socket and/or the clientlist.
Socket in the client, because I send in the "main" thread and receive in a subclass, ClientReceiver, who use the same socket, obviously.
I'm not sure how to do this in a proper way without the mess of billions and billions of pointers, alright that's an exaggeration, two or three.
How do I share a vector created in my Client class with the ClientReceiver class?

pseudo code could look like this:
Code: [Select]

class Server{
    SocketTCP listener;
    ServerReceiver recv;
    vector <SocketTCP > clientlist;

    void runRegularly(){

        sendSometimes;
        recv.Launch(); //RUN THREAD
    }
}

class ServerReceiver : Thread{
    SocketTCP *socketFromServer;
    vector<SocketTCP > *clist;// PROBLEM. HOW DO I STORE A POINTER TO A VECTOR?

    func initialize(SocketTCP s, vector c ){ // PROBLEM. HOW DO I PASS A POINTER TO A VECTOR?
        scoketFromServer = s;
        clist=c;
    }

    func Launch(){
        acceptSockets(putTheSocketInThisSharedVector);
        receive();
    }
}


I'll be using mutexes around the vector and socket just to be safe :roll:
Is the structure even remotely correct? Sharing stuff between threads and classes seem like a thing you shouldn't do.
Main problem right now is the vector.
Without it I can't get the Sockets for the clients in the server. They're "in" the selector (not in the "code" snippet, I know, but that's a problem for another day).
Anyways, it's late and I'm tired as heck and I hope you understand my ramblings.

Any help would be appreciated.

11
Network / TCP Server, Wait() + Send
« on: January 20, 2011, 02:48:33 pm »
Quote from: "tntexplosivesltd"
If it halts the whole loop, try looking at threading. Although, it might be a bit unnecessary. Not sure if you can implement the situation you outlined above, sorry. It might be able to be done, I have no idea.

Yeah, I've thought about threading but man, it's a headache.
I was thinking about having 4 player matches and I can't figure out how to do threading in OOP design.
Any tips?

12
Network / TCP Server, Wait() + Send
« on: January 17, 2011, 11:11:14 am »
Quote from: "tntexplosivesltd"
All wait does is wait for at least one socket to be ready. Can be found on the documentation here.

This sort of problem (handling multiple TCP connections) has been discussed before in this thread
For your 2-player situation, you probably don't need a selector.

Yeah that's the thing, it waits for a socket to be ready. It halts the whole "while(true)" loop.
Can I not Send on those sockets who are not ready to be read? e.g.
While Waiting:
 Send to clients.
else (there is something to be received)
 Receive from clients.

13
Network / TCP Server, Wait() + Send
« on: January 16, 2011, 06:36:45 pm »
Hello,
I'm currently exploring the world of network programming. I started with the Selector example in the tutorial and kind of understood it all, except maybe the Wait function. I tried extending the example to be able to send messages from the server to the client but it seems like Wait is blocking anything from running.
Is there a place where I can read more about the uses of Wait and Selector?
I get that the GetSocketReady function returns a socket that has sent something to you but can you loop the selector and send to all sockets who are not currently sending to you?

Any hints on how to extend the example to be able to send from the server when it isn't receiving?

EDIT: Seeing as this is supposed to be a 2 player "match" game, do I even need the selector? There's the server player and the client player.
I could save some headaches, right?

14
Graphics / render at 2x?
« on: December 24, 2010, 10:29:58 pm »
Quote from: "Laurent"
Use a view of 320x240 on a RenderWindow of 640x480.

For example:
Code: [Select]
sf::RenderWindow window(sf::VideoMode(640, 480), ...);
window.GetDefaultView().SetFromRect(sf::FloatRect(0, 0, 320, 240));

Laurent, you are damn awesome. 8 minutes for a perfect answer from the administrator.

Thank you very much.

15
Graphics / render at 2x?
« on: December 24, 2010, 10:14:57 pm »
Hello,
This is a seemingly simple question but anyways, here it goes.
How do I render my RenderWindow at 2x?
e.g. I have a drawing area of 320x240 and draw it all out. Then when actually displaying the drawn stuff I want it to be 640x480.

Allegro has strech_blit. It works like this:
stretch_blit(buffer, screen,0,0,320,240,0,0,640,480);
this streches the buffer(bitmap) with the size of 320,240 pixels to 640,480 pixels and blits it onto screen(bitmap which is displayed).

Is there a way to do this in sfml?

Pages: [1] 2