当前位置:网站首页>Cocos2d Lua 越来越小样本 内存游戏
Cocos2d Lua 越来越小样本 内存游戏
2022-07-06 10:19:00 【全栈程序员站长】
大家好,又见面了,我是全栈君。
1.游戏简介
一个”记忆”类的比赛游戏。你和电脑对战,轮到谁的回合,谁翻两张牌,假设两张牌一样。就消掉这两张牌,得2分,能够继续翻牌,假设两张牌不一样,就换一个人。直到最后。看谁的得分高。
游戏设计思想能够看这篇文章《Cocos2d 游戏状态机》
2. Lua 简单面向对象
我们知道Lua是脚本语言,不是真正面向对象语言。可是面向对象好像能让代码结构更加合理。Javascript, Lua都能够模拟出面向对象。Lua面向对象还有超多种方式实现,这里当然不一一介绍。
简单来看个继承Sprite的写法。抄官方的。
MatchCard = class("Match",function (spriteFrameName, value)
MatchCard.value = value //--属性
return cc.Sprite:createWithSpriteFrameName("MatchCardBg.png")
end)
MatchCard.test= true //--属性
//--一个方法
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.rectContainsPoint(touchRect,cc.p(x,y))
return b
end
//--new 一个对象,当然这跟c++的那种不一样的
local card = MatchCard.new()
//--调用方法
card:containsTouchLocation()3.Cocos Code Ide 创建Lua项目
我这游戏是用Cocos Code Ide 创建的。还算顺利。API參考Lua-Tests即可了。
总体是一样的。还没玩过Quick cocos2d-x。
4.cocos2d lua 使用感受
使用Cocos2d-x的C++编程感觉是最舒服的,尽管C++语法有写难。但不easy遇到非常奇怪的Bug。就是编译速度太慢了,跟策划不好合作。像Js,和Lua,你定义好一些写法。策划直接也能够写Js和Lua,C++就不行了。还有Cocos2d-x C++ 能用上最新版本号,移植Android和IOS没什么问题。
还有Cocos2d-x C++感觉能写出较高质量的代码。还有VS2012非常好用。
Lua,JS都是脚本语言,用来开发游戏速度快非常多。
不须要编译。就是习惯了C++那种条条框框的面向对象后,写Lua,JS的面向对象总怪怪的。Debug有时候相对C++比較困难。cocos2d JS还是用WebStorm编写比較爽。Cocos Code Ide 跟VS2012和WebStorm还有差距,某些方面由于是集成Cocos的游戏框架,所以某些方面比較好用。
5.动态图以及项目源代码下载
我对Lua使用比較少,感觉写的比較差,太多全局变量。项目下载地址:
exe能够直接执行在/runtime/win32/MatchGame.exe,不支持XP,Win7应该能够。
http://www.waitingfy.com/archives/1289
版权声明:本文博客原创文章,博客,未经同意,不得转载。
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/117397.html原文链接:https://javaforall.cn
边栏推荐
- Pytest learning ----- pytest confitest of interface automation test Py file details
- 递归的方式
- 1700C - Helping the Nature
- 二分(整数二分、实数二分)
- Will openeuler last long
- Selected technical experts from China Mobile, ant, SF, and Xingsheng will show you the guarantee of architecture stability
- Codeforces Round #803 (Div. 2)
- Why does wechat use SQLite to save chat records?
- C语言自动预订飞机票问题
- 李书福为何要亲自挂帅造手机?
猜你喜欢

1700C - Helping the Nature

Today in history: the mother of Google was born; Two Turing Award pioneers born on the same day

Maixll-Dock 摄像头使用

std::true_type和std::false_type

Pourquoi Li shufu a - t - il construit son téléphone portable?
![Jerry is the custom background specified by the currently used dial enable [chapter]](/img/32/6c22033bda8ff1b53993bacef254cd.jpg)
Jerry is the custom background specified by the currently used dial enable [chapter]

Implementation of queue

Appium automated test scroll and drag_ and_ Drop slides according to element position

The third season of Baidu online AI competition is coming in midsummer, looking for you who love AI!

Interview assault 63: how to remove duplication in MySQL?
随机推荐
Stealing others' vulnerability reports and selling them into sidelines, and the vulnerability reward platform gives rise to "insiders"
最新财报发布+天猫618双榜第一,耐克蓄力领跑下个50年
Common - magic number 7
This article discusses the memory layout of objects in the JVM, as well as the principle and application of memory alignment and compression pointer
Getting started with pytest ----- allow generate report
TOP命令详解
UDP协议:因性善而简单,难免碰到“城会玩”
1700C - Helping the Nature
The easycvr platform reports an error "ID cannot be empty" through the interface editing channel. What is the reason?
2019 Alibaba cluster dataset Usage Summary
C语言通过指针交换两个数
【剑指 Offer】 60. n个骰子的点数
【Android】Kotlin代码编写规范化文档
High precision operation
编译原理——自上而下分析与递归下降分析构造(笔记)
Jielizhi obtains the customized background information corresponding to the specified dial [chapter]
队列的实现
模板于泛型编程之declval
CRMEB 商城系统如何助力营销?
[Android] kotlin code writing standardization document