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 - Me-Myself-And-I

Pages: [1] 2 3 4
1
Audio / Re: Music not playing even though its loaded.
« on: April 24, 2024, 06:08:16 pm »

Quote
Why this would have an impact on the music playing or not playing, I don't know, since those are separate modules without any overlaps.  ???
I too thought that was very strange.


Quote
You shouldn't use any SFML resources globally, in general avoid globals as much as possible.
Initialization and destruction order at a global scope aren't guaranteed, so you can run into issues where some expected internal SFML global isn't initialize or already destructed, leading to crashes. As for globals in general, they make it very hard to impossible to track the state and code flow at any given moment.

The solution is for me to make a better habit of not declaring SFML elements globally. Thankyou for your help.


Quote
I tried the same code (both global and local window) and music played fine in both cases. Although I'm using SFML 3 so maybe it doesn't have the issue.
I even tried playing the music without a window and it worked. (I replaced the while open loop with a Sleep(10000)).

But I see some bits of the audio system have changed since SFML 2.5 with how the global audio device is handled.

Yes, its likely that this problem was fixed in sfml 3. I use 2.4.0 so it might be more likely for this error to occur in this version when the window is declared globally.

2
Audio / Re: Music not playing even though its loaded.
« on: April 24, 2024, 02:55:33 am »
So strange. I cut it down to a bare minimum and I located the problem at the window declaration.

In main.h
#include <SFML\Graphics.hpp>




extern sf::RenderWindow window;
 


In main.cpp
#include <SFML\Graphics.hpp>
#include <SFML\Audio.hpp>
#include "main.h"
#include <windows.h>




               
sf::RenderWindow window(sf::VideoMode(960,540),"Weather Dodger");



int main()
{
       
       
       






        sf::Music themusic;
        if(!themusic.openFromFile("ASSETS/snow.wav"))
        {
                MessageBox(NULL,"Not found","Error",MB_OK);

        }
        themusic.setVolume(100);
        themusic.play();


        while(window.isOpen())
        {

                sf::Event e;
                while(window.pollEvent(e))
                {
                        if(e.type==sf::Event::Closed)
                                window.close();
                }
               
       
               
               
               
               
               
               
               
               
                window.clear();

                window.display();
        }
}



 

With this code the music does not play.


But with window declared locally theres no problem.Any ideas why this problem occurs?

In main.cpp with window local.

#include <SFML\Graphics.hpp>
#include <SFML\Audio.hpp>
#include "main.h"
#include <windows.h>




               



int main()
{
       
       
       



        sf::RenderWindow window(sf::VideoMode(960,540),"Weather Dodger");



        sf::Music themusic;
        if(!themusic.openFromFile("ASSETS/snow.wav"))
        {
                MessageBox(NULL,"Not found","Error",MB_OK);

        }
        themusic.setVolume(100);
        themusic.play();


        while(window.isOpen())
        {

                sf::Event e;
                while(window.pollEvent(e))
                {
                        if(e.type==sf::Event::Closed)
                                window.close();
                }
               
       
               
               
               
               
               
               
               
               
                window.clear();

                window.display();
        }
}








 

Seems like a window error to me.But why? :P

3
Audio / (SOLVED)Music not playing even though its loaded.
« on: April 23, 2024, 12:43:38 am »
I have this strange problem where the music is loaded but nothing happens when the program is run.

This is put before my window.isOpen() loop.
        Music themusic;
        if(!themusic.openFromFile("ASSETS/snow.wav"))
        {
                MessageBox(NULL,"Not found","Error",MB_OK);

        }
        themusic.setVolume(100);
        themusic.play();


The game updates fine.Theres no freezing going on.And I'm sure the audio file works.I have been using audio files in music and suddenly it doesn't make a sound.I'm sure my computer audio works too because sf::sound works. Either i'm doing something wrong here or something in my other code is stopping themusic. I'm certain there is no themusic.stop() anywhere in my code so i'm wondering if its some sort of problem with sfml. I did use 500 sounds. Could this effect sf:Music? I know. Why use 500 sounds? Well its actually for a sound that is played very fast so I need it.
Any ideas where the problem is?
Thanks

4
Graphics / Re: invisible window border causes smaller top of window
« on: February 04, 2024, 10:11:29 pm »
Ok.Nevermind.I found a solution. It seems this happens because the window is set to create in the center of the screen.All that was needed was to move the window to point 0,0 after creating it.

5
Graphics / (solved)invisible window border causes smaller top of window
« on: February 04, 2024, 08:40:27 pm »
I have a program that gets the desktops workarea size then makes a window with that size and it works good for displaying the window as large as the screen and not cover up the taskbar but either this or sfml's window class is causing a transparent border to shrink the window at the top.

Here's my code:



IntRect getWorkArea()
{
        RECT rcWorkArea = { 0 };
        SystemParametersInfo( SPI_GETWORKAREA, 0, &rcWorkArea, 0 );
        return IntRect(int(rcWorkArea.left),int(rcWorkArea.top),int(rcWorkArea.right),int(rcWorkArea.bottom));
}


