Polygon Sprite and AutoPolygon
Check performance between normal sprite and polygon sprite (area to draw vs. function call count)
auto pinfo= AutoPolygon::generatePolygon("filename.png");
auto spp= Sprite::create(pinfo);
Touch event handling
#include "ui/CocosGUI.h"

auto loadingBar= LoadingBar::create("LoadingBarFile.png");
// set the direction of the loading bars progress


// something happened, change the percentage of the loading bar

// more things happened, change the percentage again
#include "ui/CocosGUI.h"

auto textField= TextField::create("", "Arial", 30);

textField->addTouchEventListener([&](Ref* sender, Widget::TouchEventType type) {
  std::cout << "editing a TextField" << std::endl;

// make this TextField password enabled

// set the maximum number of characters the user can enter for this TextField

// create ParallaxNode
auto paraNode= ParallaxNode::create();

// background image is moved at a ratio of 0.4x, 0.5y
paraNode->addChild(background, -1, Vec2(0.4f, 0.5f), Vec2::ZERO);

// tiles are moved at a ratio of 2.2x, 1.0y
paraNode->addChild(middle_layer, 1, Vec2(2.2f, 1.0f), Vec2(0, -200));

// top image is moved at a ratio of 3.0x, 2.5y
paraNode->addChild(top_layer, 2, Vec2(3.0f, 2.5f), Vec2(200, 800));
5 types of event listeners
  1. EventListenerTouch - responds to touch events
  2. EventListenerKeyboard - responds to keyboard events
  3. EventListenerAcceleration - responds to accelerometer events
  4. EventListenerMouse - responds to mouse events
  5. EventListenerCustom - responds to custom events
  • A node of a lower value of FixedPriority receives events before nodes with higher values
  • SceneGraphPriority is a pointer to a Node. Event listeners with higher z-order values receives events before event listeners have lower z-order values.
Touch Events
// Create a "one by one" touch event listener
// (processes one touch at a time)
auto listener1= EventListenerTouchOneByOne::create();

// When "swallow touches" is true, then returning 'true' from the
// onTouchBegan method will "swallow" the touch event, preventing
// other listeners from using it

// trigger when you push down
listener1->onTouchBegan= [](Touch* touch, Event* event) {
  // your code
  return true; // if you are consuming it

// trigger when moving touch
listener1->onTouchMoved= [](Touch* touch, Event* event) {
  // your code

// trigger when you let up
listener1->onTouchEnded= [=](Touch* touch, Event* event) {
  // your code

// Add listener
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener1, this);
2015/12/07 10:29 2015/12/07 10:29

Trackback Address >> 이 글에는 트랙백을 보낼 수 없습니다

댓글을 달아 주세요