Cocos2d-x tilmap black screen - c++

I am a beginner with cocos2d-x and try to use it with Tiled to create maps.
I created a TileMap, and here is my code, in LevelOne::init() in level_one.cpp :
if (!CCLayer::init())
{
return false;
}
_tileMap = new CCTMXTiledMap();
_tileMap->initWithTMXFile("levelone.tmx");
this->addChild(_tileMap);
return true;
The debugger allows me to see that the variable _tileMap contains well (at least a part) of the information in my levelone.tmx file.
But when i run it, got a black screen.
Here is the project on github : https://github.com/LeopoldBriand-bot/Platformer
what would I have misunderstood?
Thanks.

I figure it out: Tiles folder should be on th same disk than .tmx file to have relative path and both should be in Ressource folder.

Related

Opencv C++ Opens Two Window for Each imshow

I am using OpenCV 3.3.0 for c++ in visual studio. The problem is that when I use this code, it opens two windows with the same name that one of them contains the image and the another one is extra and empty. (Screenshot from the two windows )
cv::Mat im0 = cv::imread("C:\\Users\\MY_PC\\Desktop\\Image.bmp"); //read the image
cv::resize(im0, I, cv::Size(640, 480), 0, 0, CV_INTER_LINEAR); //Resize the image to 640x480
cv::namedWindow("HI");
cv::imshow("HI", I);
cv::waitKey(0);
The more important problem following this problem, is that the waitkey() function just works with the extra window and I should press the keys on that window to see the changes in the another window.
Furthermore the setMouseCallback has the same problem and mouse commands doesn't work on the window containing the image. Thanks a lot.
I have the same problem with the project type "Win32 Console Application".
If you use a "Empty Project" the problem disappears.
Try commenting out the line cv::namedWindow("HI");, does it work?
Unfortunately I can't help with other two.
I don't see any mistakes in the code you shared.
However, I'm usually writing like that:
const char* display_name = "Display";//Display name
namedWindow(display_name, WINDOW_AUTOSIZE);//Create Display
imshow(display_name, frame);//Display Image
waitKey(0);//Wait a key to be pressed
For x64: Removed opencv_world410.lib and just add opencv_world410d.lib from Additional Dependencies
(Common properties->Linker->Inputs->Additional Dependencies)
This link helps you to create config files for all of your projects:
https://docs.opencv.org/4.1.0/dd/d6e/tutorial_windows_visual_studio_opencv.html

DevIL reading an invalid extension

So I've been using the DevIL library for a while now (along with ILU and ILUT) and have had few problems with it after I got it working. That is, until now. All of a sudden it does not seem to work with any image of any format. I'm using this code:
GLuint myTex;
void Init() {
myTex = ilutGLLoadImage(L"img.tga");
}
void Draw() { // 2D Drawing
glBindTexture(GL_TEXTURE_2D, myTex);
draw::TwoD::Textured::Rectangle(100, 100, 200, 200);
}
The rectangle appears blank white. I checked the function and it seems like it should work fine, so I tried calling ilGetError(). It returned IL_INVALID_EXTENSION for nearly every different image I tried. I've tried putting the whole directory and even made sure that I was using the right version of DevIL (unicode) and still it returns this. Any idea what's going on?
Thanks in advance!
Edit:
I've also notices that DevIL returns this even if the file specified does not exist. This makes me think something is wrong with DevIL itself instead of my code.
Edit 2:
So I found out that I placed the unicode DLLs in the project directory (as necessary) but it turns out I linked to the library directories for multi-byte chars. Even after fixing it, the problem continued. I'm stumped by this one.
Edit 3:
Okay sorry for so many edits but I also just found out that the DevIL setup I had in my previous projects still work perfectly. It seems to only be the project I'm using now. All the relevant code is the same (copy/pasted), so I think it has to do with the project properties, but I can't find any differences. Do you know of any way to copy the properties of one project to another in VS2015?

cocos2d-x 3.0 - Create sprite by relative path

