Skip to content

doom20082004/cocos2dx-classical

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

这是什么

这是一个私人定制的cocos2dx版本, 基于cocos2dx v2分支的最新代码, 目标是创造一个cocos2dx的古典经典版. cocos2dx目前已经全面发力于3.x版本, 2.x版本已经被抛弃, 当然, 如果他们不抛弃2.x, 我也不会创建这个项目.

我觉得2.x仍然还有价值, 同时3.x并不让我感到多大兴趣. 实际上cocos2d作为一个2d引擎, 还有很多不完善的地方, 相信无数的人已经在2.x时代踩过了很多的坑, 也不得不自己去填上这些坑, 我也一样, 为了填这些坑, 我创建了cocos2dx-better项目, 把这些坑通过外挂的方式填掉, 但是总有一些坑, 外挂解决不了, 只能改原始代码. 对于我个人而言, 目前更需要一个好用的2.x, 而不是一个有未知新坑的3.x.

另外, 我日常使用mac, 主要做iOS和Android开发, 所以其它的平台我都会删掉.

所以, 如果你正好也是一个Mac/iOS/Android开发者, 也正好还在使用cocos2dx 2.x, 不妨可以看几眼.

What is this

It is a customized cocos2dx, based on latest code of cocos2dx v2 branch. The purpose of it is creating a classical cocos2dx version. I created it because cocos2dx already gave up v2 but v2 is still valuable to me. v3 doesn't interest me much because it may have more bugs. So I need a better v2, not a creepy v3.

To get a bette v2, I created a cocos2dx-better project to overcome limitations of v2. Now I start this project to merge cocos2dx-better code to v2 branch, and more.

I only care about iOS/Android platform so other platform implementation will be deleted. Are you same with me? If so, take a look at this project.

目标

  1. 基于cocos2dx 2.x最新代码 (已完成)
  2. 将我个人的cocos2dx-better代码融入 (已完成)
  3. 把quick-cocos2dx那一套lua支持拷贝过来改吧改吧 (已完成)
  4. 专注于填坑改bug, 而非大刀阔斧的修改架构 (随时进行中)

Purpose

  1. based on cocos2dx v2 (Done)
  2. merge my cocos2dx-better (Done)
  3. provide full lua support, in quick-cocos2dx 3.x style (Done)
  4. fix v2 bugs (Always in progress)

何时结束

等有一天我也开始使用3.x的时候, 这个项目就结束了, 即使到了那一天, 我也希望这个项目留下了一个好用的2.x. 就像名字希望的一样, 这会成为cocos2dx的古典经典版.

Everything that has a beginning has an end

At the day when I switch to v3, this project will be stopped. But, I hope its corpse is still valuable to somebody because it is better than v2 corpse.