int main()
{
        IntRect workarea;
        workarea=getWorkArea();
        RenderWindow window(VideoMode(workarea.width,workarea.height),"Blupi Desktop",Style::None);
       
       //loop stuff
}
 

6
I thought I should mention what solved my problem in case anyone wants to know. The solution was to load the entire picture into an sf::image then to load the necessary rect from that into the amount of textures needed.  That way the texture doesn't have to be loading a rect directly from file and instead make the texture reusable by allowing the rect to change as its loading from the memory of sf::image. I don't know if this is a dummy solution or not but hey, it works. :P

7
Thankyou for your help.

8
Hello all.

I know I have asked about this before but I still haven't found a solution. My biggest problem is trying to load dimentionally large animations into a game without causing performance lagging or having an overabundance of texture objects. If I put any large dimention animations into a spritesheet its too large to load to texture. Recently I heard something about it being possible to load large textures using vertices. Is this correct? If so, How? My game isn't so dimentionally large.Its only 960x540 at most. There must be a way to display large frames without hitting performance issues. If I split up an animation thats large into dimentionally small frame rects and save each as files,and load each into the game,it still requires either loading a lot into memory or lloading from file as its needed. Loading from file as needed definitely causes lag I know.  Would it be possible to create several textures when they are needed for preloading and delete them after its done playing the animation?Or would this still cause lag?Also I know that each texture is loaded into memory anyways so why can't it treat one large image as memory the same way that it treats several loaded images as the same amount of memory?

9
Graphics / Re: Image doesn't save but gives no error report.
« on: November 17, 2023, 05:09:49 am »
Thanks for the advice.

10
Graphics / Re: Image doesn't save but gives no error report.
« on: November 17, 2023, 01:57:15 am »
I figured out why it wasn't showing any error. Directly after this section,the window closes and no messages are sent to the console.
        for(int x=0;x<numberOfFrames;x++)
        {      
               
                currentsize.x+=rect[x].width;
               

       
                if(currentsize.x<=totalsize.x)
                {
                        //
                        for(int x1=currentsize.x-rect[x].width;x1<currentsize.x;x1++)
                        {
                                for(int y=currentsize.y-rect[x].height;y<currentsize.y;y++)
                                {
                                        saveimage.setPixel(x1,y,image[x].getPixel(x1-currentsize.x,y-currentsize.y));
                                }
                        }      
                }
                else
                {
                        currentsize.y+=rect[x].height;
                        currentsize.x=0;
                }
        }


I commented this out.
I'm guessing the applied changes are out of the image's size scope? Does this seem to be what would normally happen if the set pixel was out of scope?

The error that does show now is "Failed to save image "test/sheet.png""




11
Graphics / Image doesn't save but gives no error report.
« on: November 16, 2023, 05:21:37 am »
I searched and searched for an existing topic about this problem because I think I made a similar topic previously. I just couldn't find it.
 
I keep running into this problem every time I make a program that is manipulating images.
Eventually the image does not save as a file and no error report shows up. I just can't figure why it doesn't save. Previous attempts have shown extreme flippancy by influence of non related changes that only sometimes fix it every other time it runs. With this specific program I'm not experiencing any flippancies yet.



string sframe[100];
int numberOfFrames;
RectangleShape shape;
Crop::loadcrop(string filetype)
{
       
        ifstream framelist("frames/frame list.txt");
        for(int a=0;a<100;a++)
        {
                getline (framelist,sframe[a]);
               
                if(sframe[a]=="")
                {
                        numberOfFrames=a-1;
                        break;
                }
                sframe[a]+=filetype;
        }
       
        shape.setOutlineColor(Color::Red);
        shape.setFillColor(Color::Transparent);
        shape.setOutlineThickness(2.f);
        shape.setSize(Vector2f(0,0));
}

int  currentframe=0;
Texture texture;
Sprite sprite;
IntRect rect[100];
IntRect selectrect;
bool firstclick=false; 
bool firsttap=false;   
Crop::setcrop(RenderWindow &window)
{
        if(currentframe<numberOfFrames)
        {
                texture.loadFromFile("frames/"+sframe[currentframe]);
                sprite.setTexture(texture);

                Vector2f MPosition=window.mapPixelToCoords(Mouse::getPosition(window));
               
                if(Mouse::isButtonPressed(Mouse::Left))
                {
                        shape.setPosition(MPosition.x,MPosition.y);
                       
                }
                if(Keyboard::isKeyPressed(Keyboard::Space))
                {
                        shape.setPosition(MPosition.x-shape.getSize().x,MPosition.y-shape.getSize().y);
                }
                shape.setSize(Vector2f(MPosition.x-shape.getPosition().x,MPosition.y-shape.getPosition().y));
                selectrect=IntRect(shape.getPosition().x,shape.getPosition().y,shape.getSize().x,shape.getSize().y);
                if(Keyboard::isKeyPressed(Keyboard::Return))
                {
                        if(firsttap==false)
                        {
                               
                                currentframe++;
                                firsttap=true;
                                rect[currentframe]=selectrect; 
                       
                        }
                }
                else
                {
                        firsttap=false;
                }
               
        window.draw(sprite);
        window.draw(shape);    
        }
        else
        {
                save();
                window.close();
        }
       
}





