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]
1
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

2
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

3
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

4
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

5
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

6
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

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

was testing button 1 instead of button 0

8
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 ?

9
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;
}

 

10
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


11
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

 

12
Audio / music sound lowered
« on: May 08, 2022, 02:46:55 pm »
hi

when i play a sound the music volume is lowered and after few seconds upping to the old volume

music.hpp
#ifndef    __music__
#define    __music__

#include <SFML/Audio.hpp>
#include <string>

class music{
public:
    bool initMusic();
    void setMusicVolume(const float volume);
    void playSong();
    void stopSong();

    sf::Music m_music;

private:
    bool loadSong(std::string title);
    void setMusicLoop(bool loop);


};
#endif

music.cpp
#include "music.hpp"

bool music::loadSong(std::string title)
{
    return m_music.openFromFile(title);
}

void music::setMusicVolume(const float volume)
{
    m_music.setVolume(volume);
}

void music::setMusicLoop(bool loop)
{
    m_music.setLoop(loop);
}

bool music::initMusic()
{
    bool flag = loadSong("A Theme.flac");
    setMusicLoop(true);
    return flag;
}

void music::playSong()
{
    m_music.play();
}

void music::stopSong()
{
    m_music.stop();
}
 

sound.hpp

#ifndef    __sound__
#define    __sound__

#include <SFML/Audio.hpp>
#include <string>
#include <vector>
#include <memory>

class sound{
public:
 //   sound();
    void initSounds();
    void playSound(const int thatSound);
    void setSoundVolume(const float volume);

private:
    bool loadFileSounds();
    void assignSoundsToBuffers();

    std::array<sf::SoundBuffer, 15> m_soundBuffer;
    std::array<sf::Sound, 15> m_sound;
};
#endif

sound.cpp

#include "sound.hpp"
#include <array>
#include <iostream>

bool sound::loadFileSounds()
{
    bool flag{true};
    bool flag1 = m_soundBuffer[0].loadFromFile("sound\\harddrop.ogg");
    flag1 = m_soundBuffer[1].loadFromFile("sound\\rotation.ogg");
    flag1 = m_soundBuffer[2].loadFromFile("sound\\softdrop.ogg");
    flag1 = m_soundBuffer[3].loadFromFile("sound\\ouverturemenu.ogg");
    flag1 = m_soundBuffer[4].loadFromFile("sound\\levelchgt.ogg");
    flag1 = m_soundBuffer[5].loadFromFile("sound\\complitedlines.ogg");
    flag1 = m_soundBuffer[6].loadFromFile("sound\\departfinpartie.ogg");
}

void sound::assignSoundsToBuffers()
{
    for(auto i = 0; i < 15; ++i){
        m_sound[i].setBuffer(m_soundBuffer[i]);
    }
}

void sound::initSounds()
{
    loadFileSounds();
    assignSoundsToBuffers();
}

void sound::setSoundVolume(const float volume)
{
    for(auto i = 0; i < 15; ++i){
        m_sound[i].setVolume(volume);
    }
}

void sound::playSound(const int thatSound)
{
    m_sound[thatSound].play();
}
 

both volume are initialized once
m_jsonSetup.loadJsonFile("setup.json");
    gameSound.initSounds();
    gameMusic.initMusic();
    setSetUp();
    setSoundVolume(m_setup.soundVolume);
    setMusicVolume(m_setup.musicVolume);

thx

Pages: [1]
anything