@cold dune
#help XD
53 messages · Page 1 of 1 (latest)
I have a problem with my c++ code, I'm sorry if my english is bad, I am french.
So
My code is the start of a plateformer game.
And the problem of all of my code is that, my character is not loading in the good place and doesn't even move... Even with tests like cout<<1<<endl; at the beginning of the main function, nothing apear on the cmd.
Here are the files:
Haven't used SFML for ages, but does move() actually take a delta or is it absolute position ?
like , player.move(200,200) will move the sprite to 200,200 instantly
Yes, I've tried it, but doesn't work
The problem, is that the problem is unspotable
Like
Even the beginning of the main doesnt work
Everything is loading
But Idk
I've putted a cout<<1<<ebdl; at the begging of the main and doesnt work
Are you using an IDE where you can easily put in a breakpoint and you could inspect the variables ?
Wdym? I'm kinda new in c++
Like, a code editor where you can set a point in code where it should stop running and show you information about variables and such
Oh yeah
you should be able to do alot with just cout << "1" stuff too, just more tedious 😉
I'm in visual studio
okay, you should be able to click on the left side where you have your line numbers, it should get marked with a red filled circle.. if you run your program in debug mode it will stop at that line and you can point at the variables with your mouse to see more information
what I'm getting at is that, with a breakpoint you could verify that your deltaX and Y are actually set
I don't think the problem is located here
I founded some errors on an other panel
I give you
Gravity Code Description Project File Line Deletion Status
Error C2440 'initialization': cannot convert from 'initializer list' to 'int' Platformer H:\C++\Platformer\Platformer\menu.cpp 9
Error C2011 'joueur': redefinition of a type 'struct' Platformer H:\C++\Platformer\Platformer\menu.h 23
Error C2079 'perso' uses an undefined struct 'joueur' Platformer H:\C++\Platformer\Platformer\menu.cpp 9
Error C2664 'void Collisions::gererCollisionsJoueur(sf::Sprite &, sf::Image &, joueur &, float &)': cannot convert argument 3 from 'int' to 'joueur &' Platformer H:\C++\Platformer\Platformer\menu.cpp 84
Error C2374 'WIN_HEIGHT': redefinition; multiple initialization Platformer H:\C++\Platformer\Platformer\menu.h 13
Error C2374 'WIN_WIDTH': redefinition; multiple initialization Platformer H:\C++\Platformer\Platformer\menu.h 14
whoa, that looks like it doesn't compile at all
T_T
those errors about "redefinition" is usually because you have used #include in a way that something gets defined twice or more
Imma try to find the error
not sure if it is going to help, but I noticed your menu.h does not have header guards, like #ifndef MENU_H and #define MENU_H, finally a #endif
Thank you, I've done this and now I only have 2 errors
What are those errors? 🙂
I'm translating them
Error C2660 'Collisions::gererCollisionsJoueur': function does not take 4 arguments: This error occurs on line 85 of "menu.cpp". It means that you are calling the 'gererCollisionsJoueur' function with 4 arguments, but the function is defined to take a different number of arguments. Check the function signature of 'gererCollisionsJoueur' in the "collisions.h" file and make sure you are calling the function with the correct number of arguments.
Error C2061 syntax error: identifier 'Sprite': This error occurs on line 11 of "collisions.h". It indicates that there is incorrect usage of the identifier 'Sprite' in that file. Make sure you have included the necessary SFML library to use the 'Sprite' class correctly. Check if you have included the line #include <SFML/Graphics.hpp> in "collisions.h" to have access to the 'Sprite' class.
okay, first one seems to be a missmatch on number of arguments you are passing to the function, double check you got them right
second one might be fixed with the hint they give you to #include the proper file, unless you already did that then it is something odd
paste in the line 11 from collisions.h to this chat
#ifndef COLLISIONS_H
#define COLLISIONS_H
#include "menu.h"
#include <iostream>
#include <SFML/Graphics.hpp>
using namespace sf;
class Collisions
{
public:
static void gererCollisionsJoueur(Sprite& sprite, Image& image_masque, joueur& player, float& gravite);
};
#endif // COLLISIONS_H
The 11 line is the {
oh yeah, cpp is rather bad at giving you exact line number for some reason
yea, I see the function declaration, to me that looks just fine. If you hover your mouse on the Sprite& .. does it show you information about it? Like, it should show something about where that was declared etc.
There's nothing when I hover my mouse
what if you prefix it with sf:: ?
like static void gererCollisionsJoueur(sf::Sprite& sprite...
Gravity Code Description Project File Line Deletion Status
Error C2660 'Collisions::gererCollisionsJoueur': function does not take 4 arguments Platformer H:\C++\Plateformer\Plateformer\menu.cpp 85
Error C2061 syntax error: identifier 'joueur' Platformer H:\C++\Plateformer\Plateformer\collisions.h 13
sf:: in this case means you want to use Sprite from the namespace "sf"
the second error there sell you that it doesn't know what "joueur" is, you have to #include its declaration from some file, and from code you posted earlier it was declared in "menu.h", I would put this into a separate file and include that instead, for example joueur.h
Also noticed that you have circular #include statements, menu.h includes collision.h, but collision.h also includes menu.h ... basically they are including each other for ever 😉