Game Scene Creating Node

How To Make Flappy Bird
  • MoseHas
    Likes 0

    Problem Description

    Apology for my bothering again.

    I was reviewing every source code line by line and make sure that I have fully understanded them. And I found out that I could not really understand this part.

    GameScene.cpp
    
        ....
    
        auto edgeBody = PhysicsBody::createEdgeBox( visibleSize, PHYSICSBODY_MATERIAL_DEFAULT, 3 );
        edgeBody->setCollisionBitmask( OBSTACLE_COLLISION_BITMASK );
        edgeBody->setContactTestBitmask( true );
        
        auto edgeNode = Node::create();
        edgeNode->setPosition( Point( visibleSize.width / 2 + origin.x, visibleSize.height / 2 + origin.y ) );
        
        edgeNode->setPhysicsBody( edgeBody );
        
        this->addChild( edgeNode );
    
        ....

     

    Why we have to create a node? What for?

    I tried to delete the lines with edgeNode and modified this->addChild( edgeNode ) to this->addChild( edgeBody ) , error occured.

    It said physicsBody is not the child of class GameScene. So I guess it is because we have to pass the correct type?

    Would you mind explaining them line by line what they do?

    My appreciation!

  • Sonar Systems admin
    Likes 0

    To put it simply, think of the edgeBody as a human skeleton and the edgeNode as the flesh/skin, we see the skin not the skeleton (most of the time) but we can see its affects because people can move their limbs etc. The principle is the same, the edgeBody is the underlying system, in this case a physics object that other physics objects can interact with.


    This reply has been verified.
  • MoseHas
    Likes 0

    Wow, this is a little bit complicated.

    Let me try to explain it again.

    A car can move due to its engine. But we do not directly USE engine, instead, we manipulate the wheel and the throttle to make it move. 

    So we have a engine(skeleton) that we cannot see but it does the most part of job, and we need a wheel and throttle(flesh/skin) to directly use it.

    Is that right?


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

    Yh, nice example :D


    This reply has been verified.
  • MoseHas
    Likes 0

    A little bit abstract but I am getting clear. Thanks!


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

    :D       


    This reply has been verified.

Login to reply