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.


Topics - Guido_Ion

Pages: [1]
1
Graphics / [SOLVED] Problem when zooming
« on: May 02, 2023, 05:41:25 pm »
Hi, I can't figure out what to do to make the text and the minimap stay in the same size when i zoom.
I zoom in the main view and the text and minimap that I'm drawing after the scene zooms also, I want them to stay the same size.
Should I create another view? As I understand the views overwrite each other, can I make a transparent View so I write the text and minimap over it and the rest is transparent so the back main view is viewed?
Or should I apply a counter-zoom to the text and the minimap?

2
SFML projects / Top Down Soccer/Football game with SFML and BOX2D
« on: December 29, 2021, 03:18:54 am »
Hey! I wanted to share with you my project, it's a soccer game with total control. I've always felt that mainstream soccer games (FIFA, PES) lack control over what you do, meaning, where you kick is approximate, your passes are approximate, etc. Also I've never found a soccer game that really does what I want it to do. Natural Soccer is good but not exactly what I want. Sensible Soccer is great but very limited.

So... I decided to try to do it myself. After 18 months of developing this is the current state. There's a lot to improve but I think it's going in the direction I want. A lot (I mean a lot) of develompment went (and still goes) to the handling of the players, it's 80% done. Art is basic, a lot to do there. AI is basic also, I will re do it, I'm still learning about AI.

http://www.youtube.com/watch?v=q8-m00-ddwk

Thanks! you can follow development on twitter @guido_ion

3
Graphics / [Solved] Position a sprite relative to another
« on: October 21, 2021, 10:03:22 pm »
Hi, I'm trying to position a sprite relative to another. I have 2 sprites, one for the character and one for the head. The view is top down, when he is standing the head and character are aligned but when I do a slide the head remains in the center, I need to position the head in the correct place applying and offset form the center. How can I achieve this? I leave a beautiful image discribing the problem  ;)

I have this code but the translation isn't working, I can't see the head (it might be outside the screen)
Code: [Select]
void FieldPlayer::draw()
{
m_sprite.setPosition(Game::SCALE * m_body->GetPosition().x, Game::SCALE * m_body->GetPosition().y);
m_sprite.setRotation(Game::RadiansToDegrees(m_body->GetAngle()));
Game::GetWindow()->draw(m_sprite);

head_sprite.setPosition(Game::SCALE * m_body->GetPosition().x, Game::SCALE * m_body->GetPosition().y);
head_sprite.setRotation(Game::RadiansToDegrees(m_body->GetAngle()));
// move the head back if sliding
if (PlayerState.sliding) {
sf::Transform t = head_sprite.getTransform();
t.translate(-52.f, -10.f); ???
Game::GetWindow()->draw(head_sprite, t);
}
else {
Game::GetWindow()->draw(head_sprite);
}
}

Note: I need the code to consider rotations also

4
SFML projects / Gamepad Class for SFML (using XInput and SDL database)
« on: October 09, 2021, 12:12:19 am »
Hi guys I wanted to share this class that I made that uses SDL's controller database. I started looking for a gamepad db for SFML and I noticed that it is a common request from users so I decided to do it myself.

https://github.com/GuidoBisocoli/SFML_GamepadSupport


Features:
  • It supports Left and Right Trigger as button or axis seamlessly
  • It manages inverted axes

TO DO:
  • Support for dpad
  • Hide buttons, axes and triggers, now they are public
  • Read also linux and MacOs gamepads
  • Test gamepads

I've only tested it with my 2 gamepads (Logitech Dual Action and Controller (XBOX 360 For Windows)) and it works great, if you can help testing other gamepads please comment and let us know.

5
Window / Gamepad Class that reads from SDL controller database
« on: October 02, 2021, 07:50:11 pm »
Hi, I'm trying to do a simple class to read SDL's database of controllers (the txt file). The problem is that SDL uses GUID of devices and I can't get that information with sf::Joystick since SFML works with vendorID and ProductID. I've tried also comparing the names of the joysticks but sometimes they are slightly different, for example SFML writes "Logitech Dual Action" while SDL writes "Logitech Dual Action USB".

