2010-11-20 22:07:03 +08:00
|
|
|
cocos2d-x multiplatform
|
|
|
|
==================
|
|
|
|
|
|
|
|
[cocos2d-x][1] is a multi-platform 2D game engine in C++, based on [cocos2d-iphone][2] and licensed under MIT.
|
2011-11-18 20:35:35 +08:00
|
|
|
Now this engine has been ported to WOPhone, iOS 4.1, Android 2.1 and higher, WindowsXP & Windows7.
|
2010-11-20 22:07:03 +08:00
|
|
|
|
|
|
|
Multi Platform
|
|
|
|
-------------
|
2010-12-17 20:59:38 +08:00
|
|
|
* [cocos2d-iphone-cpp][3]: tested on iPhone 3.2, 4.1 & 4.2 SDK
|
|
|
|
* [cocos2d-android-ndk][4]: based on ndk-r4(crystax.net version) & ndk-r5, tested on Android 2.1, 2.2, 2.3 emulator, HTC G2, G3, G6, G7 device
|
2011-03-09 17:28:35 +08:00
|
|
|
* [cocos2d-wophone][5]: well tested on WOPhone of ChinaUnicom, both emulator & device.
|
2010-12-17 20:59:38 +08:00
|
|
|
* [cocos2d-win32][6]: well tested on WindowsXP & Windows7. It depends on PowerVR OpenGL ES 1.1 libraries for win32 system
|
2010-11-20 22:07:03 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Document
|
|
|
|
------------------
|
2010-12-17 21:38:03 +08:00
|
|
|
* Website: [www.cocos2d-x.org][7]
|
2011-11-18 20:35:35 +08:00
|
|
|
* [Online API References][8]
|
|
|
|
|
2010-11-20 22:07:03 +08:00
|
|
|
Contact us
|
|
|
|
------------------
|
2010-12-17 21:38:03 +08:00
|
|
|
* Forum: [http://forum.cocos2d-x.org][9]
|
|
|
|
* Twitter: [http://www.twitter.com/cocos2dx][10]
|
|
|
|
* Sina mini-blog: [http://t.sina.com.cn/cocos2dx][11]
|
2011-11-18 20:35:35 +08:00
|
|
|
|
2010-11-20 22:07:03 +08:00
|
|
|
[1]: http://www.cocos2d-x.org "cocos2d-x"
|
|
|
|
[2]: http://www.cocos2d-iphone.org "cocos2d for iPhone"
|
2011-01-17 21:16:25 +08:00
|
|
|
[3]: http://www.cocos2d-x.org/wiki/cocos2d-x/Cocos2d-iphone-cpp "cocos2d-iphone-cpp"
|
|
|
|
[4]: http://www.cocos2d-x.org/wiki/cocos2d-x/Cocos2d-android-ndk "cocos2d-android-ndk"
|
2011-03-09 17:28:35 +08:00
|
|
|
[5]: http://www.cocos2d-x.org/wiki/cocos2d-x/Cocos2d-wophone "cocos2d-wophone"
|
2011-01-17 21:16:25 +08:00
|
|
|
[6]: http://www.cocos2d-x.org/wiki/cocos2d-x/Cocos2d-win32 "cocos2d-win32"
|
2011-04-04 10:02:45 +08:00
|
|
|
[7]: http://www.cocos2d-x.org "www.cocos2d-x.org"
|
2011-01-17 21:16:25 +08:00
|
|
|
[8]: http://www.cocos2d-x.org/embedded/cocos2d-x/classes.html "API References"
|
2010-12-17 21:38:03 +08:00
|
|
|
[9]: http://forum.cocos2d-x.org "http://forum.cocos2d-x.org"
|
|
|
|
[10]: http://www.twitter.com/cocos2dx "http://www.twitter.com/cocos2dx"
|
|
|
|
[11]: http://t.sina.com.cn/cocos2dx "http://t.sina.com.cn/cocos2dx"
|
2011-11-23 13:38:56 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Lua Support FIX Readme
|
|
|
|
------------------
|
|
|
|
* CCScheduler support local function
|
|
|
|
* Support autorelease C++ object
|
2011-11-29 20:09:27 +08:00
|
|
|
* When C++ object deleted, set Lua object userdata to nil
|
2011-11-23 13:38:56 +08:00
|
|
|
* Add CCNode:setPosition(x, y), CCNode::getPosition(), huge performance boost
|
|
|
|
* Remove needless class and functions from tolua++ .pkg files, improved performance
|
2011-11-29 20:09:27 +08:00
|
|
|
* CCMenuItem support script function
|
|
|
|
* CCScene script callback
|
2011-11-30 21:55:40 +08:00
|
|
|
* CCLayer touch & multi-touches events handler
|
2011-11-23 13:38:56 +08:00
|
|
|
|
|
|
|
**How to use:**
|
|
|
|
|
2011-11-29 20:09:27 +08:00
|
|
|
-- use CCSchedule::scheduleScriptFunc()
|
|
|
|
|
2011-11-23 13:38:56 +08:00
|
|
|
local scheduler = CCScheduler:sharedScheduler()
|
|
|
|
|
|
|
|
local handle -- save script callback handle
|
|
|
|
|
|
|
|
local frameCount = 0
|
|
|
|
local function onEnterFrame(dt)
|
2011-11-29 20:09:27 +08:00
|
|
|
print("onEnterFrame:", frameCount, dt)
|
2011-11-23 13:38:56 +08:00
|
|
|
frameCount = frameCount + 1
|
|
|
|
if frameCount >= 60 then
|
|
|
|
-- remove script callback
|
|
|
|
scheduler:unscheduleScriptFunc(handle)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
handle = scheduler:scheduleScriptFunc(onEnterFrame, 1.0 / 60, false)
|
|
|
|
|
2011-11-29 20:09:27 +08:00
|
|
|
- - -
|
|
|
|
|
|
|
|
-- use CCMenuItem:registerScriptHandler()
|
|
|
|
|
|
|
|
local function onMenuItemTap(menuItemTag)
|
|
|
|
print(menuItemTag) -- output "1"
|
|
|
|
end
|
|
|
|
|
|
|
|
local menuItem = CCMenuItemImage:itemFromNormalImage("button.png", "button.png")
|
|
|
|
menuItem:registerScriptHandler(onMenuItemTap)
|
|
|
|
|
|
|
|
local menu = CCMenu:node()
|
|
|
|
menu:addChild(menuItem)
|
|
|
|
menuItem:setTag(1) -- menuItemTag
|
|
|
|
|
|
|
|
scene:addChild(menu)
|
|
|
|
|
|
|
|
- - -
|
|
|
|
|
|
|
|
-- use CCScene script callback
|
|
|
|
|
|
|
|
local function newScene()
|
|
|
|
local scene = CCScene:node()
|
|
|
|
|
|
|
|
local function sceneEventHandler(isOnEnter)
|
|
|
|
if isOnEnter then
|
|
|
|
if scene.onEnter then scene:onEnter() end
|
|
|
|
else
|
|
|
|
if scene.onExit then scene:onExit() end
|
|
|
|
scene:unregisterScriptEventsHandler()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
scene:registerScriptEventsHandler(sceneEventHandler)
|
|
|
|
return scene
|
|
|
|
end
|
|
|
|
|
|
|
|
local myScene = newScene("MyScene")
|
|
|
|
function myScene:onEnter()
|
|
|
|
print("MyScene:onEnter()")
|
|
|
|
end
|
|
|
|
|
|
|
|
function myScene:onExit()
|
|
|
|
print("MyScene:onExit()")
|
|
|
|
end
|
|
|
|
|
|
|
|
CCDirector:sharedDirector():runWithScene(myScene)
|
|
|
|
|
2011-11-30 21:55:40 +08:00
|
|
|
- - -
|
|
|
|
|
|
|
|
-- use CCLayer touch event handler
|
|
|
|
|
|
|
|
local layer = CCLayer:node()
|
|
|
|
local function onTouch(event, x, y)
|
|
|
|
-- event: CCTOUCHBEGAN, CCTOUCHMOVED, CCTOUCHENDED, CCTOUCHCANCELLED
|
|
|
|
print(event, x, y)
|
|
|
|
if event == CCTOUCHBEGAN then return true end
|
|
|
|
end
|
|
|
|
|
|
|
|
layer:registerScriptTouchHandler(onTouch, false)
|
|
|
|
|
|
|
|
- - -
|
|
|
|
|
|
|
|
-- use CCLayer multi-touches event handler
|
|
|
|
|
|
|
|
local layer = CCLayer:node()
|
|
|
|
local function onTouches(event, points)
|
|
|
|
-- event: CCTOUCHBEGAN, CCTOUCHMOVED, CCTOUCHENDED, CCTOUCHCANCELLED
|
|
|
|
print(event)
|
|
|
|
|
|
|
|
for i = 1, #points, 2 do
|
|
|
|
print(string.format("x: 0.2f, y: 0.2f", points[i], points[i + 1]))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
layer:registerScriptTouchHandler(onTouches, true)
|
2011-11-23 13:38:56 +08:00
|
|
|
|
|
|
|
**TODO:**
|
|
|
|
|
|
|
|
* When C++ object deleted, remove Lua object userdata
|