Pop Star - listeners of clicking on the bricks

  • MoseHas
    Likes 0

    Problem Description

    Hi there. I have more questions about fetures I am going to implement.

    1. Could I change the entire screen to vertical display instead of horizontal?

              

    1. onclicklistener

              I will have two listeners, single-click and double-click on the brick. They do different things. How could I implement them using listener?

     

    1. physicsworld settings

              Bricks are effected with gravity. Therefore, when the lower one is eliminated, all bricks above it will drop. I assume I should set a collision detection like FlappyBird. When the bird hit the floor it would not drop out of the screen. But Still have no idea how to.

     

    Thanks!

  • Sonar Systems admin
    Likes 0

    1: You can change the design resolution, what language are you using?

    2: Check this out http://discuss.cocos2d-x.org/t/cclayer-with-gestures-tap-double-tap-swipe-supported-ios-android-should-also-work/5823

    3: For the ground have a physics body that is static and do the same for the bricks


    This reply has been verified.
  • MoseHas
    Likes 0

    My language is cpp, designing by Microsoft visual studio, platform windows 7. And I expect I will run it on Android or iOS device.

    So the horizontal display is the default? Because I have never set its resolusion.

     

    Secondly, I appreciate that you found a already-written class for me. I will try it. Thank you very much.

    I feel I had difficulty using listeners. For example, in Flappy Bird project, we did call onTouchBegan:

    	auto touchListener = EventListenerTouchOneByOne::create();
    	touchListener->setSwallowTouches(true);
    	touchListener->onTouchBegan = CC_CALLBACK_2(GameScene::onTouchBegan, this);
    	Director::getInstance()->getEventDispatcher()->addEventListenerWithSceneGraphPriority(touchListener, this);
    1. We declared touchListener for the single click.
    2. set it to be swallowable for touches.
    3. This is the part I do not understand. Why onTouchBegan is touchListener’s member function? Didn’t we declare it in GameScene.cpp? And what does CC_CALLBACK_N do?
    4. Calling a bunch of things really confuses me. 

    Could you explain it for me? Thousand thanks!

     

    Not only I need the bricks stack on the ground but also I need to stack a brick on another. In FlappyBird project, the bird just ran into the pipe and overlapped it before GameOverScene was replaced. Therefore, I assume I need to prevent objects overlapping each other.

     

    Thanks.

     

     


  • MoseHas
    Likes 0

    I just imitated what you did in FlappyBird and I successfully remove a brick by its tag.

    Now I am still looking for a way that listener could know where I click and eliminate the brick which I have clicked.

    Had no clue :\

  • MoseHas
    Likes 0

    I figured out a really stupid way to find out the tag of the brick.

    I use getLocation() to find out where I click, and set 10+10 if statements for both x and y axis.

    I set the tag from 0 to 99 depending on its createing order. The bottomleft one is the first brick, so it has the coordinate (0,0), and its tag is 0*10+0=0.

    Same as the topright one (9*10+9=99). And I could use the if statements to judge my click is located at which interval.

    void HelloWorld::elimite(const float x, const float y)
    {
    	Size visibleSize = Director::getInstance()->getVisibleSize();
    	Vec2 origin = Director::getInstance()->getVisibleOrigin();
    	int xPos=-1, yPos=-1;
    	if (x > visibleSize.width / 2 + origin.x - 5 * BRICK_SIZE && x < visibleSize.width / 2 + origin.x - 4 * BRICK_SIZE) xPos = 0;
    	else if (x > visibleSize.width / 2 + origin.x - 4 * BRICK_SIZE && x < visibleSize.width / 2 + origin.x - 3 * BRICK_SIZE) xPos = 1;
    	else if (x > visibleSize.width / 2 + origin.x - 3 * BRICK_SIZE && x < visibleSize.width / 2 + origin.x - 2 * BRICK_SIZE) xPos = 2;
    	else if (x > visibleSize.width / 2 + origin.x - 2 * BRICK_SIZE && x < visibleSize.width / 2 + origin.x - 1 * BRICK_SIZE) xPos = 3;
    	else if (x > visibleSize.width / 2 + origin.x - 1 * BRICK_SIZE && x < visibleSize.width / 2 + origin.x - 0 * BRICK_SIZE) xPos = 4;
    	else if (x > visibleSize.width / 2 + origin.x - 0 * BRICK_SIZE && x < visibleSize.width / 2 + origin.x + 1 * BRICK_SIZE) xPos = 5;
    	else if (x > visibleSize.width / 2 + origin.x + 1 * BRICK_SIZE && x < visibleSize.width / 2 + origin.x + 2 * BRICK_SIZE) xPos = 6;
    	else if (x > visibleSize.width / 2 + origin.x + 2 * BRICK_SIZE && x < visibleSize.width / 2 + origin.x + 3 * BRICK_SIZE) xPos = 7;
    	else if (x > visibleSize.width / 2 + origin.x + 3 * BRICK_SIZE && x < visibleSize.width / 2 + origin.x + 4 * BRICK_SIZE) xPos = 8;
    	else if (x > visibleSize.width / 2 + origin.x + 4 * BRICK_SIZE && x < visibleSize.width / 2 + origin.x + 5 * BRICK_SIZE) xPos = 9;
    
    	if (y > BRICK_SIZE * 0 + origin.y + 100 && y < BRICK_SIZE * 1 + origin.y + 100) yPos = 0;
    	else if (y > BRICK_SIZE * 1 + origin.y + 100 && y < BRICK_SIZE * 2 + origin.y + 100) yPos = 1;
    	else if (y > BRICK_SIZE * 2 + origin.y + 100 && y < BRICK_SIZE * 3 + origin.y + 100) yPos = 2;
    	else if (y > BRICK_SIZE * 3 + origin.y + 100 && y < BRICK_SIZE * 4 + origin.y + 100) yPos = 3;
    	else if (y > BRICK_SIZE * 4 + origin.y + 100 && y < BRICK_SIZE * 5 + origin.y + 100) yPos = 4;
    	else if (y > BRICK_SIZE * 5 + origin.y + 100 && y < BRICK_SIZE * 6 + origin.y + 100) yPos = 5;
    	else if (y > BRICK_SIZE * 6 + origin.y + 100 && y < BRICK_SIZE * 7 + origin.y + 100) yPos = 6;
    	else if (y > BRICK_SIZE * 7 + origin.y + 100 && y < BRICK_SIZE * 8 + origin.y + 100) yPos = 7;
    	else if (y > BRICK_SIZE * 8 + origin.y + 100 && y < BRICK_SIZE * 9 + origin.y + 100) yPos = 8;
    	else if (y > BRICK_SIZE * 9 + origin.y + 100 && y < BRICK_SIZE * 10 + origin.y + 100) yPos = 9;
    	if (xPos >= 0 && yPos >= 0) this->removeChildByTag (yPos * 10 + xPos);
    }

     

    Well, problem solved, but it is not a clever way. Looking for a better solution.


  • Sonar Systems admin
    Likes 0

    COOL,

     

    Here is one of our videos covering touch for more info http://www.sonarlearning.co.uk/coursepage.php?topic=game&course=cocos2d-x-v3&videoindex=352#352

     


    This reply has been verified.
  • MoseHas
    Likes 0

    Yeah I have seen it. Thanks a lot! It helps.

    May I ask what  getEventDispatcher() is doing? I assume Director::getInstance() is just like doing things it calls, and getEventDispatcher() is what it does.

    Is that correct?

    A little bit complicated.

     

    By the way, I do not know how to use physics engine to create stackable bricks.


  • Sonar Systems admin
    Likes 0

    Hello

     

    Check this out for more info http://www.cocos2d-x.org/wiki/EventDispatcher_Mechanism


    This reply has been verified.
  • MoseHas
    Likes 0

    Thank you. I am studying it.

  • Sonar Systems admin
    Likes 0

    :D         


    This reply has been verified.
  • MoseHas
    Likes 0

    Answering my own question.

    I just found how to change the resolution of the window.

    In AppDelegate.cpp, 

    	if(!glview) 
    	{
    		glview = GLViewImpl::create("POPSTAR");
    		director->setOpenGLView(glview);
    	}

    Add after this part.

    	glview->setDesignResolutionSize(480,800,ResolutionPolicy::SHOW_ALL);

     

    This is for the gaming area resolution. Only change the resolution here will remain black background at sides.

    Therefore, we need:

    	glview->setFrameSize(480, 800);

    After we set the framesize, it will perfectly fit the window. No more black sides! Congradulations!

     

     


    This reply has been verified.
  • Sonar Systems admin
    Likes 0

    Well done, good to hear you have solved it :D


    This reply has been verified.

Login to reply