Is there a way to read GUID from SFML or maybe somehow converting GUID to VendorID and ProductID? Is that info in there?

I'll share the results with the community once it's done (if it can be done)

6
Hi, I'm programming a Football/Soccer game, currently I'm working on the height of the kick. The game is top down so I'm simulating the height of the ball with calculations and visual aids.

The kick consists of a 2d vector with it's magnitude (force) and it's direction. From this information and the angle of the kick in the z-axis (height, angle a in the image) that I assign according to the force, I want to get the z-component of the vector.

From hours of researching I get that I can get the x-component like this: std::abs(magnitude) * cos(angleInDegrees) and the y-component like this: std::abs(magnitude) * sin(angleInDegrees). But of course I have these components in the vector itself.

I have this so far for the z-component:
Quote
initialAngle = getAngleRelativeToForce(force); // this returns an angle from 0 to 60 according to the force of the kick (this works fine)
b2Vec2 resultingVector = force * direction;
float sinAngleY = resultingVector.x / std::abs(force); // angle between y-axis and hypotenus (x-component/hypotenuse)
// Formula for z-component: Force * sinAngleY * sin(initialAngle)
forceInZAxis = std::abs(force) * sinAngleY * std::sin(Game::DegreesToRadians(initialAngle));

This gives me weird behaviors: for example similar kick with huge height when I'm facing up, and no height when facing down. Or a strong kick with no height.

I'm stuck there, I keep reseraching but I feel there is something I'm missing and maybe someone can point it out.

7
Window / Calculating Mouse movement not accurate when View is modified
« on: March 08, 2021, 09:32:00 pm »
Hi! I'm implementing mouse movement that mimmics the movement of a GamePad Stick.

What I need is to calculate the movement each frame, I do this by calculating the difference between the previous position and the new one. The problem occurs when the View is modified by zooming and/or by moving. In this case even if I don't move the mouse, its position is modified.

This is part of the code:
Code: [Select]
static sf::Vector2f previousMousePosInCoords = Game::GetWindow()->mapPixelToCoords(sf::Mouse::getPosition(*Game::GetWindow()));
sf::Vector2f mousePosInCoords = Game::GetWindow()->mapPixelToCoords(sf::Mouse::getPosition(*Game::GetWindow()));
sf::Vector2f mouseDifferenceInCoords = mousePosInCoords - previousMousePosInCoords;
// if mouse moved
if (mouseDifferenceInCoords.x != 0.f && mouseDifferenceInCoords.y != 0.f) {
Input.thereIsMovement = true;
Input.directionNormalized = Game::SfVecToBoxVec(mouseDifferenceInCoords);
Input.directionLenght = Input.directionNormalized.Normalize();
previousMousePosInCoords = mousePosInCoords;
}
else Input.thereIsMovement = false;

I understand that if I work on pixels instead of coordinates it should work but the movement will depend on the resolution the game is played.
Other thing I could do is substract the amount of movement and zoom of the view but I think they might be a simpler better solution.
How could I do this?

8
I'm using tmxLoader by fallahn and my view rotates with the movement of the player. The issue is that some parts of the map are not drawn when rotating. It seems that the drawing only takes the size of the view without the rotation.

As you can see in attachment 1, when the player and the view are not rotated (or slightly) the maps draws correctly, and in attachment 2 you can see that when they are rotated part of the map is not drawn.

