Game Play genie

Source: Internet
Author: User
Tags addchild

Create a Cocos2d-X project, as shown in the directory of the project:


Add a PNG image to the resourcees folder.

Add the following code to the bool helloworld: Init () function in the helloworldscene. cpp file:

// Call the initialization function of the cclayer parent class if (! Cclayer: Init () {return false;} // create the genie ccsprite * sprite = ccsprite: Create ("blocks.png"); ccsprite * sprite1 = ccsprite :: create ("blocks.png");/* set the first parameter in the Wizard to the time when the action passes, and the second parameter to the direction of the hop, the third parameter is the jump height. The fourth parameter is the number of hops. The CCP (0, 0) indicates */sprite-> runaction (ccjumpby: Create (60, CCP (0, 0), 100,100); // Add the genie to the scene. This-> addchild (sprite); // Add the scene to the layer addchild (sprite1 );

Program Execution result: (enable the sprite to beat up or down)



Add the following code below to the code above to set the location of the genie.

sprite->setPosition(CCPoint(100, 200)); sprite1->setPosition(CCPoint(300, 200));


Execution result:


Add the following code to the bool helloworld: Init () function in the helloworldscene. cpp file to implement proportional configuration.

// Call the initialization function of the cclayer parent class if (! Cclayer: Init () {return false;} // create the genie ccsprite * sprite = ccsprite: Create ("blocks.png"); ccsprite * sprite1 = ccsprite :: create ("blocks.png"); // Add the genie to the scene this-> addchild (sprite); // Add the scene to the layer addchild (sprite1 ); // set sprite-> setposition (ccpoint (100,200); sprite1-> setposition (ccpoint (300,200); // set the sprite-> setscale (. 5f); sprite-> setscalex (. 5f); sprite-> setscale (2); Return true;

Execution result:



Add the following code to the bool helloworld: Init () function in the helloworldscene. cpp file to implement sprite rotation.

// Call the initialization function of the cclayer parent class if (! Cclayer: Init () {return false;} // create the genie ccsprite * sprite = ccsprite: Create ("blocks.png"); ccsprite * sprite1 = ccsprite :: create ("blocks.png"); // Add the genie to the scene this-> addchild (sprite); // Add the scene to the layer addchild (sprite1 ); // set sprite-> setposition (ccpoint (100,200); sprite1-> setposition (ccpoint (300,200); // setrotation rotation, angle in units, positive is clockwise, negative is counterclockwise sprite-> setrotation (-80); sprite-> setrotationy (180); Return true;


Execution result:


Add the following code to the bool helloworld: Init () function in the helloworldscene. cpp file to implement the sprite distortion, which is similar to the sprite's rotation on a plane.

// Call the initialization function of the cclayer parent class if (! Cclayer: Init () {return false;} // create the genie ccsprite * sprite = ccsprite: Create ("blocks.png"); ccsprite * sprite1 = ccsprite :: create ("blocks.png"); // Add the genie to the scene this-> addchild (sprite); // Add the scene to the layer addchild (sprite1 ); // set the sprite position sprite-> setposition (ccpoint (100,200); sprite1-> setposition (ccpoint (300,200); // setskewx is distorted, and the single vector is almost rotated, however, Sprite-> setskewx (180); sprite1-> setrotationx (180); Return true;


Execution result:


Add the following code to the bool helloworld: Init () function in the helloworldscene. cpp file to implement the sprite distortion, which is similar to the sprite's rotation on a plane.

// Call the initialization function of the cclayer parent class if (! Cclayer: Init () {return false;} // create the genie ccsprite * sprite = ccsprite: Create ("blocks.png"); ccsprite * sprite1 = ccsprite :: create ("blocks.png"); // Add the genie to the scene this-> addchild (sprite); // Add the scene to the layer addchild (sprite1 ); // set sprite-> setposition (ccpoint (100,200); sprite1-> setposition (ccpoint (300,200); // setflipx reverse, with setrotationy (180) same effect sprite-> setflipx (true); Return true;

Execution result:


Add the following code to the bool helloworld: Init () function in the helloworldscene. cpp file to set the opacity of the genie.
// Call the initialization function of the cclayer parent class if (! Cclayer: Init () {return false;} // create the genie ccsprite * sprite = ccsprite: Create ("blocks.png"); ccsprite * sprite1 = ccsprite :: create ("blocks.png"); // Add the genie to the scene this-> addchild (sprite); // Add the scene to the layer addchild (sprite1 ); // set sprite-> setposition (ccpoint (100,200); sprite1-> setposition (ccpoint (300,200); // setopacity transparency 0 ~ 255 (value range), 255 opaque, 0 fully transparent sprite-> setopacity (128); Return true;

Execution result


Add the following code to the bool helloworld: Init () function in the helloworldscene. cpp file to implement the hidden genie.
// Call the initialization function of the cclayer parent class if (! Cclayer: Init () {return false;} // create the genie ccsprite * sprite = ccsprite: Create ("blocks.png"); ccsprite * sprite1 = ccsprite :: create ("blocks.png"); // Add the genie to the scene this-> addchild (sprite); // Add the scene to the layer addchild (sprite1 ); // set sprite-> setposition (ccpoint (100,200); sprite1-> setposition (ccpoint (300,200 )); // setvisible whether sprite-> setvisible (false); Return true;

Execution result: Too Many Rows exist.

Game Play genie

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.