Crop::save()
{
        Image image[numberOfFrames];
        Vector2i totalsize;


        for(int x=1;x<numberOfFrames+1;x++)
        {
               
                image[x].loadFromFile("frames/"+sframe[x]);
               
               
        }
       
       
       
       
        Image saveimage;

        Vector2i currentsize;
        bool row=true;
        Vector2i sizecheck;
        for(int x=0;x<numberOfFrames;x++)
        {
                if(totalsize.x<1000)
                {
                        totalsize.x+=rect[x].width;
                }
               
                if(sizecheck.x<1000)
                {
                        sizecheck.x+=rect[x].width;
                }
                else
                {
                       
                        totalsize.y+=rect[x].height;
                        sizecheck.x=0; 
                }
               
        }

        saveimage.create(totalsize.x,totalsize.y,Color::Transparent);
       

        for(int x=0;x<numberOfFrames;x++)
        {      
               
                currentsize.x+=rect[x].width;
               

       
                if(currentsize.x<=totalsize.x)
                {
                        //
                        for(int x1=currentsize.x-rect[x].width;x1<currentsize.x;x1++)
                        {
                                for(int y=currentsize.y-rect[x].height;y<currentsize.y;y++)
                                {
                                        saveimage.setPixel(x1,y,image[x].getPixel(x1-currentsize.x,y-currentsize.y));
                                }
                        }      
                }
                else
                {
                        currentsize.y+=rect[x].height;
                        currentsize.x=0;
                }
        }
 
        saveimage.saveToFile("test/sheet.png");
        //WHY DO I KEEP RUNNING INTO THIS PROBLEM WHERE IMAGES DONT SAVE AND SHOW NO ERROR?!
       
}

Ok.So my code is extremely confusing to anyone not familiar with my terms but i'm absolutely certain that the save() function is where the problem is. And it is certain that the images are loaded  into 
Image image[numberOfFrames];
without any problems since these images have been saved as separate files before I tried combining them into one image.The important thing is getting the image called "saveimage" to save to file.

Any ideas what wrong here?

12
Window / Re: ffplay causes sfml window to freeze and crash.
« on: October 23, 2023, 11:10:06 pm »
I figured out the problem.

Ffplay was run by running a batch file using system();
Inside the batch file was this which took parameters that were sent through system();.

@echo off

cd VIDEOS

ffplay -autoexit  -left %1  -top %2  -x %3 -y %4  %5

pause


Having pause at the end of the batch file was making the sfml window freeze until a key was pressed while the console was selected.I solved the issue by replacing pause with EXIT /B.


13
Audio / Re: Playing sound causes frame or line skips.
« on: October 19, 2023, 04:45:26 pm »
I'm thinkin it gets the variables messed up because it causes large variable changing sections of code to be skipped.I tried making it local but that didn't work.I did however find out that moving that calling function fixes it.It would be good though to know why this changes anything.
So I moved it directly past the function it was skipping the rest of.
       


bool click(int left,int top,int width,int height)
{
                if(Mouse::isButtonPressed(Mouse::Left))
                {
                       
                        if(IntRect(left,top,width,height).contains(MPosition.x,MPosition.y))
                        {
                                if(released)
                                {
                                        released=false;
                                       
                                       
                                        //playsound() was here
                                       
                                       
                                        return true;
                                }
                        }
                        else
                        {
                                if(released)
                                {
                                       
                                       
                                }
                        }
                       
                        released=false;
                       
                }
                else
                {
                        released=true;
                        return false;
                       
                }
       
}      

void loop()
{
       
        MPosition=window.mapPixelToCoords(Mouse::getPosition(window));
       
        if(room==1)
        {
                if(leave)
                        tback.loadFromFile("1.png");
                leave=false;
       
                if(click(501,256,104,54))//click function
                {
                        playsound(0,"room.wav");//moved to here
                        room=2;
                        leave=true;
                }
               
        }
}

14
Window / ffplay causes sfml window to freeze and crash.
« on: October 19, 2023, 03:11:54 pm »
Just  like the title says"ffplay causes sfml window to freeze and crash".Any ideas how to bypass or fix this problem?

15
Audio / Re: Playing sound causes frame or line skips.
« on: October 17, 2023, 07:54:14 pm »
I only played the sound once and the function only loads the file once every start. Could that alone be too much to handle?

Update:
I tried it without using any arrays and theres no change.

Pages: [1] 2 3 4