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

Pages: [1]
1
After people told me to shorten the program I did it and here is the shortened version of the program with the same error as stated above.It only appears after a few moments into the program.If i hit continue the program works fine.However see the movement function?It does't work.The sprite refuses to move in any direction.However if i give a very large floating value in the move,then the sprite is displaced from it's position when i start the program and it stays there in that position with no further movement.For example if i write sprite.move(400.f,400.f) the sprite moves from (0,0) to (400,400) and stays there.It doesn't move any more. Here's the shortened version of the code:
   

       #include"SFML\Graphics.hpp"
       #include<iostream>
        int main()

    {
   sf::RenderWindow window(sf::VideoMode(640, 480), "CHECK",sf::Style::Default);
   std::cout << "WORKS";
   sf::Texture text;
   text.loadFromFile("bahamut.png");
   sf::Sprite sprite;
   sf::Clock frap;
   sprite.setTexture(text);
   while (window.isOpen())
   {
      float fps = frap.restart().asSeconds();
      sf::Vector2f movements;
      if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::A))
      {
         movements.y = 0;
         movements.x = -1 * fps;
      }
      else
           {
               if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key: :D ))
               {
               movements.y = 0;
               movements.x = 1 * fps;
                }
                else
                     {
                            if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::S))
                            {
                            movements.y = 1 * fps;
                            movements.x = 0;
                            }
                               else
                                  {
                                       if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::W))
                                        {
                                        movements.y = -1 * fps;
                                        movements.x = 0;
                                        }  
                                       else
                                           {
                                            movements.x = 0;
                                            movements.y = 0;
                                           }
                                  }
                    }
            }
        sprite.move(movements);
      window.clear();
      window.draw(sprite);
      window.display();
     
   }
    return 0;
    }
I improved upon the code to no effect.It still produces the same bug and error.
I used the dissassembler an found the error was caused in
00B37AEE  cmp         esi,esp 
in window.display().
Are the if else statements clear now?

2
General / Sprite doesn't move along with handler exception
« on: December 28, 2016, 01:44:40 pm »
Hello!So I want to create a game which i like a 2d puzzle of moving stuff around and solving them however I have encountered a few bugs.First of all,when i execute the program and press w,a,s or d it seems like it is trying to move but it can't move.....You'll now what i mean if you copy paste the codes in your visual studio c++(BTW its VS 2015 here).The animations for going up,down,right,left whatever work correctly.HOWEVER,ignoring that it doesn't move,after it works for a few minutes it stops working giving a handler exception:-
Quote
Exception thrown at 0x00000000 in ConsoleApplication1.exe: 0xC0000005: Access violation executing location 0x00000000.

If there is a handler for this exception, the program may be safely continued.
Here's the source code:-

#include <SFML\Graphics.hpp>
#include <iostream>
#include"Animatrix.h"
#include"move.h"
int main()
{
        sf::RenderWindow window(sf::VideoMode(1360, 720), "Larger SFML", sf::Style::Default);
        sf::Texture texture;
        texture.loadFromFile("bahamut.png");
        texture.setRepeated(false);
        float fraps = 0.0;
        sf::Clock fps;
        move playa(&texture, sf::Vector2u(4, 4), 1.f, window);
        while (window.isOpen())
        {
                sf::Event event;
                fraps = fps.restart().asSeconds();
                while (window.pollEvent(event))
                {
                        switch (event.type)
                        {
                        case sf::Event::Closed:
                                std::cout << std::endl << "I wont let u close!MUAHAHAHAHAHA!!";
                                return 0;
                                break;
                        case sf::Event::Resized:
                                std::cout << "New height" << event.size.height << " New width" << event.size.width << std::endl;
                                break;
                        case sf::Event::TextEntered:
                                printf("You have pressed =%c \n", event.text.unicode);
                                break;
                        }

                }
                sf::Sprite potty=playa.moves(fraps, 72.f, 1, 2, 3, 0);
                window.clear();
                potty.move(playa.movements);
                window.draw(potty);
                window.display();
        }
               
        return 0;
}

Here's the header of move:-

#pragma once
#include"Animatrix.h"
#include"SFML\Graphics.hpp"
class move
{
public:
        Animatrix mmovement;
        sf::RenderWindow window;
        sf::Vector2f movements;
        move(sf::Texture* texture, sf::Vector2u num, float stime, sf::RenderWindow &window);
        sf::Sprite moves(float fps,float speed, int left, int right, int up, int down);
        ~move();
};

