Sprite not showing up!

When I upgraded to Cocos2dx V3.7 and when I ran this very trivial code:

#ifndef MAINGAME_HPP
#define MAINGAME_HPP

#include "cocos2d.h"
#include "ui/CocosGUI.h"

class MainGame : public cocos2d::Scene
{
	public:

		MainGame();
		virtual ~MainGame();

		static cocos2d::Scene * createScene();

		virtual bool init();

		CREATE_FUNC(MainGame);

	private:

		cocos2d::ui::TextField * mNameField;
		cocos2d::Sprite * mSprite;
};

#endif

and this is the implementation file:

#include "MainGame.hpp"

MainGame::MainGame()
{

}

MainGame::~MainGame()
{
}

cocos2d::Scene * MainGame::createScene()
{
	auto scene = MainGame::create();
	return scene;
}

bool MainGame::init()
{
	if(!cocos2d::Scene::init())
		return false;

	cocos2d::Size screenSize = cocos2d::Director::getInstance()->getOpenGLView()->getFrameSize();
	cocos2d::Vec2 centerPos = cocos2d::Vec2(screenSize.width / 2.0f , screenSize.height / 2.0f);

	mSprite = cocos2d::Sprite::createWithSpriteFrameName("pacman.png");
	mSprite->setAnchorPoint(cocos2d::Vec2(0.5f, 0.5f));
	mSprite->setPosition(cocos2d::Vec2(400.0f, 400.0f));
	mSprite->setVisible(true);

	this->addChild(mSprite , 0);

	return true;
}

Sigh, whats going on? I don’t use layer anyway so I could not fathom why the code so simple as this wouldn’t even work. Also, the sprite doesn’t seem to be added on the actual scene. When I turn on engine stats, it indicates it is not drawing any at all.

I also tried my older projects written using v3.2 and I am getting crashes CCNavMesh.cpp.

Maybe I missed something on the patch notes.

Thanks for your help.

I think you should load the corresponding picture before creating a Sprite by Sprite::createWithSpriteFrameName().

@zhangzm That’s what I did. In fact I check the SpriteFrameCache through the debugger if the size > 0 and it is.

I was able to run it by not adding the Node into layer. My usual routine is to create a class inheriting from scene than the traditional class inheriting from a Layer class. What I did is I created a Scene class and compose a Layer class to it. There I add the Node object to the Layer then adding the layer to the scene. When I run it, it crashes for some reason.