这些年, 已经填过的坑

  • 修正工程的64位编译设置
  • 使用c++11编译所有代码
  • 重新实现CCLabelTTF(来自cocos2dx-better的CCRichLabelTTF):
    • 完全兼容CCLabelTTF的原有功能
    • 支持字符串中嵌入格式控制, 包括颜色, 字体, 大小, 样式, 图片, 链接等
  • CocoStudio的调整
    • 去掉了CocoStudio类的UI前缀兼容设置, 去掉了一些文件的UI前缀
    • 修正对CocoStudio Mac 1.0.0.0 beta的支持问题, 具体修改为:
      • Label构造函数中_fontSize缺省改为20, 因为mac版cocostudio默认字体大小为20, 当为20时, 不会序列化到json中
      • 对类名称"Node"的节点, 一律创建Layout
      • WidgetPropertiesReader0300::createWidget中, 检查文件版本, 如果为1.0.0.0, 认为其为mac版
      • WidgetPropertiesReader0300::widgetFromJsonDictionary中添加page item的代码注释掉, 因为PageView重新实现后采用动态方式创建page item
      • Layout的缺省背景色类型改成NONE
      • PageView重新实现:
        • 支持动态创建页, 解决了page比较多时的性能问题
        • 使用了cocos2dx-better的VelocityTracker跟踪滑动速度, 解决了页间滑动很别扭的问题
        • 注: 不再支持从CocoStudio中直接添加page item, 必须使用PageViewDataSource接口
    • 修正LabelBMFont::setFntFile方法中的内存泄露
    • ListView的pushBackDefaultItem返回新item
    • 修正CCArmature有时候帧事件触发两次的问题
    • 修正CCArmature单帧动画不触发完成事件的问题
    • 由于CocoStudio Mac 1.0.0.0 beta没有骨骼动画功能, 需要使用骨骼动画时, 可以使用CocoStudio Windows版1.4.0.1, 1.4.0.1以上版本我没有测试过.
    • Widget添加addScriptTouchEventListener以支持在lua处理Widget的触摸事件
    • CCArmatureAnimation添加hasFrameEvent用于检测是否存在某个帧事件
  • 重新实现TMX地图, 支持一个层有多张贴图的情况(来自cocos2dx-better的CBTMXTileMap)
  • 重新实现CCTableView(来自cocos2dx-better中的CCGridView代码):
    • CCTableView支持多列
    • 支持cell重用, cell可以设置名称
    • 支持不等宽度的行或列
    • 支持设置行间距, 列间距, 边界间距
  • CCProtocols.h增加CCMeasurableProtocol, 让LoadingBar, CCProgressTimer实现CCMeasurableProtocol. 从而让CCProgressTo, CCProgressFromTo支持UILoadingBar
  • CCLabelBMFont添加了setLineKerning, 用于调整行间距
  • CCScrollView添加方法可以设置min/max scale
  • 重新实现CCLayerMultiplex以避免某些情况下发生的内存泄露
  • CCLayer增加is/setSwallowTouch, 从而可以控制CCScrollView是否吞掉touch
  • CCSpriteBatchNode的insertQuadFromSprite, updateQuadFromSprite, addSpriteWithoutQuad改为public
  • CCScrollView增加getTouchPoint方法获得最后一次点击位置
  • 修正CCScrollView的isNodeVisible方法
  • CCRepeatForever覆盖stop方法, 停掉内部动作
  • copy()返回的对象不再需要release
  • setShaderProgram可以设置参数, 从而支持多个节点使用同一个shader但参数不同
  • CCNode添加了nodeToAncestorTransform, ancestorToNodeTransform, convertToParentSpace, convertToParentSpaceAR方法
  • 设计了一个资源打包工具, lpk_ui是它的图形界面, lpk_console是命令行工具, 不过这个工具我只是调试完成, 尚未在实际项目中验证, 而且引擎也需要修改来支持这个工具, 所以目前仅供参考
  • Lua相关修改
    • quick 3.x的binding generator工具移植完成, 名叫autolua, 引擎的lua绑定已经全部生成
    • lua和luajit的库都已经预编译, 缺省使用luajit库, 如果想切换成lua, 可以编辑scripting/lua/Android.mk(for anroid)或cocos2dx/proj.ios/cocos2dx.xcodeproj(for ios)
    • HelloLua工程修改调试通过
    • 使用ccScriptFunction代表一个脚本方法, 替代了原来使用int的方式. 引擎中注册脚本方法相关的代码都改成使用ccScriptFunction, 相应的牵涉到CCLuaEngine, CCLuaStack等都有不少修改, 脚本回调方法可以获得self参数, 解决了脚本回调方法中获取self不方便的问题
    • 逐渐完善一些公用库, 都放在scripting/lua/script下, 提供一些基本的封装
    • 加入了lfs方便载入脚本, 修正了Cocos2dxLuaLoader和lfs冲突的问题
    • 加入了位操作库
    • 修正了一些tolua_fix的bug
    • 添加了tolua.isa方法
    • script端的CCNotification监听方法现在可以收到额外参数
    • 修改了extern.lua, 添加了dtor方法, 会在C++对象析构时调用
    • CCDirector/CCEGLView的end方法改名为terminate, 避免和lua的关键字冲突
    • CCNode添加了set/getScriptUserData, 支持在lua端为CCNode关联一个lua table
    • string包增加了split, tonumber, toint, tobool, empty方法
    • table包增加了print, hasnumber, hasstring, fill, fillnew方法
    • debug包增加了addtrace, removetrace方法
    • tools下有xcode_lua_support工具, 可以为Xcode添加lua语法高亮
    • 添加CCApplicationLua, 封装通用的初始化逻辑, 因此AppDelegate可以不再需要

cocos2dx-better新加的其它功能我就不列举了, 目前cocos2dx-better的代码已经合并完成, 有一部分代码我感觉写的用处不大就没有合并了, 不过只是一小部分, 95%的cocos2dx-better代码已经合并.

