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

Pages: [1]
1
Network / Help clarify
« on: September 02, 2020, 01:01:20 pm »
I've started messing around with networking recently and had a few questions that I would like some clearing up on after looking around and finding multiple answers. The questions will revolve around server to multiple client connections.
 
  • Checking if the client is still connected.

    Would it be best to use receive() until It doesn't take anything? I tried using socket.getRemoteAddress() != sf::IpAddress::None, but It didn't seem to do anything.

  • Threading the receive().

    -Never really worked with threading, but I'm curious as to how I can get receive() to work with send() simultaneously. Right now for me, I have to send() then wait for a receive() before I can send again.

  • Selecting different sockets from the client to message.

    First off, how would I even get the other socket values from the server to client? Should I put every socket accepted on the server into a vector or a list? But then back to my first question, how do I get the values of other sockets to my client? Should I just use receive() and store them into another container on the client? And if I want to send a message directly to another client, should I create another socket to an open port on the server and connect the two clients to it? 
   
If my questions have already been answered elsewhere then a link would be much appreciated. I'm sorry, but these are just questions I couldn't really find a clear answer to.

Thanks a bunch in advance.

2
General / Re: Rotating a Sprite
« on: July 15, 2020, 02:08:44 am »
Try this in the constructor.

Ship::Ship()
    : sf::Sprite()
{
   texture.loadFromFile("10B.png");
   this->setTexture(texture);
 
   
   this->scale(sf::Vector2f(0.25f, 0.25f));  
   this->setPosition(100.0f, 100.0f);
   this->setOrigin( this->getLocalBounds().width / 2, this->getLocalBounds().height / 2 );
 
   // Definimos la velocidad
   this->speed.x = 300.0f;
   this->speed.y = 300.0f;

}
 

3
General / Re: Sprite rotation on tile map
« on: July 14, 2020, 11:47:04 pm »
it could be because you are constantly reseting the sprite origin when you update poll events.
have you tried like this?
void Player::initializePlayer(const sf::Texture& idle_T)
{      
//[...]
        this->player_Sprite.setOrigin(sf::Vector2f(
                this->player_Sprite.getLocalBounds().width / 2.f,
                this->player_Sprite.getLocalBounds().height / 2.f));
}

Same results.

You want to match the sprite's position to the position it would've been inside the tile map after the tile map has been rotated?

I would like the sprite to match with the tile position when rotating.

While on the first tile it rotates fine, but moving to another then rotating makes it move rotate around in a circle.

For more of a visual representation here is a video.


4
General / Sprite rotation on tile map [FIXED]
« on: July 14, 2020, 06:04:15 pm »
[FIXED]
-Read below for answer.

I've been searching around for a solution for hours now and I still haven't managed to find anything. I've also looked at https://www.sfml-dev.org/tutorials/2.5/graphics-transform.php.

The problem...
I have a 11x11 tile map with each tile being 125x125. I would like to rotate my sprite which is also 125x125, but it goes off center unless its in the first tile of the tilemap.

To put it simple, I click a tile and then press 'Q' to rotate it, but the origin is off. How can I set the origin correctly with a tile map?

void Player::initializePlayer(const sf::Texture& idle_T)
{      
        this->player_Sprite.setTexture(this->idle_T);
        this->player_Sprite.setTextureRect(*this->idle_Frame);
        this->player_Sprite.setPosition(sf::Vector2f(0.f, 0.f));
        this->player_Sprite.setOrigin(sf::Vector2f(125.f, 125.f));
}
 

void Player::updatePollEvent(sf::Event& ev, const sf::Vector2f& tilePosition)
{
        if (ev.type == sf::Event::KeyPressed)
        {
                if (ev.key.code == sf::Keyboard::Q)
                {
                        this->transform.rotate(10.f);
                }
        }

        this->player_Sprite.setOrigin(sf::Vector2f(
                this->player_Sprite.getLocalBounds().width / 2.f,
                this->player_Sprite.getLocalBounds().height / 2.f));
}
 
I tried passing the tile's position here to set the origin but that did not work either.

My first post and I'm sorry if the post is not up to standards with the rules. Any help would be much appreciated.

[SOLUTION]
-Rotate the sprite directly using
sprite.rotate(x.f)
and also draw the sprite directly
target.draw(sprite)
instead of
target.draw(sprite, transform)

Pages: [1]