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

Pages: [1] 2
1
Thank you Laurent. This is exactly what i needed.
As for those warnings: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11|
I know i shouldn't bother with them, but i wanted my code better, and now i have.

2
After many battles with IntRect i successfully initialized it like this:
player.cpp
Player::Player(VideoMode VMo){
    playerRectSourceSprite.left = 0;
    playerRectSourceSprite.top = 0;
    playerRectSourceSprite.width = 60;
    playerRectSourceSprite.height = 60;
}
 
Why i couldn't do this like this:
playerRectSourceSprite(0, 0, 60, 60);
 
or like this 
IntRect playerRectSourceSprite(0, 0, 60, 60); // I know this one is definitely wrong but i tried this as well
 
Of course i could initialize it this way:
playerRectSourceSprite = {0, 0, 60, 60}; // but then i receive warnings and i read this isn't best way of initializing
 
but in the same moment i can initialize Sprite position in the same constructor in a way i can't IntRect:
playerS.setPosition(50, 450);
 
Is there any reason behind it, or maybe there is different way to initialize IntRect collectively? Or, maybe, i am doing something incorrectly?

3
Graphics / Re: Why can't i see my sprite?
« on: April 16, 2017, 08:26:54 pm »
I know that this can be very easy to solve. But i'm looking in my code 3rd day today and can't see what's wrong. When i run program everything is running, and i think that window.draw(player1.playerS) should see playerS inside Player class. But after moving, adding and removing code for few hours a day i don't have more ideas. It's hard to say, but i got stuck.

4
Graphics / Why can't i see my sprite?
« on: April 16, 2017, 07:10:50 pm »
I'm trying to implement constructors and inheritence in my program. In previous version, everything was running ok, but now i can't draw my sprite (player1.playerS). I dont know where problem or problems are lying.
Here are files of my program:
sfml001.cpp:
#include <SFML/Graphics.hpp>
#include "events.h"
#include "player.h"

using namespace sf;

int main()
{
    VideoMode VMode(1280, 720, 32);
    RenderWindow window( VMode, "Game");

    Player player1;
    window.setFramerateLimit(120);
    while(window.isOpen()){ //zwraca w petli  while informacje, czy okno aplikacji jest otwarte
        EventsInProgram event1(window, player1.plRectSourceSprite);

        window.clear(Color(0, 110, 0));

        window.draw(player1.playerS);
        window.display();
    }
    return 0;
}
 

player.cpp
#include <SFML/Graphics.hpp>
#include "player.h"
#include <string>
using namespace sf;
using namespace std;
Player::Player(VideoMode VM , IntRect plRectSourceSprite){//, string tex){
VMode = VM;
Texture playerT;
playerT.loadFromFile("heroanimation.png");
Sprite playerS(playerT, plRectSourceSprite);
}
 

player.h
#pragma once
#include <SFML/Graphics.hpp>
#include <string>
using namespace sf;
using namespace std;

class Player{
public:

    Sprite playerSprite;
    IntRect playerRectSourceSprite;
    IntRect plRectSourceSprite;
    Texture playerT;

    VideoMode VMode;
    Clock playerMoveClock;
    Clock playerAnimationClock;
    Sprite playerS;
    Vector2f playerSpeedVector;
    Vector2f playerPosition;
    int playerSpeed = 300;
    //int playerLives = 1;
private:

public:
    Player(VideoMode VM = {1280, 720, 32}, IntRect plRectSourceSprite = {0, 0, 60, 60});//, string tex ="heroanimation.png");//, Texture tex );
    ~Player();
};
 

events.cpp
#include <SFML/Graphics.hpp>
#include "events.h"
#include "player.h"
using namespace sf;

EventsInProgram::EventsInProgram(RenderWindow & window, IntRect  playerRectSourceSprite){
    eventList(window, playerRectSourceSprite);

}

 EventsInProgram::~EventsInProgram(){}

void EventsInProgram::eventList(RenderWindow & window,   IntRect  playerRectSourceSprite){//, Event & zdarzenie){
       Event zdarzenie;
       bool pause01 = 0;
     while( window.pollEvent( zdarzenie ) ){
            if( zdarzenie.type == Event::Closed ){
                window.close();
            }
            if(Keyboard::isKeyPressed(Keyboard::Escape)){
                if(pause01 = 0) pause01 = 1;
                else if(pause01 = 1) pause01 = 0;
            }
            if(zdarzenie.type == Event::KeyReleased) playerRectSourceSprite.top = 0;
        }
}
 

events.h
#pragma once
#include <SFML/Graphics.hpp>
#include "player.h"
using namespace sf;

class EventsInProgram {
public:
    EventsInProgram(RenderWindow & window, IntRect  playerRectSourceSprite);
     ~EventsInProgram();

    void eventList(RenderWindow & window, IntRect  playerRectSourceSprite);

};
 

5
Your'e advices are great! Exactly what i need.

6
It looks nice and easy. Thanks!

7
I mean, i dont need pixel perfect detection but this rectangle collision is a bit to little. I think very good option could be if i could exclude some rectangles from the main rectangle, and then check for collision. Like on my drawing below.



