+ 3
C++ SFML
Trying to sort out a game engine/state machine using enum class. Can't seem to figure it out, I've looked all over the internet btw.
14 Antworten
+ 5
are you facing linker's problem?!
if yes so tell me about your environment and ide ....
leme know it first..
+ 3
I understand how enum works, I'm just lost at how to work the different levels/menu stuff into it. I know I can create headers and cpp files but I just can't order it or figure how to link it to work
+ 3
No, I understand the enum itself
But where would I declare my game states and how would I link that to my enum class header
For example atm I have a menu, a main game and a win page as functions. This is messy and doesn't work if I try to loop back to main. How can I make these into a game engine linked to enum
+ 3
Yes except for me wanting to loop win screen to menu
+ 3
It runs fine in main, but I can't make win screen go to menu screen because of the order of the functions. In a state machine/game engine you should be able to create whatever whenever but I don't know how to create and link it in to the enum class
+ 3
I can't because win has to be above main and main has to be above menu
+ 2
When I said main I meant main game func.
I currently have all 3 states in separate functions. I want to create a state machine/game engine with enum controlling which screen I'm on, game/menu/win ect.
I'm using SFML in Visual Studio 2019
+ 1
Iâm not sure about what youâre trying to do here.
letâs take an example of
enum go {east, south, west, north}
to create a state machine, just create a vector of go
vector<go> dir = {east, east, west, north};
//prints 0 0 2 3
is that what youâre looking for?
+ 1
Again, not sure what youâre asking about
declare enum in header.h
include header.h in main.cpp
access enum from main
does this answer your question?
+ 1
before you split the functions and classes into multiple header files, does it work with single main.cpp?
+ 1
I never made a game myself, so I have very little idea of what youâre talking about
but if it doesnât work in a single main.cpp, then why do you think splitting them will make it work
I think there might be something wrong with your game logic
+ 1
if you have a function that shows menu screen, letâs call it menu()
what happens when you call menu() after win screen appears
forget about enum class for a second
+ 1
can you move menu to the top of main?
if not, why?
all functions should be declared before main()
this is the root of your problem, not linking multiple files
+ 1
I have created a system of headers and c++ files that individually work. Except...I cant seem to find a way to switch between the states. I declared my enum in engine which includes header files to Game, Menu,Win. I have separate cpp files for input,draw,update that includes engine. Where and how could I conditionally switch states? Ideally I'd like game to switch to win when score=5 and win to switch to menu when button pressed. But where can I write this that would be able to access those variables.