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

Pages: 1 [2] 3
16
Graphics / Re: [SOLVED]Loading charset
« on: August 09, 2013, 12:59:38 pm »
Good thing that you learned what the lifetime of a variable is and finally managed to make it work. :)

 I can't say it better :)

17
I recommend you take a look at great tutorials of Coding Made Easy

Tutorial Loading Tile maps [easy]
SFML 2.0 Tutorials

18
Graphics / Re: Loading charset
« on: August 09, 2013, 10:27:11 am »
As they said, you need to define the texture in main code and pass it as a parameter in defCharset.

chars.h
#include <SFML/Graphics.hpp>

void defCharset(sf::Texture *gmChar, sf::Sprite *gmCharacther_semiIdle,sf::Sprite *gmCharacther_stage1, sf::Sprite *gmCharacther_stage2, std::string filename);
 

chars.cpp
#include "chars.h"

void defCharset(sf::Texture *gmChar, sf::Sprite *gmCharacther_semiIdle,sf::Sprite *gmCharacther_stage1,sf::Sprite *gmCharacther_stage2, std::string filename)
{
    if (!gmChar->loadFromFile(filename)){
    }

    gmCharacther_semiIdle->setTexture(*gmChar);
    gmCharacther_stage1->setTexture(*gmChar);
    gmCharacther_stage2->setTexture(*gmChar);
}
 

main.cpp
#include <SFML/Graphics.hpp>
#include <SFML/Audio.hpp>
#include "chars.h"

const int AppHeight = 540;
const int AppWidth = 1020;

int main()
{
  sf::RenderWindow Window(sf::VideoMode(AppWidth,AppHeight,32),"TESTE", sf::Style::Close | sf::Style::Titlebar);

  //sf::Music backgroundMusic;
  /*if(!backgroundMusic.openFromFile("Resource/FromHere.ogg")){
      return EXIT_FAILURE;
    }*/

////////////////////////////////////////////////////////////////////////

  float x = 90;
  float y = 40;

  int mute = 0;

  sf::Sprite gmChar_sm;
  sf::Sprite gmChar_s1;
  sf::Sprite gmChar_s2;
  sf::Texture gmChar;   // <-- create texture

  defCharset(&gmChar, &gmChar_sm, &gmChar_s1, &gmChar_s2,"cb.bmp");

  gmChar_sm.setPosition(x,y);
 
  ....
 

19
Network / Re: How to limit the number of TCP clients
« on: August 07, 2013, 10:30:09 am »
You are right, I have to remove the listener before close it. My mistake.. Now it's works perfect. Thank you so much binary1248.

sf::TcpListener listener;
sf::SocketSelector selector;
std::vector <sf::TcpSocket*> clients;

listener.listen(2000);
selector.add(listener);

while (true)
{
   if (selector.wait())
   {
       if (selector.isReady(listener))
        {
            sf::TcpSocket *socket = new sf::TcpSocket;
            listener.accept(*socket);
            clients.push_back(socket);
            selector.add(*socket);
            numPlayers++;
            std::cout << "new player connected. Number players: " << numPlayers << std::endl;
           
            if (numPlayers == maxPlayers)
            {
                 std::cout << numPlayers << " players connected, not more allowed." << std::endl;
                 selector.remove(listener);
                 listener.close();
            }

 

20
General discussions / Re: SFML team is growing
« on: August 07, 2013, 12:24:41 am »
Great news, thank for your work guys  ;)

21
Network / Re: How to limit the number of TCP clients
« on: August 07, 2013, 12:09:21 am »
Thanks for your reply binary1248. I tried to accept() and disconnect() socket and it's work ok.

Just I said, if I close the listener, the server doesn't receive more packets from clients. I uploaded a simply code here: http://sdrv.ms/17wMIf5

Basically the server start and listen for client connection request. When arrives one, accepts and send to client the game map, his player id, his player position, number of players and all the player positions. When receive a player position request, check if is avaiable and send this new position for all the players.

In the client side, its connect to server and receive the map game, his id, position and all player positions.
When the player wants to move (with arrow keys: left, right, up, down), send the requested new position to server, if its available, receive an answer and move to it. Also, if receive a position of one rival, set it.

I limited the number of players to 4, when a 5th client attempts to connect, show the error message, close listener and since then, the server doesn't receive the clients data. It's a bug or works properly?

I use SFML 2.1 with Code::Blocks 12.11 (Windows 8 Pro, 32 bits)

22
Network / [SOLVED]How to limit the number of TCP clients
« on: August 06, 2013, 05:44:51 pm »
I’m making a simple game with TCP Client/Server communication. In the server I have a TcpListener and SocketSelector.

I want to limit the number of clients that can connect to the server to 4. My question is in SFML as I can tell to the server that if have 4 clients, do not accept more connection requests and stop listening new connections? I try with listener.close() but then does not receive data from the existing 4 players.

Any idea? Thanks.

23
Simply, if you have a previous SFML version installed, delete it and this DLLs where you are placed. In my case I added my SFML path on Windows Environment Path, I modified SFML-2.0 for SFML-2.1, I deleted the SFML-2.0 folder and now its work ok.

24
When I installed the new release 2.1 I have the same error. I fix it deleting the SFML 2.0 folder and his DLLs. Check if you have a copy of SFML libraries on Windows/System32 or a reference in Windows environment Path. Now SFML 2.1 works fine in Code::Blocks 12.1.

25
General / Re: SFML project not building. (CodeBlocks)
« on: May 29, 2013, 11:34:41 am »
In Code:Blocks 12.11 with MinGW you need to use the GCC 4.7 TDM (SJLJ) - 32 bits SFML version, not DW2. Check what version are you using. This code works perfect in my Code:Blocks with SJLJ version.

26
General discussions / Re: A new logo for SFML
« on: May 01, 2013, 12:24:46 pm »
I like this logo, looks perfect. Simply and modern. Good job!

27
General / Re: Runtime Crash!
« on: April 30, 2013, 11:56:01 pm »
You need copy the .dll files of sfml-2.0/bin in your program folder or copy all to Windows/System32. Also you can add your sfml-2.0/bin pathway in your Vista System Variables Path.

28
General / Re: how to read a joystick ?
« on: April 30, 2013, 11:48:50 pm »
Hi! First of all, I advise you change to SFML 2.0. It's includes a complete documentation. Take a look, it's free  :P

Some clues:

sf::Joystick::isConnected(0)
sf::Joystick::getAxisPosition(0, sf::Joystick::X)
sf::Joystick::getAxisPosition(0, sf::Joystick::Y)

A final clue:
http://www.sfml-dev.org/documentation/2.0/classsf_1_1Joystick.php

29
General / Re: Build crashes on Code::Blocks (SFML 2.0)
« on: April 30, 2013, 11:39:27 pm »
The new official SFML 2.0 release works prefect with Code:Blocks 12.11. Also you can use the SFML Project wizard of C:B 12. 

30
General discussions / Re: SFML 2 and its new website released
« on: April 30, 2013, 11:31:33 pm »
Yeay ! Long Life To SFML !  ;D
+1

Congrats Laurent and thank you for your work.

Pages: 1 [2] 3
anything