Things Improved

  • fixed project 64bits compiling
  • reimplement CCLabelTTF (merge code from cocos2dx-better CCRichLabelTTF)
    • fully compatibile with old CCLabelTTF
    • support attibuted style, such as color, font, size, style, image, link
  • polish CocoStudio
    • remove UI prefix
    • fix json parsing bug for CocoStudio Mac 1.0.0.0 beta, how to do:
      • set Label default _fontSize to 20 because CocoStudio Mac use 20 by default
      • create Layout for node whose name is "Node"
      • check version in WidgetPropertiesReader0300::createWidget to detect CocoStudio Mac json
      • because PageView is reimplemented, comment out page item code in WidgetPropertiesReader0300::widgetFromJsonDictionary
      • set Layout default background color style to NONE
      • reimplement PageView
        • use data source to create page item dynamically, and reuseable
        • use VelocityTracker (from cocos2dx-better) to improve page slide experience
        • Note: don't support add page item in CocoStudio
    • fix memory leak in LabelBMFont::setFntFile
    • return created item in Listview::pushBackDefaultItem
    • fix bug: CCArmature frame event may be triggered more than once
    • fix bug: CCArmature single frame animation doesn't trigger complete event
    • Note: if you want to use skeleton animation, please still use CocoStudio Windows version, 1.4.0.1 is recommended.
    • Widget adds addScriptTouchEventListener to support process widget touch event in lua side
    • CCArmatureAnimation adds hasFrameEvent to detect existence of a frame event
  • reimplement TMX, support multi-tileset for one layer(merge from cocos2dx-better CBTMXTileMap)*
  • reimplement CCTableView(merge from cocos2dx-better CCGridView):
    • support multi-column
    • support cell reuse, cell can set name
    • column or row can be different size
    • support to set row spacing, col spacing and border spacing
  • add CCMeasurableProtocol class to abstract LoadingBar and CCProgressTimer, so that CProgressTo, CCProgressFromTo can be used on LoadingBar
  • CCLabelBMFont adds setLineKerning to adjust line spacing
  • CCScrollView add methods to set min/max scale
  • reimplement CCLayerMultiplex to avoid memory leak
  • CCLayer adds is/setSwallowTouch to control swallowing touch or not
  • CCSpriteBatchNode insertQuadFromSprite, updateQuadFromSprite, addSpriteWithoutQuad are changed to public
  • CCScrollView adds getTouchPoint to get last touch position
  • fix CCScrollView isNodeVisible method
  • CCRepeatForever override stop method
  • setShaderProgram can specify uniform values so that one shader can be shared by many nodes
  • CCNode adds nodeToAncestorTransform, ancestorToNodeTransform, convertToParentSpace, convertToParentSpaceAR
  • add a tool for resource pack, lpk_ui is UI tool, lpk_console is command tool. However, it is not tested in a real project. It is only for your reference by so far.
  • Lua related
    • quick 3.x binding generator is migrated, renamed as autolua
    • engine lua binding is generated
    • lua and luajit are both precompiled, by default we use luajit. if you want to use lua, you can modify scripting/lua/Android.mk(for android) or cocos2dx/proj.ios/cocos2dx.xcodeproj(for ios)
    • HelloLua project is debugged and fine
    • use ccScriptFunction struct to replace int handler, modified all related code
    • make it easy to pass self parameter to script callback
    • adding more shared library, in scripting/lua/script
    • add lfs to easily load lua files under a folder, fix conflict between Cocos2dxLuaLoader and lfs
    • add bit operation library
    • fix some bugs of tolua_fix
    • add tolua.isa method
    • CCNotification script observer can get extra parameters now
    • lua class add a dtor method to receive CCObject destruction event
    • rename CCDirector/CCEGLView end method to terminate, to avoid name conflict with lua keyword
    • add set/getScriptUserData for CCNode so that we can associate a lua table to CCNode
    • string package adds split, tonumber, toint, tobool, empty methods
    • table package adds print, hasnumber, hasstring, fill, fillnew methods
    • debug package adds addtrace, removetrace method
    • xcode_lua_support tool, can add lua syntax highlight for Xcode
    • add CCApplicationLua to encapsulate basic logic of lua app, so that AppDelegate can be eliminated

How to use CCImagePicker

There is a CCImagePicker merged from cocos2dx-better, it can take image from camera or album and return it in any size. It is very handy, but you need more setup before using it. In iOS, just use it. In Android, don't forget to config something:

  • register activities in AndroidManifest.xml, below is an example, you can change some attribute if you like, such as screenOrientation.
<activity
    android:name="org.cocos2dx.lib.cropimage.CropImage"
    android:configChanges="keyboardHidden|orientation"
    android:screenOrientation="portrait"
    android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
</activity>
<activity
    android:name="org.cocos2dx.lib.ImagePickerActivity"
    android:configChanges="keyboardHidden|orientation"
    android:screenOrientation="portrait"
    android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
</activity>
  • add necessary permission
<uses-permission android:name="android.permission.CAMERA" />
  • add feature declaration
<uses-feature
    android:name="android.hardware.camera"
    android:required="false" />
<uses-feature
    android:name="android.hardware.camera.front"
    android:required="false" />

And that is it! No more settings needed.

About

A better cocos2d-x v2, for anyone who is still sticking to cocos2d-x 2.2.x+

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C++ 71.7%
  • C 20.4%
  • Lua 2.7%
  • Java 2.5%
  • Objective-C++ 1.3%
  • Objective-C 1.0%
  • Other 0.4%