I've learned that magic numbers are bad in code. However, should the coordinates, and rotation angles of all the sprites be stored in variables? Is the convention in game development to leave those hard-coded values as arguments to set the coordinates or the angles of the transformable?
// Create a texture to hold a graphic on the GPU
Texture textureBackground;
// Load a graphic into the texture
textureBackground.loadFromFile("graphics/background.png");
// Create a sprite
Sprite spriteBackground;
// Attach the texture to the sprite
spriteBackground.setTexture(textureBackground);
// Set the spriteBackground to cover the screen
spriteBackground.setPosition(0, 0);
// Create a tree sprite
Texture textureTree;
textureTree.loadFromFile("graphics/tree.png");
Sprite spriteTree;
spriteTree.setTexture(textureTree);
spriteTree.setPosition(810, 0);
// Prepare the bee
Texture textureBee;
textureBee.loadFromFile("graphics/bee.png");
Sprite spriteBee;
spriteBee.setTexture(textureBee);
spriteBee.setPosition(0, 800);
800
(rather than800
and810
). Then those appear to be the same value, when that might be only coincidential. This makes it more difficult to consistently change the value later. Imho here this is much less a problem (unless810
should actually be800 + 10
or something like that), because you use the values once and i supposeSprite
has a properly named accessor for the value. Anyhow, this is purely opinion based \$\endgroup\$static constexpr vec2d FixedBeePosition {0,800};
where vec2d is struct with an x and y value. Your set position will then be :spriteBee.setPosition(FixedBeePosition.x, FixedBeePosition.y)
(or allow SetPosition to accept a vec2d directly). And you have removed "magic constants" from your code. \$\endgroup\$class Object
, and maybe, aclass Actor: public Object
to bundle all the stuff for one object / actor which belongs together...) \$\endgroup\$