Classes/Sprite3D/Sprite3DLesson2.cpp
// on "init" you need to initialize your instance
on "init" you need to initialize your instance
on " init " you need to initialize your instance
bool Sprite3DLesson2::init()
{
    if ( !Layer::init() )
    {
        return false;
    }
    Size visibleSize = Director::getInstance()->getVisibleSize();
    Vec2 origin = Director::getInstance()->getVisibleOrigin();
    auto closeItem = MenuItemImage::create(
                                           "CloseNormal.png",
                                           "CloseSelected.png",
                                           CC_CALLBACK_1(Sprite3DLesson2::menuCloseCallback, this));
	closeItem->setPosition(Vec2(origin.x + visibleSize.width - closeItem->getContentSize().width/2 ,
                                origin.y + closeItem->getContentSize().height/2));
    auto menu = Menu::create(closeItem, NULL);
    menu->setPosition(Vec2::ZERO);
    this->addChild(menu, 1);
    auto sprite = Sprite::create("HelloWorld.png");
    sprite->setPosition(Vec2(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y));
    sprite->setScale(0.3f);
    this->addChild(sprite, 0);
    sprite->setGlobalZOrder(0);
    auto sprite3d = Sprite3D::create("res/Sprite3D/boss.obj");
    sprite3d->setTexture("res/Sprite3D/boss.png");
    sprite3d->setPosition(Vec2(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y));
    addChild(sprite3d);
    sprite3d->setScale(10);
    auto action = RotateBy::create(3, 360);
    auto action_back = action->reverse();
    auto seq = Sequence::create( action, action_back, nullptr );
    sprite3d->runAction( RepeatForever::create(seq) );
    return true;
}
bool Sprite3DLesson2 :: init ( ) { if ( ! Layer :: init ( ) ) { return false ; } Size visibleSize = Director :: getInstance ( ) -> getVisibleSize ( ) ; Vec2 origin = Director :: getInstance ( ) -> getVisibleOrigin ( ) ; auto closeItem = MenuItemImage :: create ( " " , " " , CC_CALLBACK_1 ( Sprite3DLesson2 :: menuCloseCallback , this ) ) ; closeItem -> setPosition ( Vec2 ( origin . x + visibleSize . width - closeItem -> getContentSize ( ) . width / 2 , origin . y + closeItem -> getContentSize ( ) . height / 2 ) ) ; auto menu = Menu :: create ( closeItem , NULL ) ; menu -> setPosition ( Vec2 :: ZERO ) ; this -> addChild ( menu , 1 ) ; auto sprite = Sprite :: create ( " " ) ; sprite -> setPosition ( Vec2 ( visibleSize . width / 2 + origin . x , visibleSize . height / 2 + origin . y ) ) ; sprite -> setScale ( 0.3f ) ; this -> addChild ( sprite , 0 ) ; sprite -> setGlobalZOrder ( 0 ) ; auto sprite3d = Sprite3D :: create ( " " ) ; sprite3d -> setTexture ( " " ) ; sprite3d -> setPosition ( Vec2 ( visibleSize . width / 2 + origin . x , visibleSize . height / 2 + origin . y ) ) ; addChild ( sprite3d ) ; sprite3d -> setScale ( 10 ) ; auto action = RotateBy :: create ( 3 , 360 ) ; auto action_back = action -> reverse ( ) ; auto seq = Sequence :: create ( action , action_back , nullptr ) ; sprite3d -> runAction ( RepeatForever :: create ( seq ) ) ; return true ; }
on "init" you need to initialize your instance
on " init " you need to initialize your instance
////////////////////////////// // 1. super init first ///////////////////////////// // 2. add a menu item with "X" image, which is clicked to quit the program //    you may modify it. // add a "close" icon to exit the progress. it's an autorelease object // create menu, it's an autorelease object ///////////////////////////// // 3. add your codes below... // add a label shows "Hello World" // create and initialize a label // add "Sprite3DLesson2" splash screen" // position the sprite on the center of the screen //    // add the sprite as a child to this layer //create Sprite3D