Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Scene* KZ::createScene()
- {
- _scene = Scene::createWithPhysics();
- #if DEBUG
- _scene->getPhysicsWorld()->setDebugDrawMask(PhysicsWorld::DEBUGDRAW_ALL);
- #endif
- Size visibleSize = Director::getInstance()->getVisibleSize();
- Vec2 origin = Director::getInstance()->getVisibleOrigin();
- // Build the score label.
- string txt = "Score: " + to_string(Ratio);
- scoreLabel = Label::create(txt.c_str() , "fonts\\arial.ttf", 11.2f);
- scoreLabel->setPosition(Vec2(origin.x + scoreLabel->getContentSize().width,
- origin.y + visibleSize.height - scoreLabel->getContentSize().height));
- // Mouse events.
- auto mmove = EventListenerMouse::create();
- mmove->onMouseMove = CC_CALLBACK_1(KZ::onMouseMove, this);
- mmove->onMouseDown = CC_CALLBACK_1(KZ::onMouseDown, this);
- // Physics contacts.
- auto cphysics = EventListenerPhysicsContact::create();
- cphysics->onContactBegin = CC_CALLBACK_1(KZ::onContactBegin, this);
- // Our weapon.
- weapon = Sprite::create("weapon.png");
- weapon->setPosition(origin.x + weapon->getContentSize().width,
- origin.y + weapon->getContentSize().height);
- // Build the image and then animate it.
- enemy = Sprite::create("kz.png");
- auto enemyPhysics = PhysicsBody::createBox(enemy->getContentSize());
- enemyPhysics->setDynamic(false);
- enemyPhysics->setContactTestBitmask(0xFFFFFFFF);
- enemy->setPhysicsBody(enemyPhysics);
- enemy->setPosition(origin.x,
- origin.y + visibleSize.height - enemy->getContentSize().height / 2);
- auto moveby = MoveBy::create(3, Vec2(visibleSize.width - origin.x, 0));
- auto moveby_back = moveby->reverse();
- auto seq = Sequence::create(moveby, moveby_back, nullptr);
- // Update event listeners.
- _scene->getEventDispatcher()->addEventListenerWithSceneGraphPriority(mmove, _scene);
- _scene->getEventDispatcher()->addEventListenerWithSceneGraphPriority(cphysics, _scene);
- // Fetch everything inside the scene.
- _scene->addChild(scoreLabel);
- _scene->addChild(enemy);
- _scene->addChild(weapon);
- enemy->runAction(RepeatForever::create(seq));
- return _scene;
- }
Advertisement
Add Comment
Please, Sign In to add comment