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

Pages: 1 ... 3 4 [5] 6
61
Graphics / Animation......again
« on: September 04, 2011, 01:30:59 am »
Hello everyone. Ive made an animation class that inherits from sprite, and uses a subrect to change the frames. Im trying to make a class that holds multiple animation objects. However, the problem with this is that I can't use the functions of sprite with this object. For example say this class was called mario.
I could do Draw(*Mario.getPointerOfCurrentSprite)
but I cant do mario.move()
or mario.SetX() because each Animation(Sprite) has its own location. Any Help?

62
Graphics / thanks....again
« on: September 02, 2011, 02:06:08 am »
wow sfml has a nice community.thanks for all the help. I finally got an animation class. I based it off the one above.
Code: [Select]

using namespace std;

class Animation : public sf::Sprite {

public:
    Animation(string location,int numFrames,float Delay);
    void setCurrentFrame(int frame);
    int getCurrentFrame();
    void setNumOfFrames(int frames);
    int getFrameWidth();
    void setDelay();
    int getDelay();
    void play();
    void update();
    void pause();
    void reset();

private:
    sf::Image image;
    sf::Clock timer;
    int currentFrame;
    int numOfFrames;
    int frameWidth;
    float frameTime;
};
Animation::Animation(string location,int numFrames,float Delay) {

    if (!image.LoadFromFile(location))
        std::cout<<"unable to load from "<<location;
    SetImage(image);

    currentFrame=1;
    numOfFrames=numFrames;
    frameWidth=GetSize().x/numOfFrames;
    frameTime=Delay;

    SetSubRect(sf::IntRect(0,0,frameWidth,GetSize().y));
}
void Animation:: setCurrentFrame(int frame) {
    currentFrame=frame;
}
int Animation::getCurrentFrame() {
    return currentFrame;
}
void Animation::setNumOfFrames(int frames) {
    numOfFrames=frames;
}
int Animation:: getFrameWidth() {
    return frameWidth;
}
void Animation::play() {
    SetSubRect(sf::IntRect((currentFrame-1)*frameWidth,0,currentFrame*frameWidth,GetSize().y));
}
void Animation::update() {
    if (timer.GetElapsedTime() >= frameTime) {
        if (++currentFrame > (numOfFrames))
            currentFrame = 1;
        timer.Reset();
    }
}

(ignore all the useless functions)

63
Graphics / How to do animation
« on: September 01, 2011, 10:38:36 pm »
okay so i'm trying to make a animation by inheriting from sf::sprite.However, when I call App.Draw(Sprite), it shows up as a white box.

Oh yeah, this is not related to the problem above, which i found the soluton to.

64
Graphics / Problem loading images
« on: September 01, 2011, 06:38:49 pm »
never mind, i found out what the working dir was. sorry

65
Graphics / Problem loading images
« on: September 01, 2011, 05:18:27 pm »
it is, the project runs properly, everything works as it should except the images, which are white blocks.

66
Graphics / Problem loading images
« on: September 01, 2011, 04:25:17 pm »
Hello everyone, I've encountered a problem with SFML using code::blocks. Whenever I use code::blocks to run a program that has to load an image, it is unable to do so. The console says the reason is : unable to do so. As a result I have to go to the folder where the exe is and run it from there. Help is appreciated.thanks

67
Graphics / figured it out
« on: September 01, 2011, 02:15:55 am »
So i found out why the image was white. When I run  the program from code::blocks, the image doesn't load. I tried it from the actual folder where the exe is and it works fine. I tried running code::blocks with as admin, but doesnt work. lol sorry for so many posts.

68
Graphics / new problem
« on: September 01, 2011, 02:09:05 am »
lol never mind i got it. Aaaaaand theres a new problem. Every time I restart my computer or log off and back on, the loading images dont work. All that sows up is a white image. However, when i start a new project, the image loads properly, even if its the same exact code!!As soon as i log off, the project becomes corrupt, and i have to start a new one. PLZ HELP. im gonna cry...

69
Graphics / ugh
« on: September 01, 2011, 01:23:23 am »
also, why arnt the img tags working?

70
Graphics / back again
« on: September 01, 2011, 01:22:24 am »
soory guys for the break, but i was going back to basics with sfml. Anyways, I was doing clocks all over again and I did this, which was posted by one of the posters in this thread.
Code: [Select]
if (timer.GetElapsedTime() >= 1) {
            if (++whichOne > 2) {
                whichOne = 0;
                timer.Reset();
            }
        }

std::cout<<whichOne;



This is what it produces:





Its supposed to constantly say zero, one then two, for the same amount of time, but it does 0 for 1 second, then quickly 1 and 2. Help!

71
Graphics / How to do animation
« on: August 26, 2011, 10:10:19 pm »
animation. a proper example of animation. maybe of two things bieng animated at the same time?

72
Graphics / How to do animation
« on: August 26, 2011, 01:16:29 am »
I would really appreciate it if someone could give me a proper example. thanks

73
Graphics / How to do animation
« on: August 25, 2011, 02:04:50 am »
I know I suck at this, but an example code would be very very useful.

74
Graphics / my try
« on: August 24, 2011, 06:24:54 pm »
Hello Guys, I tried this but it doesnt works. The image stays the same unless I press the Right button.

Code: [Select]

#include <iostream>
#include <SFML/Graphics.hpp>

using namespace std;
//using namespace sf;

int main() {

    sf::Sprite marioSprite;
    sf::Image run[3];
    sf::RenderWindow App(sf::VideoMode(800, 600, 32), "JustAnimation");
    int whichOne = 0;
    sf::Clock timer;

    if (!run[0].LoadFromFile("resources/0000.png")) {}
    if (!run[1].LoadFromFile("resources/0001.png")) {}
    if (!run[2].LoadFromFile("resources/0002.png")) {}

    marioSprite.SetImage(run[0]);

    while (App.IsOpened()) {
        App.Clear(sf::Color::Black);

        sf::Event Event;

        if (App.GetEvent(Event))
            if (Event.Type == sf::Event::Closed)
                App.Close();

        App.Draw(marioSprite);

        if (timer.GetElapsedTime()<100) {
            whichOne=0;
        } else if (timer.GetElapsedTime()<200) {
            whichOne=1;
        } else {
            whichOne=2;
            timer.Reset();
        }
        marioSprite.SetX(marioSprite.GetPosition().x);

        if (App.GetInput().IsKeyDown(sf::Key::Right)) {
            marioSprite.SetX(marioSprite.GetPosition().x+2);

        }

        marioSprite.SetImage(run[whichOne]);


        App.Display();
    }

    return 0;
}

75
Graphics / thanks
« on: August 24, 2011, 05:47:13 pm »
wow thanks guys!

Pages: 1 ... 3 4 [5] 6