Before drawing this is being called (private method):
Code: [Select]
void MapLoader::SetDrawingBounds(const sf::View& view)
{
if(view.getCenter() != m_lastViewPos)
{
sf::FloatRect bounds;
bounds.left = view.getCenter().x - (view.getSize().x / 2.f);
bounds.top = view.getCenter().y - (view.getSize().y / 2.f);
bounds.width = view.getSize().x;
bounds.height = view.getSize().y;

//add a tile border to prevent gaps appearing
bounds.left -= static_cast<float>(m_tileWidth);
bounds.top -= static_cast<float>(m_tileHeight);
bounds.width += static_cast<float>(m_tileWidth * 2);
bounds.height += static_cast<float>(m_tileHeight * 2);
m_bounds = bounds;

for(auto& layer : m_layers)
layer.Cull(m_bounds);
}
m_lastViewPos = view.getCenter();
}

Do I need to change tmxLoader myself or is there a way to set it up manually outside MapLoader?
And how do I need to change it?   ???

Note: I didn't want to post in the tmxLoader specific Topic since is been inactive for 4 years now.

9
I'm trying to get the view to follow the player's position and rotation as it moves. I want to place the view slightly upwards in the direction of the player (variable segment) so the player is placed almost at the bottom of the screen.

Here is the code of the placement of the view:

Code: [Select]
float angle = HumanFieldPlayer::Instance().getSFMLAngle(); // in Degrees
float segment = Game::WindowHeight / 4.f;

m_view.setRotation(angle);

sf::Vector2f posCoords = HumanFieldPlayer::Instance().getSFMLPosition(); // in SFML Coordinates
m_view.setCenter(posCoords.x, posCoords.y - segment);

Game::GetWindow()->setView(m_view);

As you can see in the GIF (see attachment) it's not the behavior I want, when I rotate the player ir should be always in the same position, at the bottom in the middle like in the beginning of the GIF.

I tried a lot of things but I'm pretty lost, what am I missing?


10
I've been searching different GUIs but they all come with buttons or fonts to draw. My artist will make all the buttons, etc. as sprites so I just need the functionality of the GUI and I will slap the sprite on top of it.

Is there any simple GUI out there for this? Should I make my own?

11
Window / [SOLVED] How to know if sprite is in view
« on: January 10, 2017, 11:28:58 pm »
Hi Guys, I'm having trouble trying to know if a sprite is inside the current view, this is my code:

bool Sector::lightInView(sf::FloatRect spriteAABB)
{
        sf::Vector2i viewCenter(Game::GetWindow()->getView().getCenter()); // global coords, right?
        sf::Vector2i viewSize(Game::GetWindow()->getView().getSize());  // in this case: 1680x1050
       
        // create the view Rect, are the -/+ ok?
        sf::FloatRect currentViewRect
                (viewCenter.x - viewSize.x / 2,
                viewCenter.y + viewSize.y / 2,
                viewCenter.x + viewSize.x / 2,
                viewCenter.y - viewSize.y / 2);

        // check if the sprite is in view
        return (spriteAABB.intersects(currentViewRect));
}

This isn't working, I know because the sprites are lights that I only draw when they are in view. They won't draw or draw when not in view, etc.
I'm having trouble understanding the coordinates system, it's probably an issue with that.

12
Graphics / 8x8 tiles and big map, bad idea? [Solved]
« on: June 25, 2015, 05:22:25 am »
Hi, I've been working with SFML for some months now and some weeks ago I started to do the tileset for my game. I began by making 64x64 tiles and everything was working fine but now I need to do 8x8 tiles so I can create very detailed figures, but with tiles this small I need to do big maps, something like 300 * 120 tiles which gives a total of 36000 tiles!! of course this dropped my frames to a little bit more than 30 (before it was >200).

From what I know this 36000 tiles means 36000 calls to draw() which is expensive to the CPU, is that correct?

The question is: is there another way to do this or I need to go to bigger tile sizes?

It would be good to be able to use small tiles because I want to create circuits (like those of a motherboard), what I'm doing now is every tile is a small segment of a circuit (straight line, curve, circle, etc.) and I create different circuits with each segment.


Pages: [1]