当前位置:网站首页>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
边栏推荐
- 8位MCU跑RTOS有没有意义?
- Fleet tutorial 13 basic introduction to listview's most commonly used scroll controls (tutorial includes source code)
- 趣-关于undefined的问题
- J'aimerais dire quelques mots de plus sur ce problème de communication...
- The latest financial report release + tmall 618 double top, Nike energy leads the next 50 years
- 李书福为何要亲自挂帅造手机?
- 【.NET CORE】 请求长度过长报错解决方案
- 30 minutes to understand PCA principal component analysis
- 【剑指 Offer】 60. n个骰子的点数
- Five data structures of redis
猜你喜欢

Take you through ancient Rome, the meta universe bus is coming # Invisible Cities

The easycvr platform reports an error "ID cannot be empty" through the interface editing channel. What is the reason?

模板于泛型编程之declval

I want to say more about this communication failure

微信为什么使用 SQLite 保存聊天记录?

Top command details

小程序在产业互联网中的作用

1700C - Helping the Nature

面向程序员的精品开源字体

F200——搭载基于模型设计的国产开源飞控系统无人机
随机推荐
I want to say more about this communication failure
Why should Li Shufu personally take charge of building mobile phones?
【Android】Kotlin代码编写规范化文档
Virtual machine VirtualBox and vagrant installation
TOP命令详解
Comparative examples of C language pointers *p++, * (p++), * ++p, * (++p), (*p) + +, +(*p)
High precision operation
78 year old professor Huake has been chasing dreams for 40 years, and the domestic database reaches dreams to sprint for IPO
Jerry's access to additional information on the dial [article]
node の SQLite
STM32+HC05串口蓝牙设计简易的蓝牙音箱
On time and parameter selection of asemi rectifier bridge db207
C语言高校实验室预约登记系统
Compilation principle - top-down analysis and recursive descent analysis construction (notes)
Today in history: the mother of Google was born; Two Turing Award pioneers born on the same day
Excellent open source fonts for programmers
MS-TCT:Inria&SBU提出用于动作检测的多尺度时间Transformer,效果SOTA!已开源!(CVPR2022)...
Codeforces Round #803 (Div. 2)
win10系统下插入U盘有声音提示却不显示盘符
Rb157-asemi rectifier bridge RB157