Here's the definition:-

#include "move.h"
#include"Animatrix.h"
#include<iostream>


move::move(sf::Texture* texture,sf::Vector2u num,float stime,sf::RenderWindow &window):
        mmovement(texture,num,stime)
{
        movements.x = 0;
        movements.y = 0;
        window.clear();
        window.display();
}

sf::Sprite move::moves(float fps,float speed,int left,int right,int up,int down)
{
        sf::Sprite playas;
                if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::A))
                {
                        movements.y = 0;
                        movements.x = -speed*fps;
                        mmovement.currentimage.y = left;
                        mmovement.Update(fps);
                        playas = mmovement.show();
                        std::cout << "                         " << movements.x;
                        playas.move(movements);
                        return playas;
                }
                if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::D))
                {
                        movements.y = 0;
                        movements.x = speed*fps;
                        mmovement.currentimage.y = right;
                        mmovement.Update(fps);
                        std::cout <<"                         "<< movements.x;
                        playas = mmovement.show();
                        playas.move(movements);
                        return playas;
                }
                if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::S))
            {
                        movements.y = speed*fps;
                        movements.x = 0;
                        mmovement.currentimage.y = down;
                        mmovement.Update(fps);
                        playas = mmovement.show();
                        std::cout << "                         " << movements.x;
                        playas.move(movements);
                        return playas;
                }
                if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::W))
                {
                        movements.y = -speed*fps;
                        movements.x = 0;
                        mmovement.currentimage.y = up;
                        mmovement.Update(fps);
                        playas = mmovement.show();
                        std::cout << "                         " << movements.x;
                        playas.move(movements);
                        return playas;
                }
                else
                {
                        mmovement.currentimage.y = down;
                        mmovement.Update(fps);
                        playas = mmovement.show();
                        return playas;  
                }
}


move::~move()
{
}

Here's the header for animatrix:-

#pragma once
#include "SFML\Graphics.hpp"
class Animatrix
{
public:
        Animatrix(sf::Texture* texture,sf::Vector2u num,float stime);
        sf::Vector2u currentimage;
        sf::Vector2u size;
        float stime, fps;
        float totaltime;
        sf::Sprite show();
        void Update(float fps);
        sf::Sprite sprite;
        sf::Vector2u count;
        int j;
        ~Animatrix();
};
 

Here's the definition for animatrix:-

#include "Animatrix.h"
#include"SFML\Graphics.hpp"
#include<iostream>



Animatrix::Animatrix(sf::Texture* texture,sf::Vector2u num,float stime)
{
    sprite.setTexture(*texture);
        count.x = num.x;
        count.y = num.y;
        size.x= texture->getSize().x / count.x ;
        size.y = texture->getSize().y / count.y ;
        std::cout << std::endl << texture->getSize().x;
        currentimage.x = 0;
        currentimage.y = 0;
        totaltime = 0.0;
        this->stime = stime;
        j = 0;
}

void Animatrix::Update(float fps)
{
        this->fps = fps;
        totaltime = totaltime + this->fps;
        if( totaltime >= stime )
        {
        totaltime = totaltime - stime;
                if (j == 0)
                {
                        if (currentimage.x < count.x)
                        {
                                currentimage.x++;
                        }
                        if(currentimage.x==count.x-1)
                        {
                                j++;
                        }
                }
                else
                       
                {
                        j++;
                                currentimage.x--;
                                if (currentimage.x == 0)
                                {
                                        j = 0;
                                }
                }
        }
       
}
sf::Sprite Animatrix::show()
{
        sf::IntRect tempos;
        tempos.left = currentimage.x*size.x;
        tempos.top = currentimage.y*size.y;
        tempos.width = size.x;
        tempos.height = size.y;
        sprite.setTextureRect(sf::IntRect(tempos.left, tempos.top,tempos.width,tempos.height));
        return sprite;
       
}

Animatrix::~Animatrix()
{
}




