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

Pages: [1]
1
System / Re: making time counte using clock
« on: April 10, 2020, 10:44:28 pm »
clock.restart()

https://www.sfml-dev.org/documentation/2.5.1/classsf_1_1Clock.php#a123e2627f2943e5ecaa1db0c7df3231b
why i cant restart the clock from the method inside the class directly
but it worked when i set the parameter to (Clock & clock)

2
System / Re: making time counte using clock
« on: April 10, 2020, 05:51:54 pm »
Can you rephrase the question, as I'm unsure what you're trying to achieve exactly?

i want to know how to reset the clock after it hit 60 seconds so  i can get rid off this line

//set the int seconds to elapsed time - 60 if minutes have passed
        //bec elapsed after 1 minute doesnt reset will be 61 seconds
        seconds = time.asSeconds()- 60 * minutes;

3
System / making time counte using clock
« on: April 08, 2020, 07:43:17 pm »
i have  wrote a time counter function to display time on window but i i want help to right it in cleaner form
Text Menu::returnTime(Clock clock)
{
        //to set time variable to the elapsed time  
        time = clock.getElapsedTime();

        //set the int seconds to elapsed time - 60 if minutes have passed
        //bec elapsed after 1 minute doesnt reset will be 61 seconds
        seconds = time.asSeconds()- 60 * minutes;

        //if seconds less than 10 draw extra 0 so it look like time: 0:00 not time : 0: 0
        if (seconds < 10)
                str = "Time: " + to_string(minutes) + ":" + "0" + to_string(seconds);
        else
                str = "Time: " + to_string(minutes) + ":" +  to_string(seconds);  //else set it normaly cast variables to strings

       
        if (seconds == 60)
                minutes++;


        //set the text string to next time string
        timeText.setString(str);

        return timeText;
}

and also how i can do reset clock if seconds = 60

4
System / checking for events
« on: March 29, 2020, 01:51:14 pm »
iam trying to make a menu
i need to check if the user pressed a button to move throw the menu
when i tried doing this function then calling it in main
if (Keyboard::isKeyPressed(Keyboard::S))
        {
                selectedText[selectedNum].setFillColor(Color::White);
                selectedNum++;
                selectedText[selectedNum].setFillColor(Color::Blue);
               
        }
the it goes throw all menu then the program crash
else if i use
if (event.type == Event::KeyPressed && event.key.code == Keyboard::S)
                                        menu.moveDown();
it works fine
 so what is the difference between these two ways what did ido wrong

5
Graphics / my animation function is not working
« on: March 13, 2020, 08:11:26 pm »
i do have problem with my animation
when going to last fram or picture in sprite sheet the animation goes blank for a sec then starts all over again
i have read about this is cause by the rectangle is bigger than actual texture and can be fixed if i set repeated to true but my texture coordinates are 350 for width and 100 for height
and i do have another problem that the animation  is too slow how can i fix it?
and how can i fix the animation not to go blank after last picture?

here is my code for animation function

Sprite Player::walk()
{
        if (clock.getElapsedTime().asSeconds() > 1.f)
        {
               
                if (source1 == 350)
                        source1 = 50;
       
                else
                        source1 += 50;
                cout << source1<<"\n";
                player.setTextureRect(IntRect (source1, 50 * direction, 50, 50));
                clock.restart();
        }
        return player;
}
 
code for movment
void Player::move()
{
        if (Keyboard::isKeyPressed(Keyboard::W))
                player.move(0.f, -10.f);
        if (Keyboard::isKeyPressed(Keyboard::A))
        {
                player.move(-10.f, 0.f);
                direction = 1;
                walk();
               
        }
        if (Keyboard::isKeyPressed(Keyboard::S))
                player.move(0.f, 10.f);
        if (Keyboard::isKeyPressed(Keyboard::D))
        {
                player.move(10.f, 0.f);
                direction = 0;
                walk();
               
        }
         

}
loading files
Player::Player() :player(texture, source),source1(50)
{
        //load the running animation
        if (!texture.loadFromFile("running4.png"))
        cout << "Error loading player image";
        player.setScale(3, 3);
        direction = 0;
       
}
class player
#pragma once
#include "Map.h"
class Player
{
public:
        Texture texture;
        IntRect source;
        Sprite player;
        Clock clock;
        int direction;
        int source1;

public:
        Player();
        ~Player();
        Sprite walk();
        void move();
        void boundary();
        bool isAnyKeyPressed();
};

 

Pages: [1]