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

Pages: [1]
1
General / Re: Unable to initialize a reference of type....
« on: April 19, 2020, 10:26:17 am »
You're right, I know c very well, but c ++ not too much, I will try to do simple things without SFML, and when I know this language better I will try to use SFML.
Have a nice day  :D

2
General / Unable to initialize a reference of type....
« on: April 19, 2020, 09:18:03 am »
Hello,
i am having problems with this program,
it gives me three errors related to the "Draw" function,
unable to initialize a reference of type "sf :: Sprite &" (not qualified by const) with a value of type "sf :: RenderWindow",E0434 unable to initialize a reference of type "int &" (not qualified by const) with a value of type "sf :: Sprite",E0434 unable to initialize a reference of type "sf :: RenderWindow &" (not qualified by const) with a value of type "int",   and I don't know why,sorry for the inconvenience.


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



using namespace sf;
using namespace std;

void Draw(RenderWindow& window, Sprite& g, Sprite& s);
void Move(int& keyTime, RenderWindow& window, Sprite& g,Sprite& s, Texture& t, Texture& p);
int main()
{
        int keyTime = 8;
        RenderWindow window(VideoMode(640, 420), "too awesome for a title");
        window.setFramerateLimit(60);
        Texture t;
        t.loadFromFile("images/Terrain.png");
        Sprite s(t);
        Texture p;
        p.loadFromFile("images/player.png");
        Sprite g(p);
       
        s.setTextureRect(IntRect(0, 0, 64, 64));
        s.setPosition(Vector2f(300,260));
        s.setTexture(t);
       
        g.setTextureRect(IntRect(0, 0, 20, 50));
        g.setPosition(Vector2f(window.getSize().x / 2, window.getSize().y / 2));
        g.setTexture(p);

       


        while (window.isOpen())
        {
                Event e;
                while (window.pollEvent(e))
                {
                        if (e.type == Event::Closed)
                                window.close();

                        if (e.KeyPressed && e.key.code == Keyboard::Escape)
                                window.close();
                }
               
                Move(g,keyTime,window,s,t,p);
                Draw(window,g,s);
               
        }


        return 0;
}


void Move(int& keyTime, RenderWindow& window, Sprite& g, Sprite& s, Texture& t, Texture& p)
{
        if (keyTime < 8)
                keyTime++;

        if (Keyboard::isKeyPressed(Keyboard::A) && keyTime >= 8 && g.getPosition().x > 0)
        {
                g.move(-10.f, 0.f);
                keyTime == 0;

        }
        if (Keyboard::isKeyPressed(Keyboard::D) && keyTime >= 8 && g.getPosition().x + p.getSize().x < window.getSize().x)
        {
                g.move(10.f, 0.f);
                keyTime == 0;
        }

       

        if (Keyboard::isKeyPressed(Keyboard::S) && keyTime >= 8 && g.getPosition().y + p.getSize().x < t.getSize().y)
        {
                g.move(0.f, 10.f);
                keyTime == 0;
        }
}

void Draw(RenderWindow& window, Sprite& g, Sprite& s)
{
        window.clear();

        //draw stuff...

        window.draw(g);
        window.draw(s);

        window.display();

}
 

(sorry for the bad english)
(sorry for the bothering)

3
General / Re: Draw two different sprites
« on: April 19, 2020, 08:13:04 am »
Thank you!
 :D ;D :)
I had thought about it but I had thought but I had discarded the idea.

4
General / Draw two different sprites
« on: April 18, 2020, 07:52:09 pm »
Hello everyone, I'm trying to make a small program in which a red rectangle (player) can walk on blocks of dirt (terrain) and when I try to put the player's sprite in the window.draw it gives me Gravity Code Description no instance overload function "sf :: RenderWindow :: draw" corresponding to the list of arguments.

There's the code:
#include <SFML/Graphics.hpp>
#include <iostream>



using namespace sf;
using namespace std;




