Hello everyone, I've recently started learning C++ game programming with a book called:
"Beginning C++ game programming", which uses SFML. I've followed the book's instructions and am currently in page 229, in the ZombieArena project.
For some reason, the code that they give in the book doesn't work. First, in page 221, they instruct to create a ZombieArena.h file which includes only these lines:
#pragma once
using namespace sf;
int createBackground(VertexArray& rVA, IntRect arena);
Then for the next few pages they instruct how to code the createBackground function in a 'CreateBackground.cpp' file.
After that, in page 227, they instruct to return to the main file, the ZombieArena.cpp file, and make use of the createBackground function, with these few lines, first at the top of the file:
// Create the backgroundVertexArray background;
// Load the texture for our background vertex array
Texture textureBackground;
textureBackground.loadFromFile("graphics/background_sheet.png");
And then inside the game loop:
// Pass the vertex array by reference
// to the createBackground function
int tileSize = createBackground(background, arena);
and:
// Draw the background
window.draw(background, &textureBackground);
However, I'm received several errors:
First, they declare a Texture called textureBackground but try to use one called background, I've fixed this by changing background to textureBackground.
Then, in the header file, visual studio doesn't recognize VertexArray, I've fixed it by adding an #include statement for SFML/graphics.
Then, it seems that they suggest sending a Texture into the createBackground object, even though it accepts only a VertexArray reference. I've looked online a bit and following the example from here:
https://www.sfml-dev.org/tutorials/2.5/graphics-vertex-array.phpFound that I can eliminate the errors by adding these lines of code:
VertexArray vertices;
RenderStates states;
states.texture = &textureBackground;
After declaring the textureBackground Texture, and then calling createBackground like so:
int tileSize = createBackground(vertices, arena);
and window.draw like so:
window.draw(vertices, states);
However, after running the game, I still don't see any background, only the player. I can't figure out how to fix this issue, and the book doesn't help at all with it, nor can I find any useful information on the internet. Any help will be appreciated, thanks in advance!