Development with Cocos Code Ide: lua inheritance, cocoslua

Source: Internet
Author: User

Development with Cocos Code Ide: lua inheritance, cocoslua

When I write an edge error, I modify the edge and change the search. Then I made some changes. There may be errors, forgive me, and accept criticism.

 1 ---Base.lua 2  3 Base = {}                               4  5 Base.__index = Base 6 Base.value = nil 7  8 function Base:new(_value) 9     local _t = {}10     setmetatable(_t, Base)11     _t.value = _value12     return _t13 end
 1 ---Children.lua 2 require("Base") 3 Children = {} 4  5 setmetatable(Children, Base) 6 Children.__index = Children 7 Children.type = nil 8  9 function Childeren:new(_value,_type)10     local _c = Base:new(_value)11     setmetatable(_c, Children)12     _c.type = _type13     return _c14 end

Base. lua is a Base class, and Children. lua is a subclass that inherits Base. lua. You may get used to C ++.

 1 --- .h 2  3 class Base 4 { 5      public: 6           void setValue(_value) 7           int value;                       8 } 9 10 --- .cpp11 Base::setValue(_value)12 {13      value = _value;14 }15 16 main()17 {18     Base* b = new Base();19     cout << b.value << endl;20 }

Here, B is the same as the above _ t. I think it is the same and it is an object. _ t is of the table type,

_ T. value is like B. value.

Setdistribuable (Children, Base): sets the metadatabase of Childeren to Base,

Setretriable (_ c, Children): Set the _ c meta table to Children,

For example:

_ C: son Children: Father Base: Grandpa

The son wants to buy a toy. If: 1. He has money, buy it directly and get the toy.

2. If you have no money, search for your father's trouser pockets. If you have money, you will get the money and buy toys.

3. I have no money. I search for my father's trouser pockets. If I have no money, I search for my grandfather's trouser pockets. If I have money, I get money, I buy toys. If I have no money, I can only search for nil.

The same is true for class methods.

 


How Cocos Studio differs from Cocos2d-js and Cocos Code IDE

Cocos studio is used to set animations and images.
Cocos2d-js is eager to js language cocos2d framework, mainly used for web development.
Cocos code ide is a cocos2d Development Environment officially developed by cocos. It was developed using eclipse, vs, and other development environments before it was released.
 
Different Cocos2d-x, Quick-Cocos2d-x, Cocos Studio, Cocos2d-js, Cocos Code IDE

Cocos2d-x is a cross-platform framework, with C ++, including windows, ios, android, linux and so on can be transplanted.
Quick-Cocos2d-x is to add some features in the Cocos2d-x, I have never used, I only used Cocos2d-x.
Cocos2d-js is the JS language, mainly used for the development of Web games.
Cocos Studio is mainly used to design game interfaces and animations.
Cocos Code IDE is a programming development environment officially released by cocos. If you do not need the official version, you can use eclipse, vs, and other ides for development after configuration.

The 2.x version of The Cocos2d-x is quite different from the 3.x version. The Code on both sides is not compatible and requires some small modifications to run.

Pure hand beat...

Related Article

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.