How would I use "#define" in my .h file?

I’m doing a lot of coding and many names I gave things in my .plist file are quite hard to remember, so in my .h file, I said

#define groundSquare01 "groundSquare_01_001-uhd.png"

So in my code, I added

#include "Definitions.h"

Next, I changed

auto g = Sprite::create("groundSquare_01_001-uhd.png");


auto g = Sprite::create(groundSquare01);

But Xcode gave me an error.
However, it didn’t mention what the error WAS.

So, what is wrong here?
I’m using V4.

1 Like

Or use a spritesheet?

1 Like

Also, to answer your question:

what does and doesn’t go in a header file

and can you post the .h?

1 Like

#ifndef Definitions_h
#define Definitions_h

#define groundSquare01 “groundSquare_01_001-uhd.png”


1 Like

I’m just asking because I have images that have really hard names to remember that have to be used multiple times and the spritesheet is huge

This isn’t related to Cocos products specifically. I think you can answer this question with a google search. Preprocessor directives - C++ Tutorials

Just use the name of the #define where it is needed.

auto mySprite = cocos2d::Sprite::create(groundSquare01);

the spec states that #defines should be in all caps though :slight_smile:

Just a random thought, make sure these double quotes in the

#define groundSquare01 “groundSquare_01_001-uhd.png”

are ok.