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

Pages: [1] 2
1
Window / Re: joystick detection
« on: October 14, 2024, 06:53:21 pm »
thanks !!!!!!!!!!!

didn't noticed JoystickConnected

works perfect  8)

2
Window / [solved] joystick detection
« on: October 13, 2024, 05:22:35 pm »
hi

i detect if a joystick is plugged, if not, i loop to detect the plugged one. but detects nothing

thanks

void Player::setJoystickID()
{
    unsigned int pluggedJoystickNumber{0};
    while(pluggedJoystickNumber == 0) {
        sf::Joystick::update();
        for (auto i = 0; i < sf::Joystick::Count; ++i) {
            if (sf::Joystick::isConnected(i)) { ++pluggedJoystickNumber; }
        }
        if (pluggedJoystickNumber == 0) {
            std::cout << "no joystick plugged" << std::endl;
            sf::sleep(sf::milliseconds(1000));
        }
        if(pluggedJoystickNumber == 1) { m_joystickID = 0; }
    }
}
 

3
Graphics / Re: shifting center on rotation
« on: April 20, 2024, 01:24:09 pm »
thanks

was just thinking in the entire pixel

4
Graphics / [solved] shifting center on rotation
« on: April 20, 2024, 01:42:17 am »
hi

i have my drawables witch have their centre shifted 1 pixel x and y when i rotate them
i choosedodds width and height to have a real center point for the rotation
sprite are 49 * 35 i use setorigin(24,17)
tried 48 * 34 in texturerect or vertexbuffer but no

i don't know how to get rid of that. tried with

made a simple program with sf::sprites and it's the same

thx

original on bottom rotated above. red dot should always be in black roof



#include <SFML/Graphics/RenderWindow.hpp>
#include <SFML/Graphics/CircleShape.hpp>
#include <SFML/Graphics/Sprite.hpp>
#include <SFML/Graphics/Texture.hpp>

int main()
{
    sf::RenderWindow window(sf::VideoMode(300, 300), "Test divers", sf::Style::Close);

    sf::Texture texture;
    texture.loadFromFile("cars.png");
    sf::Sprite car;
    car.setTexture(texture);
    car.setTextureRect(sf::IntRect(0,0,49,35));
    car.setOrigin(24, 17);
    car.setPosition(150,150);
    sf::CircleShape circle(1);
    circle.setFillColor(sf::Color::Red);
    circle.setPosition(car.getPosition());

    window.clear(sf::Color::White);

    window.draw(car);
    window.draw(circle);
    car.setPosition(150,90);
    car.setRotation(180);
    window.draw(car);
    circle.setPosition(car.getPosition());
    window.draw(circle);
    window.display();

    while(1) ;
}

5
Graphics / draw function with several drawable in an object
« on: July 21, 2023, 02:35:06 pm »
hi

i have an object drawable with 5 sf::Sprite and a bitmapText
i did first this draw function before i tried to make the object drawable

void BottomPanel::draw()
{
   for(auto i = 0; i < 5; ++i) {
         m_window.draw(*m_sprites[i]);
    }
    m_window.draw(m_Text);
}


}


was good, tranformation are drawn good

now i have this

void BottomPanel::draw(sf::RenderTarget& target, sf::RenderStates states) const
{
    for(auto& elem : m_sprites) {
        states.transform *= elem->getTransform();
        states.texture = elem->getTexture();
        target.draw(*elem, states);
    }

    states.transform *= m_Text.getTransform();
    states.texture = m_Text.getTexture();
    target.draw(m_Text, states);

}

i have a problem with the states.transform *= m_Text.getTransform();
sprites are not drawn where it should be

it's ok if i remove these 2 lines

how do I "fix" a position coords for my object, then i can adapt sprites coords by this origin ?

the contained objects are sf::Transformable so if i set a rotation it s drawn good without
states.transform *= m_Text.getTransform();

so do i need to get transform or not ?
same with textures ?

draw what i want with that one

void BottomPanel::draw(sf::RenderTarget& target, sf::RenderStates states) const
{
    for(auto& elem : m_sprites) {
        target.draw(*elem, states);
    }
    target.draw(m_Text, states);
}


thx

6
General discussions / Re: SFML 2.6.0 released
« on: June 29, 2023, 05:16:47 pm »
hi

there are no -d lib for gcc 32 and 64 bits ?
what can we do for debug

visual 17 have them

thx

7
Graphics / my getGlobalBounds()
« on: June 10, 2023, 05:02:51 pm »
hi

i made a bitmap and sf::text button 
class Button : public sf::Drawable, public sf::Transformable

with position and size being

sf::FloatRect                   m_shape;

initialized like this and origin is set in the constructor to be le middle

mylib::Button button(sf::FloatRect(320, 200 ,150, 100), texture, sf::Vector2f(230, 1600));
    button.rotate(90);
    button.setButtonType(mylib::Button::ButtonType::release);
    button.setScale(sf::Vector2f(2,2));
    button.setFont("OneSlot.ttf");
    button.setTextSize(30);
    button.setTextColor(sf::Color::Red);
    button.setText("the button");
 

my pb is i don't have a getGlobalBounds() available