int main()
{
        RenderWindow window(VideoMode(640, 480), "Title");
        Texture t;
        t.loadFromFile("images/Terrain.png");
        Sprite s(t);
        Texture p;
        p.loadFromFile("images/player.png");
        Sprite g(p);
       
        s.setTextureRect(IntRect(0, 0, 64, 64));
        s.setPosition(Vector2f(20, 60));
        s.setTexture(t);

        cout << s.getPosition().x << endl;
        cout << s.getPosition().y << endl;

        while (window.isOpen())
        {
                Event e;
                while (window.pollEvent(e))
                {
                        if (e.type == Event::Closed)
                                window.close();

                        if (e.KeyPressed && e.key.code == Keyboard::Escape)
                                window.close();
                }
                window.clear();
                window.draw(s,g);
       
                window.display();
        }


        return 0;
}
 

(sorry for the bad english)
(sorry for the bothering)

5
General / Re: expected an expression
« on: April 16, 2020, 01:05:15 pm »
Thanks! ;D :D :)

6
General / Re: expected an expression
« on: April 15, 2020, 09:18:47 pm »
Thanks a lot, but when i try to compile it opens a white window gives me an error :
Line 1501
Expression: vector subscript out of range


(sorry for the disturbance, but I'm new on this forum and on SFML in general, and sorry for the bad English)

7
General / Re: expected an expression
« on: April 15, 2020, 06:33:26 pm »
The error is changed, it gives me Error E0018 expected ')',and I don't understand why, since I put the parenthesis on it, I don't know this library and I'm in trouble.
There's the line of code:
drawQuad(app, road,p.x,p.y,p.z p.X, p.Y, ,p.W);

I'm programming with visual studio 2019

8
General / expected an expression
« on: April 15, 2020, 03:07:43 pm »
When i try to run this code it gives me an error:

expected an expression

(sorry for the bad english)

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



using namespace sf;

int width = 1024;
int height = 768;
int roadW = 2000;
int segL = 200; //segment lenght
float camD = 0.84;//camera depth

struct Line
{
        float x, y, z; //pokemon reference & 3d center of line
        float X, Y, W; //screen coord
        float scale;

        Line() { x = y = z = 0; }

        //from world to screen coordinates
        void project(int camX, int camY, int camZ)
        {
                scale = camD / (z - camZ);
                X = (1 + scale * (x - camX)) * width / 2;
                Y = (1 - scale * (y - camY)) * height / 2;
                W = scale * roadW * width / 2;
        }
};

void drawQuad(RenderWindow& w, Color c, int x1, int y1, int w1, int x2, int y2, int w2)
{
        ConvexShape shape(4);
        shape.setFillColor(c);
        shape.setPoint(0, Vector2f(x1-w1,y1));
        shape.setPoint(1, Vector2f(x2-w2,y2));
        shape.setPoint(2, Vector2f(x2+w2,y2));
        shape.setPoint(3, Vector2f(x1+w1,y1));
        w.draw(shape);


}

int main()
{

        RenderWindow app(VideoMode(width, height), "Outrun Racing!");
        app.setFramerateLimit(60);

        std::vector<Line> lines;

        for (int i = 0; i < 1600; i++)
        {
                Line line;
                line.z = i * segL;

                lines.push_back(line);
        }

        int N = lines.size();

        while (app.isOpen())
        {
                Event e;
                while (app.pollEvent(e))
                {
                        if (e.type == Event::Closed)
                                app.close();   
                }
                app.clear();
               
                for (int n = 0; n < 300; n++)
                {
                        Line &l = lines[n % N];
                        l.project(0, 1500, 0);

                        Color grass = (n / 3) % 2 ? Color(16, 200, 16) : Color(0, 154, 0);
                        Color rumble = (n / 3) % 2 ? Color(225, 225, 225) : Color(0, 0, 0);
                        Color road = (n / 3) % 2 ? Color(107,107, 107) : Color(105, 105, 105);

                        Line p = lines[(n-1)%N];
                        drawQuad(app, grass, 0, p.Y, width, 0, l.Y, width);
                        drawQuad(app, rumble, p.X, p.Y, p.W * 1.2, l.X, l.Y, l.W * 1.2);
                        drawQuad(app, road, p.X, p.Y, ,p.x,p.z,p.W*1.2);
                }

                app.display();
        }
        return 0;
}

Pages: [1]
anything