8
I solved it... partially but solved it.
Instead of what i started:  if((playerPosition.x + 60) == (enemyPosition.x)) playerSpeedVector.x = -10;
I have this:

                if((playerPosition.x) <= (enemyPosition.x)) playerSpeedVector.x = -10;
                if((playerPosition.x) >= (enemyPosition.x)) playerSpeedVector.x = 10;
                if((playerPosition.y) <= (enemyPosition.y)) playerSpeedVector.y = -10;
                if((playerPosition.y) >= (enemyPosition.y)) playerSpeedVector.y = 10;
 

But now when my object bouncing from second object it bounce diagonally. And i want to bounce it, well, not diagonally. Can someone help me with that?

9
In this fragment of my code, that i posted below i expect to make the object stop moving in one direction, but let him to move in other directions. Like this:


But the outcome is that they colide, because of getGlobalBounds, but i can move my object freely in every direction and through second object.
I have this in code: playerPosition.x + 60 to move x point to the end of x axis of the object, but i think it does nothing.
And when i change equality sign "==" to not equal it forbid me from entering the object from both sides, and when i enter from back side it slowly move me towards -x till it push me out from object.
What is wrong with this code?

     Vector2f playerPosition;
     Vector2f enemyPosition;
     playerPosition = playerS.getPosition();
     enemyPosition = enemy1S.getPosition();

             if(playerS.getGlobalBounds().intersects(enemy1S.getGlobalBounds())) {
                playerS.setColor(Color(255, 80, 0, 200));

                if((playerPosition.x + 60) == (enemyPosition.x)) playerSpeedVector.x = -10;
             }
             else playerS.setColor(Color(255, 255, 255));

            playerS.move(playerSpeedVector * time.asSeconds());
            heroMoveClock.restart();
 


10
General / Strange behavior while moving sprite
« on: March 01, 2017, 12:14:01 am »
When i'm moving sprite in right, up and down direction everything is ok. But when i'm moving left, sprite is moving about 2 times faster. I have repaired this by adding two additionall lines of code. But still i have no idea why this is happening. And should i add this 2 lines below every "if/else"? Or an error is somewhere else? This two additionall lines of code are:
                  heroSpeedVector.x = 0;
                  heroSpeedVector.y = 0;

And this is fragment of code responsible for moving.
     
            const float heroSpeed = 0.1;
            Vector2f heroSpeedVector;

            if(Keyboard::isKeyPressed(Keyboard::Right)){
               heroSpeedVector.x = heroSpeed;
                 guyRectSourceSprite.top = 60;
             }
             else heroSpeedVector.x = 0;
            heroS.move(heroSpeedVector);

              if(Keyboard::isKeyPressed(Keyboard::Left)){
               heroSpeedVector.x = -heroSpeed;
                guyRectSourceSprite.top = 120;
             }
             else heroSpeedVector.x = 0;
            heroS.move(heroSpeedVector);
                heroSpeedVector.x = 0;
                heroSpeedVector.y = 0;

              if(Keyboard::isKeyPressed(Keyboard::Up)){
             heroSpeedVector.y = -heroSpeed;
             guyRectSourceSprite.top = 180;
             }
             else heroSpeedVector.y = 0;
            heroS.move(heroSpeedVector);

             if(Keyboard::isKeyPressed(Keyboard::Down)){
            heroSpeedVector.y = heroSpeed;
             guyRectSourceSprite.top = 240;
             }
             else heroSpeedVector.y = 0;
            heroS.move(heroSpeedVector);

 

11
Ok, i found my "error".
I just changed lines:
  Sprite heroS;                         
  heroS.setTexture(heroT);
into:
  Sprite heroS(heroT, guyRectSourceSprite);

I realised that that was remnant from before. But the point is - first frame of animation was always displaying whole .png file and the second one after refreshing was a proper one. That was because of lack of IntRect in previous 2 lines of that code.
Thx for pointing on solution.

12
I have a texture for animated creature that is controlled by a player. When I'm starting a program for a short amount of time I can see whole texture. And then after, maybe 1/5 or even 1/10 of a second a proper animation starting. Can I avoid displaying whole texture? Texture size is 300x300px, and animated sprite is 60x60, and its rather very small size of 7,52KB. File format is .PNG. In the same time I'm displaying another animation (smaller one - 300x50px, .PNG, independent from a player) and that one is ok.

13
Yes: Starting from SFML 2.2, when static linking, you will have to link all of SFML's dependencies to your project as well.
Thanks for help and for your patience.

14
That solved the problem with missing debug files. But now I have another one. After compiling project there is something like that:

I thought that this could be problem with downloaded file, so I redownloaded it and CMake it again. And outcome is the same. Then I downloaded this ready to use file:GCC 4.9.2 TDM (SJLJ) - 64-bit and same thing happened. I am starting to believe in this Murphy law: Anything That Can Possibly Go Wrong, Does.

15
I did everything like on this tutorial:https://www.youtube.com/watch?v=0LGzJP3k7M4
And now have this:

Can problem be somewhere else, because i checked it twice doing above. And why my directory contain only -s versions of these files?

Pages: [1] 2
anything