so i tried this

sf::FloatRect Button::getGlobalBounds() const
{
    return getTransform().transformRect(m_shape);
}

width and height are good but left = -180 and top = 690

how do i have the good values ??

thx

8
Graphics / Re: animation class bad coord drawing
« on: May 13, 2023, 04:21:20 pm »
thx

didn't realised that setpostion() and vextex coord are already the same

working good

9
Graphics / Re: animation class bad coord drawing
« on: May 12, 2023, 04:07:34 am »
must be with the transform because when i remove
states.transform *= getTransform();
from the draw it's ok for coords but of course it's no longer a transformable

how do i fix ?

thx

10
Graphics / animation class bad coord drawing
« on: May 12, 2023, 03:24:23 am »
hi

i wrote an animation class.
the animation plays well but not where it should that seems to be drawn at coords * 2

can't find what i'm doing wrong. did cout to see coords in console and they are goods

minimal code representing a sprite

main.cpp
#include <SFML/Graphics/RenderWindow.hpp>
#include "bitmap/animation/animation.hpp"
#include "mysprite.hpp"

int main()
{
    sf::RenderWindow window(sf::VideoMode(600, 600), "tests divers", sf::Style::Close);
    MySprite mysprite;
    mysprite.m_texture.loadFromFile("countdown.png");
    sf::Vector2f coords(275,275);
    mysprite.setPosition(coords);

    sf::Vector2f framecoord = mysprite.getPosition();
    float LeftX = framecoord.x;
    float RightX = framecoord.x + 49;
    float topY = framecoord.y;
    float bottomY = framecoord.y + 49;

    mysprite.m_frame[0].position = sf::Vector2f(LeftX, topY);
    mysprite.m_frame[1].position = sf::Vector2f(RightX, topY);
    mysprite.m_frame[2].position = sf::Vector2f(RightX, bottomY);
    mysprite.m_frame[3].position = sf::Vector2f(LeftX, bottomY);

    mysprite.m_frame[0].texCoords = sf::Vector2f(0, 0);
    mysprite.m_frame[1].texCoords = sf::Vector2f(49, 0);
    mysprite.m_frame[2].texCoords = sf::Vector2f(49, 49);
    mysprite.m_frame[3].texCoords = sf::Vector2f(0, 49);

    while(1) {
        window.clear();
        window.draw(mysprite);
        window.display();
    }
}

animation .cpp
#include "mysprite.hpp"

bool MySprite::loadTexture(std::string& fileName)
{
    return m_texture.loadFromFile(fileName);
}

void MySprite::draw(sf::RenderTarget& target, sf::RenderStates states) const
{
    states.transform *= getTransform();
    states.texture = &m_texture;
    target.draw(m_frame, 4, sf::Quads, states);
}
 

animation.hpp
#ifndef MYSPRITE_CPP
#define MYSPRITE_CPP

#include <SFML/Graphics.hpp>

class MySprite : public sf::Drawable , public sf::Transformable {
    public :
        bool                                        loadTexture(std::string& fileName);

        sf::Vertex                                  m_frame[4];
        sf::Texture                                 m_texture;
    private :

        virtual void                                draw(sf::RenderTarget& target, sf::RenderStates states) const;
};

#endif // MYSPRITE_CPP
 

image
https://ibb.co/Ry4TYN6

11
System / Re: joystick detection
« on: October 17, 2022, 07:30:39 pm »
my bad

was testing button 1 instead of button 0

12
System / Re: joystick detection
« on: October 17, 2022, 01:09:21 am »
thx working

i ve read that yesterday and i forgot today ...

one last thing

i need to press button 2 to have the message button   pressed

depends on the driver ?

13
System / joystick detection
« on: October 16, 2022, 10:45:05 pm »
hi

tested this code to see if my gamepad was detected, but no
ok with steam and dowloaded joystick tester and ok with it.
also ok in windows joystick configuration

thanks

#include <iostream>

#include <SFML/Window/Joystick.hpp>

int main()
{
    unsigned int joystckID{0};
    sf::Joystick myJoystick;
    while(joystckID < 8) {
        if (myJoystick.isConnected(joystckID)) {
            unsigned int buttonCount = myJoystick.getButtonCount(joystckID);
            std::cout << "joystick ID " << joystckID << " conneted with"  << buttonCount << " buttons.\n";
        }
        else { std::cout << "joystick ID " << joystckID << " not conneted\n"; }
        ++joystckID;
    }
    while(1) {
        if (sf::Joystick::isButtonPressed(0, 1)) { std::cout << "button 1 pressed\n"; }
    }
      return 0;
}

 

14
Audio / Re: music sound lowered
« on: May 12, 2022, 01:25:45 pm »
tested for volume set to 13 for music and sound, and it s the same

changed the music in a sound by converting flac->ogg. it s the same


15
Audio / Re: music sound lowered
« on: May 09, 2022, 06:03:14 pm »
the music begins
and when a soud is played, the music "volume" is lowered .
after few seconds the musoic "volume" up to the normal.
the set music volume is only set at the beginning
so i don t understand why the music is low then re-up

 

Pages: [1] 2
anything