cocos2d Lua getting smaller sample memory game

Source: Internet
Author: User


1. Game Introduction

A "Memory" category of game games. You play against the computer, whose turn, who turns two cards, assuming the same two cards. On the elimination of these two cards, 2 points, can continue to flop, assuming that the two cards are not the same, change a person. Until the end. To see who scored high.

The game design thought can see this article "Cocos2d Game state Machine"


2. Lua Simple Object-oriented

We know that Lua is a scripting language, not a real object-oriented language. But object-oriented seems to make the code structure more reasonable. Javascript, Lua is capable of simulating object-oriented. Lua is object-oriented and is implemented in many ways, and this is certainly not the case.

Simply take a look at the writing of the inherited sprite. Copy the official.

Matchcard = Class ("Match", Function (spriteframename, value)    Matchcard.value = value//--Property    return CC. Sprite:createwithspriteframename ("Matchcardbg.png") end) matchcard.test= true//--Property//--a method function Matchcard: Containstouchlocation (x, y) Local position = CC.P (self:getposition ()) Local s = self:getcontentsize ()    Local Touchrect = Cc.rect (-s.width/2 + position.x,-S.HEIGHT/2 + POSITION.Y, S.width, s.height)    local B = Cc.rectcontain Spoint (TOUCHRECT,CC.P (x, y))    return bend//--new An object, of course, this is not the same as the C + + local card = matchcard.new ()//--Call method card: Containstouchlocation ()

3.Cocos Code Ide Creating LUA Project

My game was created with the Cocos Code Ide. It's smooth. API Reference lua-tests can be.

The whole is the same. Haven't played quick cocos2d-x yet.


4.cocos2d LUA Usage Experience

C + + Programming with Cocos2d-x feels most comfortable, although C + + syntax is hard to write. But not easy to encounter a very strange bug. Is the compilation speed is too slow, with planning bad cooperation. Like JS, and Lua, you define some kind of writing. Planning directly can also write JS and lua,c++ will not be. and Cocos2d-x C + + can use the latest version number, porting Android and iOS is no problem.

and Cocos2d-x C + + feel able to write high-quality code. And VS2012 is very useful.


Lua,js are scripting languages that are used to develop games at a much faster speed.

No need to compile. is accustomed to C + + that kind of object-oriented, write Lua,js object-oriented always strange. Debug is sometimes difficult compared to C + +. Cocos2d JS or write with Webstorm is more cool. The Cocos Code Ide has gaps with VS2012 and webstorm, and some aspects are easier to use because they are integrated Cocos game frames.


5. Dynamic diagram and project source code download


I use less of LUA, I feel worse for writing, too many global variables. Project:

http://www.waitingfy.com/?

attachment_id=1291

EXE can be directly executed in/runtime/win32/matchgame.exe, not supported xp,win7 should be able.

http://www.waitingfy.com/archives/1289


Copyright notice: This article blog original articles, blogs, without consent, may not be reproduced.

cocos2d Lua getting smaller sample memory game

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.