How can I create a sprite with relative path? I mean I have several folder in Resources directory such as:
sd
hd
....
One of this directories is set as the place where resources should be looked up :
std::vector<std::string> resDirOrders;
if (device is hd)
resDirOrders.push_back("hd")
FileUtils::getInstance()->setSearchResolutionsOrder(resDirOrders);
Now in each of above mentioned directories I have lots of other directories such as:
intro_popup
outro_popup
main_menu
top_bar
ingame
....
In these directories I place the images. And the names of images can collide, as far as I can have coin.png in main_menu, in top_bar in ingame which are different images. Theretofore, I want to be able to create a sprite like this:
Sprite::create("ingame/coin.png");
Sprite::create("top_bar/coin.png");
But it does not work. It just does not find the file coin.png.
How I should solve this issue? I am on Windows with cocos2d-x 3.0, but it should be handled on iOS and Android too.
The folder structure must be like this :
Res/
----hd/
----sd/
----ingame/
----hd/
----sd/
----top_bar/
----hd/
----sd/
You should add the Res folder to the project, and make sure that "Create folder references for any added folders" is checked.
Set the search path and search resolution order:
Size screenSize = Director::getInstance()->getOpenGLView()->getFrameSize();
std::vector<std::string> resDirOrders;
std::vector<std::string> searchPaths = FileUtils::getInstance()->getSearchPaths();
searchPaths.insert(searchPaths.begin(), "Res");
FileUtils::getInstance()->setSearchPaths(searchPaths);
if (screenSize.width > 1024) {
resDirOrders.push_back("hd");
}
else{
resDirOrders.push_back("sd");
}
FileUtils::getInstance()->setSearchResolutionsOrder(resDirOrders);
Then you can create the sprite with Sprite::create("ingame/coin.png");

Setting icons in Unity3d standalone player

I am trying to use Unity, with a build script that creates my application by ultimately invoking BuildPipeline from the script. I am trying to figure out how to set up the icons, however. After calling PlayerSettings.SetIconsForTargetGroup and invoking BuildPipline.BuildPlayer, the appropriate icon does not show up for the executable file produced, nor display when the program is running.
I am currently using the following code.
Texture2D texture = AssetDatabase.LoadMainAssetAtPath(iconFile) as Texture2D;
int [] sizeList = PlayerSettings.GetIconSizesForTargetGroup(BuildTargetGroup.Standalone);
Texture2D[] iconList = new Texture2D[sizeList.Length];
for(int i=0;i<sizeList.Length;i++)
{
int iconSize = sizeList[i];
iconList[i] = (Texture2D)Instantiate(texture);
iconList[i].Resize(iconSize,iconSize,TextureFormat.ARGB32,false);
}
PlayerSettings.SetIconsForTargetGroup(BuildTargetGroup.Standalone,iconList);
What am I doing wrong?
Any assistance would be greatly appreciated. Thank you
Using BuildTargetGroup.Unknown works for me.
This also worked for me:
BuildTargetGroup.Unknown
But with an unwanted outcome: Unity does not override all icon sizes when setting one single Texture2D PNG, so Windows Explorer swaps the icon of my application EXE between the Unity default icon and my icon for different resolutions. Definitely, seems like a bug in Unity3D BuildPipeline.BuildPlayer(..) or SetIconsForTargetGroup(..).
If you're calling BuildPipline.BuildPlayer for OSX, then you need to specify full folder:
/MyPath/MyApp.app
i.e. don't leave out the ".app" part, because without that Unity builds the app, but doesn't include icons or splash image in resolution dialog.

In C++, using Code::Blocks, can't open a file, although it exists and the path should be correct

I am using Code::Blocks and the SDL library to create a simple computer game.
I have been following some tutorials, and have created a functional game of tic tac toe.
While the project didn't have any specific instructions, I created a template that could be used with other games.
Using that template, I created a new project, where I'd have an image of Yoshi running.
However, in this new project, when I use a function that requires to open a file, it never works. For example:
if ( (Surf_Anim = CSurface::OnLoad("yoshi.bmp")) == NULL)
return false;
always returns false, even though the yoshi.bmp exists, and the OnLoad function is exactely the same as in the Tic Tac Toe project.
I have placed copies of the yoshi.bmp image next to the executable, and it still doesn't work. (In the functional TicTacToe project, the images were on the same directory as the project)
What am I doing wrong?
EDIT: After confirming that manipulation of text files worked properly, I edited the CSurface::OnLoad function, like this:
SDL_Surface* CSurface::OnLoad(char* File)
{
SDL_Surface* Surf_Temp = NULL;
SDL_Surface* Surf_Return = NULL;
if((Surf_Temp = SDL_LoadBMP(File)) == NULL)
{
return NULL;
}
printf ("Loafing worked\n");
Surf_Return = SDL_DisplayFormat (Surf_Temp);
SDL_FreeSurface(Surf_Temp);
if (Surf_Return == NULL)
printf ("SDL_DisplayFormat didn't\n");
return Surf_Return;
}
Both printf functions were executed. I suppose this problem has to do with the way I used SDL functions. Anyway, everything was done in the same way in a perfectly working project. The image yoshi.bmp, is, like the ones on the said working project, a bit map with 24 bit colours...
The DisplayFormat function couldn't work because the pixel format and colors of the video framebuffer had not been previously set using the function SDL_SetVideoMode.
Calling this function before trying to load the image, solved the problem.