Cocos2d-x 3.6 mac Trial (particle, touch event, picture)

Source: Internet
Author: User
Tags addchild lua

Play says

Although the company how, we programmers in the case of extracurricular learning is also to do their job well.

The work of Lua also write more, in-depth understanding of cocos2d-x of course, or to Daoteng Daoteng C + +, for a C # for so many years, working with Lua's side dishes, C + + is really not used.

Cocos2d-x unknowingly updated to the 3.6 version, is really million people Spit groove, 2d has not done clearly and began to make 3d, touch the gods can not concentrate on a good thing, how many pits did not fill, but also a variety of renamed, each update to learn the same as the new library ... Orz .... The groove is finished or you have to work hard.

Romance

3.6 introduced the concept of frame architecture (do not say that there is no learning unity, the store is really a copy of the Red Fruit), to first good cocos, and then download a variety of things from the store, but to tell the truth for the Super lazy blogger is very convenient, the MAC is almost a right mouse button to complete, No more running around looking for resources. After installation it is long like this drop.

Try the next codeide, not too accustomed to, or use Xcode compare habits, for the Eclipse Department editor long-term no love ah. But considering the situation of multi-platform development, recommend everyone still try CodeIDE, this aspect is still good (wait for the Microsoft Editor, haha ha).

Don't say much nonsense, cut into the code section.

Myth

1. File creation

The new project in Cocos is a lot more humane than the command line of the year, and you can open the project in Cocosstudio after it is established.

You can then publish it to Xcode in Cocosstuido.

Very convenient to have wood there!! Let's play the game together!

After the release will be opened directly xcode,resources/res is the Cocos2d-x default storage folder, classes stored in the code, published can be run directly, AppDelegate.cpp content I will not be the cliché!! Do not understand the friend please Baidu, or point recommend me! I tutor one-on-one!! Hey.

Use of 2.Scene

cocos2d in the director,Scene, each layer of the relationship, a picture + a sentence to understand: there is only one director, he can change scene, the remaining Layer all return to scene. (Not even more confused-=)

Change scene is the director of a word of things.

Auto scene = Player::createscene ();D irector::getinstance ()->replacescene (scene);
3.ImageView and touch have to say things

The following code creates a picture of a chick (don't ask me where the picture came from ...) Hundreds of original wood has ... ), click the chicken, the chicken began to run, the amount, barely understood as the run ...

The touch event was managed by _eventdispatcher , which looks like it came out of the 3.0, and I was drifting through the Addtouchlistener in Lua anyway.

Ontouchbegin can be used to set callbacks in Cc_callback way, or directly Labmda anonymous functions with simple or direct processing.

#include "Player.h" scene* player::createscene () {Auto Scene = Scene::create ();    Auto layer = Player::create ();        Scene->addchild (layer); return scene;} BOOL Player::init () {if (!    Layer::init ()) {return false;    }//Get the current screen size of size visiblesize = Director::getinstance ()->getvisiblesize ();        Get visual screen origin coordinates Vec2 origin = Director::getinstance ()->getvisibleorigin ();    Create a background layer background = imageview::create ();    Background->loadtexture ("Background.png");    Background->setposition (Vect (ORIGIN.X+VISIBLESIZE.WIDTH/2,ORIGIN.Y+VISIBLESIZE.HEIGHT/2));    This->addchild (background);    Create chick imageview* chicken = imageview::create ();    Background->addchild (chicken);    Chicken->setposition (VEC2 (500,500));    Chicken->setname ("chicken");    Chickenrun ();    Create listener Auto MyListener = Eventlistenertouchonebyone::create ();    MyListener->setswallowtouches (TRUE); Mylistener->ontouchbegan = Cc_callback_2 (player::oNtouchbegan,this);        Binding monitoring _eventdispatcher->addeventlistenerwithscenegraphpriority (MyListener, chicken); return true;} Chicken Run void Player::chickenrun () {imageview* chicken = static_cast<imageview*> (Background->getchildbyname ("    Chicken "));    if (chickenstate = = 1) {chicken->loadtexture ("left.png");    } else {chicken->loadtexture ("right.png");    }}//Touch Start event bool Player::ontouchbegan (touch* Touch, event* event) {event->getcurrenttarget ();        Auto target = static_cast<sprite*> (Event->getcurrenttarget ());    Gets the position of the current touch point in relation to the button Locationinnode = Target->converttonodespace (Touch->getlocation ());    Size s = target->getcontentsize ();         Rect rect = rect (0, 0, s.width, s.height);        Detect the Click Area if (Rect.containspoint (Locationinnode)) {chickenstate = Chickenstate * (-1);        Chickenrun ();    return true; } return false;}
4. About the things that particles have to say

Many games used to the particle system, cocos2d have some of the particles, but the effect is relatively single, fade out with code to write particles hard to see the effect, in the Mac has Particledesigner, you can visually write particles, and then export plist files, Cocos2d can be called directly in the code.

Use the following code to import particles into cocos2d, which is quick and easy:

Create particle void Player::createfire () {    Particlesystemquad *particle = particlesystemquad::create ("particle/ Fire.plist ");    Background->addchild (particle);    Particle->setposition (VEC2 (600,500));    Particle->settag (11);}
5. Effect display

Source file is a bit large to provide download, things are relatively simple, but also a flawed ah, found that mistakes must tell me ah, is a big night, in order to live a few years, or early to sleep it.

Blog Address: http://www.cnblogs.com/nightcat/
Blog Copyright: This article to learn, research and share-based, welcome to reprint, but must be in the article page obvious location to the original connection.
If the text is inappropriate or wrong place also look at the point of master, lest fraught. If you feel that this article is helpful please "recommend" a bit! If you have better suggestions, may wish to leave a message to discuss together, progress together! Thank you again for your patience in reading this post.

Cocos2d-x 3.6 mac Trial (particle, touch event, picture)

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.