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

Pages: [1] 2
1
I would like to add that this is just a part of a class to move an animation.So if some parts seem useless or missing just try to remember that this is not the entire code

2
I know about event handling and such I just wanted to show you all the minimum code required to pose the problem faced by me.OHH I see what you meant by that if else statement yeah it's much clearer now. :D Thanks.
I found the problem.It shows me error is caused by the window.display line.However if I use a function to display in the window there's no error apparently.

3
Is it clear now?The 4 brackets above sprite.move() are the closing braces of the else statements

4
I edited the code to no effect can someone please help?!

5
Thanks.Man I kept thinking if I had done something stupid and I was right...

6
That smiley over there is supposed to be :  D   ....smh

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

8
General / Re: Sprite doesn't move along with handler exception
« on: December 29, 2016, 09:46:50 pm »
the problem is that it shows after the program has run for a few minutes.And on breaking at that point it shows the next line to run is window.display().So I have no idea why suddenly the sprite can't be displayed when it was being displayed for the last few minutes.Anyways thnx

9
General / Re: Sprite doesn't move along with handler exception
« on: December 29, 2016, 01:07:34 pm »
I have checked the dlls and lib and they are not mixed up as far as I can tell.What about the sprite not moving?Any suggestions?

10
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!!!!!!!!!! :-[ :-[ :'(

11
General / Re: Sprite animation gone wrong
« on: December 27, 2016, 02:58:58 pm »
TY

12
General / Re: Sprite animation gone wrong
« on: December 25, 2016, 09:10:20 am »
Could you please elaborate?And the coordinates that i get after adding are the correct ones.I checked using cout.Can you please explain why the error happens if i add them?

13
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 !

14
Graphics / Re: Access violation reading location 0x00000004.
« on: December 24, 2016, 12:57:50 pm »
OHHHHHHHHHHHHHHHHHHHHHH THANKS A BUNCH!Stupid me :-X :-\

15
Graphics / Re: Access violation reading location 0x00000004.
« on: December 24, 2016, 07:30:54 am »
it is returning a sprite "thing" both from the if part and it's else part.Where's the part which doesn't return the sprite

Pages: [1] 2
anything