PLEASE HELP!!!!!!!!!! :-[ :-[ :'(

3
General / Sprite animation gone wrong
« on: December 24, 2016, 08:48:42 pm »
After implementing a few bugs in the program i finally got it running with no errors.However there's a problem with the images loading up
Here's the main part:
#include <SFML\Graphics.hpp>
#include <iostream>
#include"Animatrix.h"
int main()
{
   sf::RenderWindow window(sf::VideoMode(1360, 720), "Larger SFML", sf::Style::Default);
   sf::Texture texture;
   texture.loadFromFile("bahamut.png");
   texture.setRepeated(false);
   Animatrix first(&texture,sf::Vector2u(4,4), 0.3f);
   float fraps = 0.0;
   while (window.isOpen())
   {   
      sf::Clock fps;
      sf::Event event;
      while (window.pollEvent(event))
      {
         switch (event.type)
         {
         case sf::Event::Closed:
            std::cout << std::endl << "I wont let u close!MUAHAHAHAHAHA!!";
            return 0;
            break;
         case sf::Event::Resized:
            std::cout << "New height" << event.size.height << " New width" << event.size.width << std::endl;
            break;
         case sf::Event::TextEntered:
            printf("You have pressed =%c \n", event.text.unicode);
            break;
         }
         
      }
      fraps = fps.restart().asSeconds();
      first.Update(fraps);
      window.clear(sf::Color::Red);
      window.draw(first.show());
      window.display();
   }
   
   return 0;
}

Here's the header of class animatrix:
#pragma once
#include "SFML\Graphics.hpp"
class Animatrix
{
public:
   Animatrix(sf::Texture* texture,sf::Vector2u num,float stime);
   sf::Vector2u currentimage;
   sf::Vector2u size;
   float stime, fps;
   float totaltime;
   sf::Sprite show();
   void Update(float fps);
   sf::Sprite sprite;
   sf::Vector2u count;
   int j;
   ~Animatrix();
};


Here's the definition of Animatrix.h:

#include "Animatrix.h"
#include"SFML\Graphics.hpp"
#include<iostream>



Animatrix::Animatrix(sf::Texture* texture,sf::Vector2u num,float stime)
{
    sprite.setTexture(*texture);
   count.x = num.x;
   count.y = num.y;
   size.x= texture->getSize().x / count.x ;
   size.y = texture->getSize().y / count.y ;
   std::cout << std::endl << texture->getSize().x;
   currentimage.x = 0;
   currentimage.y = 0;
   totaltime = 0.0;
   this->stime = stime;
   j = 0;
   std::cout << std::endl << "size.x="<< size.x;
}

void Animatrix::Update(float fps)
{
   this->fps = fps;
   totaltime = totaltime + this->fps;
   
   if( totaltime >= stime )
   {
   totaltime = totaltime - stime;
      if (j == 0)
      {
         if (currentimage.x < count.x)
         {
            currentimage.x++;
         }
         if(currentimage.x==count.x-1)
         {
            j++;
         }
      }
      else
         
      {
         std::cout <<std::endl<< "yo";
         j++;
            currentimage.x--;
            if (currentimage.x == 0)
            {
               j = 0;
            }
      }
   }
   
}
sf::Sprite Animatrix::show()
{
   sf::Vector2u tempos;
   tempos.x = currentimage.x*size.x;
   tempos.y = currentimage.y*size.y;
   std::cout <<std::endl<< "tempos.x= " << tempos.x;
   sf::Vector2u newpos;
   newpos.x = size.x + tempos.x;
   newpos.y = size.y + tempos.y;
   std::cout << std::endl << "newpos.x= " << newpos.x;
   sprite.setTextureRect(sf::IntRect(tempos.x, tempos.y, size.x + tempos.x, size.y + tempos.y));
   return sprite;
}

Animatrix::~Animatrix()
{
}

The images load up as given in attachment.The original image is the bahamut.png.The first up in the animation is bahamut1.png which seems like the obvious one to come.Then when it switches the sprites the sprite displayed is as in bahamut2.png.Same goes for the next time as in bahamut3.png.However in the final step after which it should run in reverse order the final sprite displays properly as in only the last texture is displayed i.e the 4th one only in bahamut.png.And then once it starts reversing the same follows again.


TLDR:1st and last image load up properly.2nd and 3rd image load in pairs as shown in bahamut2 and bahamut3.png
Please help I'm new to SFML!Don't go scolding me !

4
Graphics / Access violation reading location 0x00000004.
« on: December 23, 2016, 12:17:32 pm »
Exception thrown at 0x0F967B0E (sfml-graphics-d-2.dll) in ConsoleApplication1.exe: 0xC0000005: Access violation reading location 0x00000004.

If there is a handler for this exception, the program may be safely continued
I keep getting this error in a program i created for animation using sprites.I'm new to SFML so really any help will be appreciated.Before you all start telling me that i messed up to link the debug files,I have already triple,quadruple checked it.No i have linked to the debug files
I created a class for animation called animatrix and after scrutiny i found it which line was causing this particular error.(yeah i don't know how a line would cause a reading error in a dll)
Here's the main part:-

#include <SFML\Graphics.hpp>
#include <iostream>
#include"Animatrix.h"
int main()
{
        sf::RenderWindow window(sf::VideoMode(1360, 720), "Larger SFML", sf::Style::Default);
        sf::Texture texture;
        texture.loadFromFile("bahamut.png");
        texture.setSmooth(true);
        Animatrix first(&texture,sf::Vector2u(4,4), 2.f);
        while (window.isOpen())
        {  
                sf::Clock fps;
                sf::Event event;
                while (window.pollEvent(event))
                {
                        switch (event.type)
                        {
                        case sf::Event::Closed:
                                std::cout << std::endl << "I wont let u close!MUAHAHAHAHAHA!!";
                                return 0;
                                break;
                        case sf::Event::Resized:
                                std::cout << "New height" << event.size.height << " New width" << event.size.width << std::endl;
                                break;
                        case sf::Event::TextEntered:
                                printf("You have pressed =%c \n", event.text.unicode);
                                break;
                        }
                       
                }
                window.clear();
                        window.draw(first.Update(fps));
                window.display();
               
        }
       
        return 0;
}
Heres the header file of animatrix.

#pragma once
#include "SFML\Graphics.hpp"
class Animatrix
{
public:
        Animatrix(sf::Texture* texture,sf::Vector2u num,float stime);
        sf::Vector2u currentimage;
        sf::IntRect size;
        float stime, fps;
        float totaltime;
        sf::Sprite show();
        sf::Sprite Update(sf::Clock fps);
        sf::Sprite sprite;
        sf::Vector2u count;
        ~Animatrix();
};
 

Heres the definition of the functions and all of animatrix i.e animatrix.cpp:
#include "Animatrix.h"
#include<iostream>


Animatrix::Animatrix(sf::Texture* texture,sf::Vector2u num,float stime)
{
    sprite.setTexture(*texture);
        count.x = num.x;
        count.y = num.y;
        size.width= texture->getSize().x / count.x ;
        size.height = texture->getSize().y / count.y ;
        currentimage.x = 0;
        currentimage.y = 0;
        totaltime = 0.0;
        this->stime = stime;

}

sf::Sprite Animatrix::Update(sf::Clock fps)
{  
        this->fps = fps.restart().asSeconds();
        totaltime = totaltime + this->fps;
        std::cout << totaltime;
        if( totaltime >= stime )                  //ERROR IS CAUSED HERE BY THE > CONDITION.Whenever i remove
        {                                                    // >condition it works fine.It works in = condition too but whenever i
                                                              //put > sign the error crops up
                std::cout << "word";
                totaltime = totaltime - stime;
                sf::Sprite thing;
                std::cout << std::endl << "does change occur here?" << currentimage.x << std::endl;

                if (currentimage.x<count.x)
                {
                        std::cout << "WORKED!";
                        currentimage.x++;
                        thing = show();
                        return thing;

                }
                else
                {

                        std::cout << std::endl << "didit";
                        while (currentimage.x != 0)
                        {
                                std::cout << std::endl << "current<<" << currentimage.x;
                                currentimage.x--;
                        }
                        std::cout << std::endl << "HERE" << currentimage.x;
                        thing = show();
                        return thing;

                }
        }
       
}
sf::Sprite Animatrix::show()
{
        sf::Vector2u tempos;
        tempos.x = currentimage.x*size.width;
        tempos.y = currentimage.y*size.height;
        sprite.setTextureRect(sf::IntRect(tempos.x, tempos.y, size.width + tempos.x, size.height + tempos.y));
        return sprite;
}

Animatrix::~Animatrix()
{
}

(*I included iosteam for checking the errors in various segments of the code)
 PLEASE HELP I DON'T WANT TO STOP SFML HERE PLEASE!!! :'( :'(

Pages: [1]
anything