Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: rendering image  (Read 3048 times)

0 Members and 1 Guest are viewing this topic.

raminlich

  • Newbie
  • *
  • Posts: 16
    • View Profile
    • Email
rendering image
« on: February 18, 2015, 05:41:11 pm »
hi all
first of all im new to sfml and for my question because of idont know Appropriate word for search or title of this topic.
ok, let say i have a texture like this   http://persianupload.com/kleeja/do.php?imgf=142427696859961.png




now i want to make this little boy run  :) i mean i want to render this texture with 85*137px until end of texture.
in simple: i want this boy in my game that looks running and i want to know what class i must use for it.
note: i know how to render it in my window i just dont know how to make it runable  ;D

and look at this http://persianupload.com/kleeja/do.php?imgf=14242779300291.png
 this is my runed game i make texture smaller with this code

playerSp.setTextureRect(IntRect(0, 0, 87, 134));

but doesnt do anything just stand like you see in pic

sorry for my bad english  :-\
and thanks ;)
« Last Edit: February 18, 2015, 05:51:16 pm by raminlich »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: rendering image
« Reply #1 on: February 18, 2015, 06:03:24 pm »
Your game logic will have to handle the animation steps. So instead of setting it just to one specific sub-rectangle of the texture you need to change it with a certain frequency to make it look as if it was running.

There are also dedicated animation sprite classes on the wiki or you could take a look at Thor which also provides that feature.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

raminlich

  • Newbie
  • *
  • Posts: 16
    • View Profile
    • Email
Re: rendering image
« Reply #2 on: February 18, 2015, 09:09:12 pm »
Hi again
thank u so much it help me a lot but.....
i found this page https://github.com/SFML/SFML/wiki/Source%3A-AnimatedSprite

now i add this Animation.hpp, cpp and  AnimationSprite.hpp,cpp to my project but i get huge errors  :-[
here is pic of them
http://persianupload.com/kleeja/do.php?imgf=142429067078071.png

please see this :-\
and thank u again.
« Last Edit: February 18, 2015, 09:16:55 pm by raminlich »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: rendering image
« Reply #3 on: February 18, 2015, 09:26:52 pm »
Did you actually add it to your project? (Not just open them in VS)
Do you link SFML?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

raminlich

  • Newbie
  • *
  • Posts: 16
    • View Profile
    • Email
Re: rendering image
« Reply #4 on: February 19, 2015, 12:15:59 am »
yes
yes i add them one by one with  left click on project add->header or cpp in Vs 2013 express
and i copy paste the codes into it
and here this is my project configuration:
http://persianupload.com/kleeja/do.php?imgf=142430139487671.png

am  i doing wrong? :-\

thanks

Spirro

  • Jr. Member
  • **
  • Posts: 66
    • View Profile
Re: rendering image
« Reply #5 on: February 19, 2015, 03:43:20 am »
and here this is my project configuration:
http://persianupload.com/kleeja/do.php?imgf=142430139487671.png

am  i doing wrong? :-\

thanks
You are linking the static libraries(the ones like sfml-graphics-s.lib), but you didn't set SFML_STATIC for the preprossesor.  If you want to use static libs you have to do that.  If not, you don't want to link static libs.  Re-read http://www.sfml-dev.org/tutorials/2.2/start-vc.php.  It's all in there.

raminlich

  • Newbie
  • *
  • Posts: 16
    • View Profile
    • Email
Re: rendering image
« Reply #6 on: February 19, 2015, 09:51:49 am »
 :-[ :-[

ok i try SFML_STATIC and still same errors also try to link them dynamicly but still same.......

 :-[ :-[ please anybody can help? :'(

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: rendering image
« Reply #7 on: February 19, 2015, 12:28:12 pm »
You've setup something wrong, but it's impossible for us to figure out what. You should learn how to properly work with VS and figure things out on your own. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

raminlich

  • Newbie
  • *
  • Posts: 16
    • View Profile
    • Email
Re: rendering image
« Reply #8 on: March 03, 2015, 10:48:44 am »
hi again
after give uping for couple of days finaly i went back and reset every thing and now i dont see the errors ;)
now i got another problem i dont know is in my code or anything else!

here is my code i will be grateful to see this!

 
#include "stdafx.h"
#include <SFML\Graphics.hpp>
#include "AnimatedSprite.hpp"
#include <iostream>
using namespace sf;


int main()
{
        Vector2i vectors(800, 600);
        RenderWindow window(VideoMode(vectors.x,vectors.y),"anime");

        Texture runner;

        runner.loadFromFile("E:\\Resource\\runner.png");

        Animation run;
        run.setSpriteSheet(runner);



        Animation* current = &run;

        AnimatedSprite animatedSprite(seconds(0.2), true, false);

        animatedSprite.setPosition(sf::Vector2f(vectors / 2));

        Clock frameclock;

        float speed = 80.f;

        bool noKeyPressed=true;

        while (window.isOpen())
        {
                sf::Event event;
                while (window.pollEvent(event))
                {
                        if (event.type == sf::Event::Closed)
                                window.close();
                }
                Time frametime= frameclock.restart();
                Vector2f movement(0.f, 0.f);

                if (Keyboard::isKeyPressed(Keyboard:: D)){  // i put little space because it will show something like this in this forum :D
                        current = &run;
                        movement.x += speed;
                        noKeyPressed = false;
                }
                animatedSprite.play(*current);
                animatedSprite.move(movement *frametime.asSeconds());
                if (noKeyPressed){
                        animatedSprite.stop();
                }
                noKeyPressed = true;

                animatedSprite.update(frametime);

                window.clear();
                window.draw(animatedSprite);
                window.display();
        }

        return 0;
}
 

and here is my screenshot of my problems
http://8pic.ir/images/7bc8kexg2llgh8groffj.png
thanks
« Last Edit: March 03, 2015, 11:33:56 am by raminlich »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: rendering image
« Reply #9 on: March 03, 2015, 11:12:53 am »
Please use [code=cpp][/code] tags and upload your image either directly as attachment or to an actual image hoster and not some download hoster...
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/