merge cocos

This commit is contained in:
yangxiao 2015-09-10 10:44:09 +08:00
commit d5fab0bd38
127 changed files with 8142 additions and 4590 deletions

View File

@ -37,4 +37,4 @@ before_install:
# whitelist # whitelist
branches: branches:
only: only:
- v3.8 - v3

View File

@ -412,6 +412,7 @@ Developers:
UI: Added ScrollViewBar for displaying a scroll bar at the side of ScrollView UI: Added ScrollViewBar for displaying a scroll bar at the side of ScrollView
UI: Added RadioButton widget UI: Added RadioButton widget
UI: Refined scroll event dispatching for ScrollView UI: Refined scroll event dispatching for ScrollView
platform: Fixed Android app occasionally freeze issue caused by Cocos2dxRenderer.nativeOnResume() is not called when the activity is resumed
Sam Clegg (sbc100) Sam Clegg (sbc100)
Author of Native Client port. Author of Native Client port.

View File

@ -1,3 +1,4 @@
cocos2d-x-3.8 final September.6 2015
cocos2d-x-3.8 rc0 August.26 2015 cocos2d-x-3.8 rc0 August.26 2015
cocos2d-x-3.8 beta0 August.14 2015 cocos2d-x-3.8 beta0 August.14 2015
@ -7,7 +8,7 @@ cocos2d-x-3.8 beta0 August.14 2015
[HIGHLIGHT] FileUtils: Added a set of file writing APIs: writeStringToFile, writeDataToFile, writeValueMapToFile, writeValueVectorToFile [HIGHLIGHT] FileUtils: Added a set of file writing APIs: writeStringToFile, writeDataToFile, writeValueMapToFile, writeValueVectorToFile
[HIGHLIGHT] UI: Refined UI system [HIGHLIGHT] UI: Refined UI system
[HIGHLIGHT] UI: Added RadioButton widget (JSB/Lua ready) [HIGHLIGHT] UI: Added RadioButton widget (JSB/Lua ready)
[HIGHLIGHT] UI: Reimplemented and enhanced EditBox on Android [HIGHLIGHT] UI: Reimplemented and enhanced EditBox on Android: display cursor; support copy, cut, paste and select actions; support multi-line input; pretty adjustment when virtual keyboard shown
[HIGHLIGHT] JS: Bound new AudioEngine in JSB [HIGHLIGHT] JS: Bound new AudioEngine in JSB
[HIGHLIGHT] JS: Merged JSB test project into cocos2d test project [HIGHLIGHT] JS: Merged JSB test project into cocos2d test project
[HIGHLIGHT] network: Upgrade SocketIO support to v1.x [HIGHLIGHT] network: Upgrade SocketIO support to v1.x
@ -27,6 +28,7 @@ cocos2d-x-3.8 beta0 August.14 2015
[NEW] audio: AudioEngine supported audio preloading [NEW] audio: AudioEngine supported audio preloading
[NEW] UserDefault: Supported removing key pairs from UserDefault [NEW] UserDefault: Supported removing key pairs from UserDefault
[NEW] spine: Supported Spine runtime 2.3 (Both native and web engine) [NEW] spine: Supported Spine runtime 2.3 (Both native and web engine)
[NEW] JS: Added auto binding for BlendFuncFrame
[NEW] console: Supported new portrait projects from templates [NEW] console: Supported new portrait projects from templates
[NEW] console: Moved the framework-compile tools into cocos2d-console [NEW] console: Moved the framework-compile tools into cocos2d-console
[NEW] framework: Support generate prebuilt libs of engine with debug mode [NEW] framework: Support generate prebuilt libs of engine with debug mode
@ -35,6 +37,10 @@ cocos2d-x-3.8 beta0 August.14 2015
[REFINE] 3D: Supported composite 2D/3D scene by moving UI and camera far away [REFINE] 3D: Supported composite 2D/3D scene by moving UI and camera far away
[REFINE] 3D: Improved Particle3D performance [REFINE] 3D: Improved Particle3D performance
[REFINE] 3D: Made SkyBox not transparent [REFINE] 3D: Made SkyBox not transparent
[REFINE] 3D: Enable depth write for SkyBox
[REFINE] 3D: Enable depth write for transparent object
[REFINE] 3D: Set depth test function of Skybox brush to always
[REFINE] renderer: Enabled blending all the time for 2D render queue
[REFINE] Director: Made types to handle time consistent by modifing setAnimationInterval argument from double to float [REFINE] Director: Made types to handle time consistent by modifing setAnimationInterval argument from double to float
[REFINE] Sprite: Made Sprite::setTexture accept nullptr as parameter [REFINE] Sprite: Made Sprite::setTexture accept nullptr as parameter
[REFINE] TextureCache: Made addImageAsync function thread safe [REFINE] TextureCache: Made addImageAsync function thread safe
@ -52,6 +58,7 @@ cocos2d-x-3.8 beta0 August.14 2015
[REFINE] studio: Avoid CSLoader from openning csb file multiple times with fopen [REFINE] studio: Avoid CSLoader from openning csb file multiple times with fopen
[REFINE] studio: Added BlendFrame support to Skeleton Animation [REFINE] studio: Added BlendFrame support to Skeleton Animation
[REFINE] studio: Enabled blendfunc cascade to the skin of BoneNode [REFINE] studio: Enabled blendfunc cascade to the skin of BoneNode
[REFINE] studio: Update reader with parse logic for valid attribute of SkyBox
[REFINE] FileUtils: Remove old path while adding existing search path [REFINE] FileUtils: Remove old path while adding existing search path
[REFINE] Device: Implemented Device::getDPI for Mac [REFINE] Device: Implemented Device::getDPI for Mac
[REFINE] network: Refine NSLog in HttpAsynConnection in release mode [REFINE] network: Refine NSLog in HttpAsynConnection in release mode
@ -92,6 +99,7 @@ cocos2d-x-3.8 beta0 August.14 2015
[FIX] renderer: Fixed shader issue by reloading shader when light number changed [FIX] renderer: Fixed shader issue by reloading shader when light number changed
[FIX] Scheduler: Fixed timer's delta time is error when interval equals to zero [FIX] Scheduler: Fixed timer's delta time is error when interval equals to zero
[FIX] Scheduler: Fixed Pause/Resume act incorrectly [FIX] Scheduler: Fixed Pause/Resume act incorrectly
[FIX] Scheduler: Fixed the callback will be executed multiple times if the value of delay parameter equal zero
[FIX] Node: Fixed issue that euler angle is NaN when update Euler angle from quaternion and asin value is not between -1 and 1 by accident [FIX] Node: Fixed issue that euler angle is NaN when update Euler angle from quaternion and asin value is not between -1 and 1 by accident
[FIX] Scene: Fixed bug that can't add custom member to Scene subclass [FIX] Scene: Fixed bug that can't add custom member to Scene subclass
[FIX] Sprite: Fixed some warnings and a related bug in CCSprite [FIX] Sprite: Fixed some warnings and a related bug in CCSprite
@ -131,6 +139,9 @@ cocos2d-x-3.8 beta0 August.14 2015
[FIX] UI: Fixed EditBox input maxLength for Chinese character issue on iOS [FIX] UI: Fixed EditBox input maxLength for Chinese character issue on iOS
[FIX] UI: Fixed EditBox turning black when soft keyboard hiding [FIX] UI: Fixed EditBox turning black when soft keyboard hiding
[FIX] UI: Fixed scrollview innerContainer initial position error [FIX] UI: Fixed scrollview innerContainer initial position error
[FIX] UI: Fixed issue that Slider create function is not taking account of res type (TextureResType)
[FIX] Scale9Sprite: Fixed Scale9Sprite default capInset bug
[FIX] Scale9Sprite: Fixed issue that Scale9Sprite draw extra 1 pixel when creating from spritesheet
[FIX] studio: Removed "using namespace cocos2d" from CCFrame.h [FIX] studio: Removed "using namespace cocos2d" from CCFrame.h
[FIX] studio: Fixed the SkyBox display error while parsed from editor files [FIX] studio: Fixed the SkyBox display error while parsed from editor files
[FIX] studio: Fixed userCamera flag error while parsing old version exported files [FIX] studio: Fixed userCamera flag error while parsing old version exported files
@ -138,6 +149,8 @@ cocos2d-x-3.8 beta0 August.14 2015
[FIX] studio: Fixed crash when loading cocostudio json files with null or empty fontName [FIX] studio: Fixed crash when loading cocostudio json files with null or empty fontName
[FIX] studio: Fixed bug that setColor works on a whole armature, but not on an individual bone [FIX] studio: Fixed bug that setColor works on a whole armature, but not on an individual bone
[FIX] studio: Fixed object size error while data is error [FIX] studio: Fixed object size error while data is error
[FIX] studio: Fixed issue that bone's color and opacity cannot cascade to bone
[FIX] studio: Fixed issue that bone can be see by other cameras
[FIX] ClippingNode: Removed CCClippingRectangleNode transform error support [FIX] ClippingNode: Removed CCClippingRectangleNode transform error support
[FIX] spine: Fixed the position of debug draw of bones is incorrect [FIX] spine: Fixed the position of debug draw of bones is incorrect
[FIX] spine: Fixed memory leak caused by SkeletonRenderer::initialize [FIX] spine: Fixed memory leak caused by SkeletonRenderer::initialize
@ -174,6 +187,7 @@ cocos2d-x-3.8 beta0 August.14 2015
[FIX] platform: Removed unneeded protocol for AppController on iOS [FIX] platform: Removed unneeded protocol for AppController on iOS
[FIX] platform: Fixed link errors in release mode on win32 [FIX] platform: Fixed link errors in release mode on win32
[FIX] platform: Fixed Windows 10 UWP and WP8.1 app certification issue [FIX] platform: Fixed Windows 10 UWP and WP8.1 app certification issue
[FIX] platform: Fixed Android app occasionally freeze issue caused by Cocos2dxRenderer.nativeOnResume() is not called when the activity is resumed
[FIX] web: Fixed a bug that VideoPlayer remove event throw error [FIX] web: Fixed a bug that VideoPlayer remove event throw error
[FIX] web: Fixed Armature position error in studio JSON parser [FIX] web: Fixed Armature position error in studio JSON parser
[FIX] web: Fixed default clearColor error in director [FIX] web: Fixed default clearColor error in director
@ -187,6 +201,9 @@ cocos2d-x-3.8 beta0 August.14 2015
[FIX] web: Fixed logic issue in Menu's _onTouchCancelled function [FIX] web: Fixed logic issue in Menu's _onTouchCancelled function
[FIX] web: Fixed MenuItem crash when normal image is null [FIX] web: Fixed MenuItem crash when normal image is null
[FIX] web: Fixed CCTouch's startPoint unset issue [FIX] web: Fixed CCTouch's startPoint unset issue
[FIX] web: Fixed incomplete fadeout effects
[FIX] web: Fixed issue that return value of cc.screen.fullScreen is not boolean
[FIX] web: Fixed a bug that SkeletonNode is not drawing children
[TEST] 3D: Avoid to trigger touch event multiple times in Physics3D Test and Physics3D Constraint Test [TEST] 3D: Avoid to trigger touch event multiple times in Physics3D Test and Physics3D Constraint Test
[TEST] 3D: Fixed Sprite3D test background to foreground bug [TEST] 3D: Fixed Sprite3D test background to foreground bug

View File

@ -1224,6 +1224,8 @@
299754F5193EC95400A54AC3 /* ObjectFactory.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 299754F2193EC95400A54AC3 /* ObjectFactory.cpp */; }; 299754F5193EC95400A54AC3 /* ObjectFactory.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 299754F2193EC95400A54AC3 /* ObjectFactory.cpp */; };
299754F6193EC95400A54AC3 /* ObjectFactory.h in Headers */ = {isa = PBXBuildFile; fileRef = 299754F3193EC95400A54AC3 /* ObjectFactory.h */; }; 299754F6193EC95400A54AC3 /* ObjectFactory.h in Headers */ = {isa = PBXBuildFile; fileRef = 299754F3193EC95400A54AC3 /* ObjectFactory.h */; };
299754F7193EC95400A54AC3 /* ObjectFactory.h in Headers */ = {isa = PBXBuildFile; fileRef = 299754F3193EC95400A54AC3 /* ObjectFactory.h */; }; 299754F7193EC95400A54AC3 /* ObjectFactory.h in Headers */ = {isa = PBXBuildFile; fileRef = 299754F3193EC95400A54AC3 /* ObjectFactory.h */; };
299B15AC1B93FC530008E196 /* UIEditBoxImpl-common.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 299B15AA1B93FC530008E196 /* UIEditBoxImpl-common.cpp */; };
299B15AD1B93FC530008E196 /* UIEditBoxImpl-common.h in Headers */ = {isa = PBXBuildFile; fileRef = 299B15AB1B93FC530008E196 /* UIEditBoxImpl-common.h */; };
299CF1FB19A434BC00C378C1 /* ccRandom.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 299CF1F919A434BC00C378C1 /* ccRandom.cpp */; }; 299CF1FB19A434BC00C378C1 /* ccRandom.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 299CF1F919A434BC00C378C1 /* ccRandom.cpp */; };
299CF1FC19A434BC00C378C1 /* ccRandom.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 299CF1F919A434BC00C378C1 /* ccRandom.cpp */; }; 299CF1FC19A434BC00C378C1 /* ccRandom.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 299CF1F919A434BC00C378C1 /* ccRandom.cpp */; };
299CF1FD19A434BC00C378C1 /* ccRandom.h in Headers */ = {isa = PBXBuildFile; fileRef = 299CF1FA19A434BC00C378C1 /* ccRandom.h */; }; 299CF1FD19A434BC00C378C1 /* ccRandom.h in Headers */ = {isa = PBXBuildFile; fileRef = 299CF1FA19A434BC00C378C1 /* ccRandom.h */; };
@ -1361,6 +1363,14 @@
46C02E0818E91123004B7456 /* xxhash.c in Sources */ = {isa = PBXBuildFile; fileRef = 46C02E0518E91123004B7456 /* xxhash.c */; }; 46C02E0818E91123004B7456 /* xxhash.c in Sources */ = {isa = PBXBuildFile; fileRef = 46C02E0518E91123004B7456 /* xxhash.c */; };
46C02E0918E91123004B7456 /* xxhash.h in Headers */ = {isa = PBXBuildFile; fileRef = 46C02E0618E91123004B7456 /* xxhash.h */; }; 46C02E0918E91123004B7456 /* xxhash.h in Headers */ = {isa = PBXBuildFile; fileRef = 46C02E0618E91123004B7456 /* xxhash.h */; };
46C02E0A18E91123004B7456 /* xxhash.h in Headers */ = {isa = PBXBuildFile; fileRef = 46C02E0618E91123004B7456 /* xxhash.h */; }; 46C02E0A18E91123004B7456 /* xxhash.h in Headers */ = {isa = PBXBuildFile; fileRef = 46C02E0618E91123004B7456 /* xxhash.h */; };
46EE47511B817EFD00100730 /* CCComponentPhysics2d.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 46EE474D1B817EFD00100730 /* CCComponentPhysics2d.cpp */; };
46EE47521B817EFD00100730 /* CCComponentPhysics2d.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 46EE474D1B817EFD00100730 /* CCComponentPhysics2d.cpp */; };
46EE47531B817EFD00100730 /* CCComponentPhysics2d.h in Headers */ = {isa = PBXBuildFile; fileRef = 46EE474E1B817EFD00100730 /* CCComponentPhysics2d.h */; };
46EE47541B817EFD00100730 /* CCComponentPhysics2d.h in Headers */ = {isa = PBXBuildFile; fileRef = 46EE474E1B817EFD00100730 /* CCComponentPhysics2d.h */; };
46EE47551B817EFD00100730 /* CCPhysicsManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 46EE474F1B817EFD00100730 /* CCPhysicsManager.cpp */; };
46EE47561B817EFD00100730 /* CCPhysicsManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 46EE474F1B817EFD00100730 /* CCPhysicsManager.cpp */; };
46EE47571B817EFD00100730 /* CCPhysicsManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 46EE47501B817EFD00100730 /* CCPhysicsManager.h */; };
46EE47581B817EFD00100730 /* CCPhysicsManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 46EE47501B817EFD00100730 /* CCPhysicsManager.h */; };
4D76BE3A1A4AAF0A00102962 /* CCActionTimelineNode.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4D76BE381A4AAF0A00102962 /* CCActionTimelineNode.cpp */; }; 4D76BE3A1A4AAF0A00102962 /* CCActionTimelineNode.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4D76BE381A4AAF0A00102962 /* CCActionTimelineNode.cpp */; };
4D76BE3B1A4AAF0A00102962 /* CCActionTimelineNode.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4D76BE381A4AAF0A00102962 /* CCActionTimelineNode.cpp */; }; 4D76BE3B1A4AAF0A00102962 /* CCActionTimelineNode.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4D76BE381A4AAF0A00102962 /* CCActionTimelineNode.cpp */; };
4D76BE3C1A4AAF0A00102962 /* CCActionTimelineNode.h in Headers */ = {isa = PBXBuildFile; fileRef = 4D76BE391A4AAF0A00102962 /* CCActionTimelineNode.h */; }; 4D76BE3C1A4AAF0A00102962 /* CCActionTimelineNode.h in Headers */ = {isa = PBXBuildFile; fileRef = 4D76BE391A4AAF0A00102962 /* CCActionTimelineNode.h */; };
@ -4108,6 +4118,8 @@
2986667918B1B079000E39CA /* CCTweenFunction.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCTweenFunction.h; sourceTree = "<group>"; }; 2986667918B1B079000E39CA /* CCTweenFunction.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCTweenFunction.h; sourceTree = "<group>"; };
299754F2193EC95400A54AC3 /* ObjectFactory.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ObjectFactory.cpp; path = ../base/ObjectFactory.cpp; sourceTree = "<group>"; }; 299754F2193EC95400A54AC3 /* ObjectFactory.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ObjectFactory.cpp; path = ../base/ObjectFactory.cpp; sourceTree = "<group>"; };
299754F3193EC95400A54AC3 /* ObjectFactory.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ObjectFactory.h; path = ../base/ObjectFactory.h; sourceTree = "<group>"; }; 299754F3193EC95400A54AC3 /* ObjectFactory.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ObjectFactory.h; path = ../base/ObjectFactory.h; sourceTree = "<group>"; };
299B15AA1B93FC530008E196 /* UIEditBoxImpl-common.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = "UIEditBoxImpl-common.cpp"; sourceTree = "<group>"; };
299B15AB1B93FC530008E196 /* UIEditBoxImpl-common.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIEditBoxImpl-common.h"; sourceTree = "<group>"; };
299CF1F919A434BC00C378C1 /* ccRandom.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ccRandom.cpp; path = ../base/ccRandom.cpp; sourceTree = "<group>"; }; 299CF1F919A434BC00C378C1 /* ccRandom.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ccRandom.cpp; path = ../base/ccRandom.cpp; sourceTree = "<group>"; };
299CF1FA19A434BC00C378C1 /* ccRandom.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ccRandom.h; path = ../base/ccRandom.h; sourceTree = "<group>"; }; 299CF1FA19A434BC00C378C1 /* ccRandom.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ccRandom.h; path = ../base/ccRandom.h; sourceTree = "<group>"; };
29BDBA52195D597A003225C9 /* UIDeprecated.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = UIDeprecated.cpp; sourceTree = "<group>"; }; 29BDBA52195D597A003225C9 /* UIDeprecated.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = UIDeprecated.cpp; sourceTree = "<group>"; };
@ -4350,6 +4362,10 @@
46A170781807CE7A005B8026 /* CCPhysicsWorld.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CCPhysicsWorld.h; sourceTree = "<group>"; }; 46A170781807CE7A005B8026 /* CCPhysicsWorld.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CCPhysicsWorld.h; sourceTree = "<group>"; };
46C02E0518E91123004B7456 /* xxhash.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = xxhash.c; sourceTree = "<group>"; }; 46C02E0518E91123004B7456 /* xxhash.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = xxhash.c; sourceTree = "<group>"; };
46C02E0618E91123004B7456 /* xxhash.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = xxhash.h; sourceTree = "<group>"; }; 46C02E0618E91123004B7456 /* xxhash.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = xxhash.h; sourceTree = "<group>"; };
46EE474D1B817EFD00100730 /* CCComponentPhysics2d.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CCComponentPhysics2d.cpp; sourceTree = "<group>"; };
46EE474E1B817EFD00100730 /* CCComponentPhysics2d.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCComponentPhysics2d.h; sourceTree = "<group>"; };
46EE474F1B817EFD00100730 /* CCPhysicsManager.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CCPhysicsManager.cpp; sourceTree = "<group>"; };
46EE47501B817EFD00100730 /* CCPhysicsManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCPhysicsManager.h; sourceTree = "<group>"; };
4D76BE381A4AAF0A00102962 /* CCActionTimelineNode.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CCActionTimelineNode.cpp; sourceTree = "<group>"; }; 4D76BE381A4AAF0A00102962 /* CCActionTimelineNode.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CCActionTimelineNode.cpp; sourceTree = "<group>"; };
4D76BE391A4AAF0A00102962 /* CCActionTimelineNode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCActionTimelineNode.h; sourceTree = "<group>"; }; 4D76BE391A4AAF0A00102962 /* CCActionTimelineNode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCActionTimelineNode.h; sourceTree = "<group>"; };
5012168C1AC47380009A4BEA /* CCRenderState.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CCRenderState.cpp; sourceTree = "<group>"; }; 5012168C1AC47380009A4BEA /* CCRenderState.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CCRenderState.cpp; sourceTree = "<group>"; };
@ -6816,6 +6832,8 @@
292DB12E19B4574100A80320 /* UIEditBox */ = { 292DB12E19B4574100A80320 /* UIEditBox */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
299B15AA1B93FC530008E196 /* UIEditBoxImpl-common.cpp */,
299B15AB1B93FC530008E196 /* UIEditBoxImpl-common.h */,
50ED2BDC19BEAF7900A0AB90 /* UIEditBoxImpl-win32.h */, 50ED2BDC19BEAF7900A0AB90 /* UIEditBoxImpl-win32.h */,
50ED2BDE19BEAF7900A0AB90 /* UIEditBoxImpl-win32.cpp */, 50ED2BDE19BEAF7900A0AB90 /* UIEditBoxImpl-win32.cpp */,
292DB12F19B4574100A80320 /* UIEditBox.cpp */, 292DB12F19B4574100A80320 /* UIEditBox.cpp */,
@ -7362,6 +7380,10 @@
46A170611807CE7A005B8026 /* physics */ = { 46A170611807CE7A005B8026 /* physics */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
46EE474D1B817EFD00100730 /* CCComponentPhysics2d.cpp */,
46EE474E1B817EFD00100730 /* CCComponentPhysics2d.h */,
46EE474F1B817EFD00100730 /* CCPhysicsManager.cpp */,
46EE47501B817EFD00100730 /* CCPhysicsManager.h */,
ED74D7681A5B8A2600157FD4 /* CCPhysicsHelper.h */, ED74D7681A5B8A2600157FD4 /* CCPhysicsHelper.h */,
46A1706E1807CE7A005B8026 /* CCPhysicsBody.cpp */, 46A1706E1807CE7A005B8026 /* CCPhysicsBody.cpp */,
46A1706F1807CE7A005B8026 /* CCPhysicsBody.h */, 46A1706F1807CE7A005B8026 /* CCPhysicsBody.h */,
@ -9656,6 +9678,7 @@
B6CAB3351AF9AA1A00B9B856 /* btGImpactShape.h in Headers */, B6CAB3351AF9AA1A00B9B856 /* btGImpactShape.h in Headers */,
15AE1A6F19AAD40300C27E9E /* b2CircleContact.h in Headers */, 15AE1A6F19AAD40300C27E9E /* b2CircleContact.h in Headers */,
B6CAB3431AF9AA1A00B9B856 /* gim_box_collision.h in Headers */, B6CAB3431AF9AA1A00B9B856 /* gim_box_collision.h in Headers */,
46EE47531B817EFD00100730 /* CCComponentPhysics2d.h in Headers */,
B6CAB39B1AF9AA1A00B9B856 /* btVoronoiSimplexSolver.h in Headers */, B6CAB39B1AF9AA1A00B9B856 /* btVoronoiSimplexSolver.h in Headers */,
B6CAB1EB1AF9AA1A00B9B856 /* btBroadphaseInterface.h in Headers */, B6CAB1EB1AF9AA1A00B9B856 /* btBroadphaseInterface.h in Headers */,
B665E3E81AA80A6600DDB1C5 /* CCPUSineForceAffectorTranslator.h in Headers */, B665E3E81AA80A6600DDB1C5 /* CCPUSineForceAffectorTranslator.h in Headers */,
@ -9727,6 +9750,7 @@
5034CA35191D591100CE6051 /* ccShader_PositionTexture.frag in Headers */, 5034CA35191D591100CE6051 /* ccShader_PositionTexture.frag in Headers */,
15AE1BB219AADFEF00C27E9E /* HttpClient.h in Headers */, 15AE1BB219AADFEF00C27E9E /* HttpClient.h in Headers */,
B6CAB3FD1AF9AA1A00B9B856 /* btMultiBodyConstraint.h in Headers */, B6CAB3FD1AF9AA1A00B9B856 /* btMultiBodyConstraint.h in Headers */,
46EE47571B817EFD00100730 /* CCPhysicsManager.h in Headers */,
B6DD2FF31B04825B00E47F5F /* DetourTileCacheBuilder.h in Headers */, B6DD2FF31B04825B00E47F5F /* DetourTileCacheBuilder.h in Headers */,
15AE197619AAD35700C27E9E /* CCTimelineMacro.h in Headers */, 15AE197619AAD35700C27E9E /* CCTimelineMacro.h in Headers */,
50ABBE6F1925AB6F00A911A9 /* CCEventListenerKeyboard.h in Headers */, 50ABBE6F1925AB6F00A911A9 /* CCEventListenerKeyboard.h in Headers */,
@ -10173,6 +10197,7 @@
1A570084180BC5A10088DEC7 /* CCActionManager.h in Headers */, 1A570084180BC5A10088DEC7 /* CCActionManager.h in Headers */,
B665E3151AA80A6500DDB1C5 /* CCPUObserverManager.h in Headers */, B665E3151AA80A6500DDB1C5 /* CCPUObserverManager.h in Headers */,
15AE18C619AAD33D00C27E9E /* CCLayerLoader.h in Headers */, 15AE18C619AAD33D00C27E9E /* CCLayerLoader.h in Headers */,
46EE47541B817EFD00100730 /* CCComponentPhysics2d.h in Headers */,
B6CAB4A41AF9AA1A00B9B856 /* PpuAddressSpace.h in Headers */, B6CAB4A41AF9AA1A00B9B856 /* PpuAddressSpace.h in Headers */,
B6CAB2041AF9AA1A00B9B856 /* btMultiSapBroadphase.h in Headers */, B6CAB2041AF9AA1A00B9B856 /* btMultiSapBroadphase.h in Headers */,
B665E2C51AA80A6500DDB1C5 /* CCPUGeometryRotatorTranslator.h in Headers */, B665E2C51AA80A6500DDB1C5 /* CCPUGeometryRotatorTranslator.h in Headers */,
@ -10540,6 +10565,7 @@
15AE1BEB19AAE01E00C27E9E /* CCControlButton.h in Headers */, 15AE1BEB19AAE01E00C27E9E /* CCControlButton.h in Headers */,
B6CAB1F81AF9AA1A00B9B856 /* btDbvt.h in Headers */, B6CAB1F81AF9AA1A00B9B856 /* btDbvt.h in Headers */,
B665E35D1AA80A6500DDB1C5 /* CCPUOnRandomObserver.h in Headers */, B665E35D1AA80A6500DDB1C5 /* CCPUOnRandomObserver.h in Headers */,
299B15AD1B93FC530008E196 /* UIEditBoxImpl-common.h in Headers */,
1A570281180BCC900088DEC7 /* CCSprite.h in Headers */, 1A570281180BCC900088DEC7 /* CCSprite.h in Headers */,
B6DD2FD21B04825B00E47F5F /* DetourNode.h in Headers */, B6DD2FD21B04825B00E47F5F /* DetourNode.h in Headers */,
1A570285180BCC900088DEC7 /* CCSpriteBatchNode.h in Headers */, 1A570285180BCC900088DEC7 /* CCSpriteBatchNode.h in Headers */,
@ -10945,6 +10971,7 @@
B6CAB3E01AF9AA1A00B9B856 /* btTypedConstraint.h in Headers */, B6CAB3E01AF9AA1A00B9B856 /* btTypedConstraint.h in Headers */,
50ABBDAA1925AB4100A911A9 /* CCRenderCommand.h in Headers */, 50ABBDAA1925AB4100A911A9 /* CCRenderCommand.h in Headers */,
B29A7DF019EE1B7700872B35 /* SkeletonBounds.h in Headers */, B29A7DF019EE1B7700872B35 /* SkeletonBounds.h in Headers */,
46EE47581B817EFD00100730 /* CCPhysicsManager.h in Headers */,
B6CAB3361AF9AA1A00B9B856 /* btGImpactShape.h in Headers */, B6CAB3361AF9AA1A00B9B856 /* btGImpactShape.h in Headers */,
15AE1BE919AAE01E00C27E9E /* CCControl.h in Headers */, 15AE1BE919AAE01E00C27E9E /* CCControl.h in Headers */,
15AE193719AAD35100C27E9E /* CCArmature.h in Headers */, 15AE193719AAD35100C27E9E /* CCArmature.h in Headers */,
@ -11285,6 +11312,7 @@
38B8E2E119E671D2002D7CE7 /* UILayoutComponent.cpp in Sources */, 38B8E2E119E671D2002D7CE7 /* UILayoutComponent.cpp in Sources */,
B665E3F61AA80A6600DDB1C5 /* CCPUSlaveEmitterTranslator.cpp in Sources */, B665E3F61AA80A6600DDB1C5 /* CCPUSlaveEmitterTranslator.cpp in Sources */,
1A57019D180BCB590088DEC7 /* CCFont.cpp in Sources */, 1A57019D180BCB590088DEC7 /* CCFont.cpp in Sources */,
46EE47551B817EFD00100730 /* CCPhysicsManager.cpp in Sources */,
B6CAB2D51AF9AA1A00B9B856 /* btOptimizedBvh.cpp in Sources */, B6CAB2D51AF9AA1A00B9B856 /* btOptimizedBvh.cpp in Sources */,
50CB247B19D9C5A100687767 /* AudioEngine-inl.mm in Sources */, 50CB247B19D9C5A100687767 /* AudioEngine-inl.mm in Sources */,
1A5701A1180BCB590088DEC7 /* CCFontAtlas.cpp in Sources */, 1A5701A1180BCB590088DEC7 /* CCFontAtlas.cpp in Sources */,
@ -11507,6 +11535,7 @@
B6CAB3631AF9AA1A00B9B856 /* btContinuousConvexCollision.cpp in Sources */, B6CAB3631AF9AA1A00B9B856 /* btContinuousConvexCollision.cpp in Sources */,
B665E3021AA80A6500DDB1C5 /* CCPUMeshSurfaceEmitter.cpp in Sources */, B665E3021AA80A6500DDB1C5 /* CCPUMeshSurfaceEmitter.cpp in Sources */,
B665E3721AA80A6500DDB1C5 /* CCPUParticleFollower.cpp in Sources */, B665E3721AA80A6500DDB1C5 /* CCPUParticleFollower.cpp in Sources */,
46EE47511B817EFD00100730 /* CCComponentPhysics2d.cpp in Sources */,
B6CAB22B1AF9AA1A00B9B856 /* btCollisionObject.cpp in Sources */, B6CAB22B1AF9AA1A00B9B856 /* btCollisionObject.cpp in Sources */,
1A5702C8180BCE370088DEC7 /* CCTextFieldTTF.cpp in Sources */, 1A5702C8180BCE370088DEC7 /* CCTextFieldTTF.cpp in Sources */,
B665E2861AA80A6500DDB1C5 /* CCPUDoStopSystemEventHandlerTranslator.cpp in Sources */, B665E2861AA80A6500DDB1C5 /* CCPUDoStopSystemEventHandlerTranslator.cpp in Sources */,
@ -11970,6 +11999,7 @@
1A57006E180BC5A10088DEC7 /* CCActionEase.cpp in Sources */, 1A57006E180BC5A10088DEC7 /* CCActionEase.cpp in Sources */,
50ABBD8C1925AB4100A911A9 /* CCGLProgram.cpp in Sources */, 50ABBD8C1925AB4100A911A9 /* CCGLProgram.cpp in Sources */,
B665E2671AA80A6500DDB1C5 /* CCPUDoExpireEventHandlerTranslator.cpp in Sources */, B665E2671AA80A6500DDB1C5 /* CCPUDoExpireEventHandlerTranslator.cpp in Sources */,
46EE47561B817EFD00100730 /* CCPhysicsManager.cpp in Sources */,
B6CAB4AA1AF9AA1A00B9B856 /* SpuCollisionObjectWrapper.cpp in Sources */, B6CAB4AA1AF9AA1A00B9B856 /* SpuCollisionObjectWrapper.cpp in Sources */,
B6CAAFFF1AF9A9E100B9B856 /* CCPhysicsSprite3D.cpp in Sources */, B6CAAFFF1AF9A9E100B9B856 /* CCPhysicsSprite3D.cpp in Sources */,
15AE196119AAD35100C27E9E /* CCSSceneReader.cpp in Sources */, 15AE196119AAD35100C27E9E /* CCSSceneReader.cpp in Sources */,
@ -12152,6 +12182,7 @@
B6CAB2201AF9AA1A00B9B856 /* btBoxBoxDetector.cpp in Sources */, B6CAB2201AF9AA1A00B9B856 /* btBoxBoxDetector.cpp in Sources */,
5E9F612B1A3FFE3D0038DE01 /* CCPlane.cpp in Sources */, 5E9F612B1A3FFE3D0038DE01 /* CCPlane.cpp in Sources */,
1A57019E180BCB590088DEC7 /* CCFont.cpp in Sources */, 1A57019E180BCB590088DEC7 /* CCFont.cpp in Sources */,
46EE47521B817EFD00100730 /* CCComponentPhysics2d.cpp in Sources */,
15AE1ACC19AAD40300C27E9E /* b2PrismaticJoint.cpp in Sources */, 15AE1ACC19AAD40300C27E9E /* b2PrismaticJoint.cpp in Sources */,
15AE195F19AAD35100C27E9E /* CCSpriteFrameCacheHelper.cpp in Sources */, 15AE195F19AAD35100C27E9E /* CCSpriteFrameCacheHelper.cpp in Sources */,
15AE193019AAD35100C27E9E /* CCActionManagerEx.cpp in Sources */, 15AE193019AAD35100C27E9E /* CCActionManagerEx.cpp in Sources */,
@ -12226,6 +12257,7 @@
B6DD2FC41B04825B00E47F5F /* DetourNavMesh.cpp in Sources */, B6DD2FC41B04825B00E47F5F /* DetourNavMesh.cpp in Sources */,
B6CAAFFB1AF9A9E100B9B856 /* CCPhysics3DWorld.cpp in Sources */, B6CAAFFB1AF9A9E100B9B856 /* CCPhysics3DWorld.cpp in Sources */,
B665E3471AA80A6500DDB1C5 /* CCPUOnExpireObserverTranslator.cpp in Sources */, B665E3471AA80A6500DDB1C5 /* CCPUOnExpireObserverTranslator.cpp in Sources */,
299B15AC1B93FC530008E196 /* UIEditBoxImpl-common.cpp in Sources */,
B6CAB2A41AF9AA1A00B9B856 /* btConvexHullShape.cpp in Sources */, B6CAB2A41AF9AA1A00B9B856 /* btConvexHullShape.cpp in Sources */,
15AE1AA519AAD40300C27E9E /* b2Fixture.cpp in Sources */, 15AE1AA519AAD40300C27E9E /* b2Fixture.cpp in Sources */,
B29A7DE219EE1B7700872B35 /* MeshAttachment.c in Sources */, B29A7DE219EE1B7700872B35 /* MeshAttachment.c in Sources */,

View File

@ -42,6 +42,10 @@ Action::Action()
,_tag(Action::INVALID_TAG) ,_tag(Action::INVALID_TAG)
,_flags(0) ,_flags(0)
{ {
#if CC_ENABLE_SCRIPT_BINDING
ScriptEngineProtocol* engine = ScriptEngineManager::getInstance()->getScriptEngine();
_scriptType = engine != nullptr ? engine->getScriptType() : kScriptTypeNone;
#endif
} }
Action::~Action() Action::~Action()

View File

@ -30,10 +30,16 @@ THE SOFTWARE.
#include "base/CCRef.h" #include "base/CCRef.h"
#include "math/CCGeometry.h" #include "math/CCGeometry.h"
#include "base/CCScriptSupport.h"
NS_CC_BEGIN NS_CC_BEGIN
class Node; class Node;
enum {
kActionUpdate
};
/** /**
* @addtogroup actions * @addtogroup actions
* @{ * @{
@ -172,6 +178,9 @@ protected:
/** The action flag field. To categorize action into certain groups.*/ /** The action flag field. To categorize action into certain groups.*/
unsigned int _flags; unsigned int _flags;
#if CC_ENABLE_SCRIPT_BINDING
ccScriptType _scriptType; ///< type of script binding, lua or javascript
#endif
private: private:
CC_DISALLOW_COPY_AND_ASSIGN(Action); CC_DISALLOW_COPY_AND_ASSIGN(Action);
}; };
@ -221,7 +230,6 @@ CC_CONSTRUCTOR_ACCESS:
protected: protected:
//! Duration in seconds. //! Duration in seconds.
float _duration; float _duration;
private: private:
CC_DISALLOW_COPY_AND_ASSIGN(FiniteTimeAction); CC_DISALLOW_COPY_AND_ASSIGN(FiniteTimeAction);
}; };

View File

@ -116,7 +116,7 @@ void ActionCamera::updateTransform()
} }
// FIXME: Using the AdditionalTransform is a complete hack. // FIXME: Using the AdditionalTransform is a complete hack.
// This should be done by multipliying the lookup-Matrix with the Node's MV matrix // This should be done by multiplying the lookup-Matrix with the Node's MV matrix
// And then setting the result as the new MV matrix // And then setting the result as the new MV matrix
// But that operation needs to be done after all the 'updates'. // But that operation needs to be done after all the 'updates'.
// So the Director should emit an 'director_after_update' event. // So the Director should emit an 'director_after_update' event.

View File

@ -47,7 +47,15 @@ bool ActionInstant::isDone() const
void ActionInstant::step(float dt) { void ActionInstant::step(float dt) {
CC_UNUSED_PARAM(dt); CC_UNUSED_PARAM(dt);
update(1); float updateDt = 1;
#if CC_ENABLE_SCRIPT_BINDING
if (_scriptType == kScriptTypeJavascript)
{
if (ScriptEngineManager::sendActionEventToJS(this, kActionUpdate, (void *)&updateDt))
return;
}
#endif
update(updateDt);
} }
void ActionInstant::update(float time) { void ActionInstant::update(float time) {

View File

@ -37,6 +37,7 @@ THE SOFTWARE.
#include "base/CCEventCustom.h" #include "base/CCEventCustom.h"
#include "base/CCEventDispatcher.h" #include "base/CCEventDispatcher.h"
#include "platform/CCStdC.h" #include "platform/CCStdC.h"
#include "base/CCScriptSupport.h"
NS_CC_BEGIN NS_CC_BEGIN
@ -105,6 +106,18 @@ bool ActionInterval::initWithDuration(float d)
return true; return true;
} }
bool ActionInterval::sendUpdateEventToScript(float dt, Action *actionObject)
{
#if CC_ENABLE_SCRIPT_BINDING
if (_scriptType == kScriptTypeJavascript)
{
if (ScriptEngineManager::sendActionEventToJS(actionObject, kActionUpdate, (void *)&dt))
return true;
}
#endif
return false;
}
bool ActionInterval::isDone() const bool ActionInterval::isDone() const
{ {
return _elapsed >= _duration; return _elapsed >= _duration;
@ -122,12 +135,16 @@ void ActionInterval::step(float dt)
_elapsed += dt; _elapsed += dt;
} }
this->update(MAX (0, // needed for rewind. elapsed could be negative
MIN(1, _elapsed / float updateDt = MAX (0, // needed for rewind. elapsed could be negative
MAX(_duration, FLT_EPSILON) // division by 0 MIN(1, _elapsed /
) MAX(_duration, FLT_EPSILON) // division by 0
) )
); );
if (sendUpdateEventToScript(updateDt, this)) return;
this->update(updateDt);
} }
void ActionInterval::setAmplitudeRate(float amp) void ActionInterval::setAmplitudeRate(float amp)
@ -323,13 +340,15 @@ void Sequence::update(float t)
if( _last == -1 ) { if( _last == -1 ) {
// action[0] was skipped, execute it. // action[0] was skipped, execute it.
_actions[0]->startWithTarget(_target); _actions[0]->startWithTarget(_target);
_actions[0]->update(1.0f); if (!(sendUpdateEventToScript(1.0f, _actions[0])))
_actions[0]->update(1.0f);
_actions[0]->stop(); _actions[0]->stop();
} }
else if( _last == 0 ) else if( _last == 0 )
{ {
// switching to action 1. stop action 0. // switching to action 1. stop action 0.
_actions[0]->update(1.0f); if (!(sendUpdateEventToScript(1.0f, _actions[0])))
_actions[0]->update(1.0f);
_actions[0]->stop(); _actions[0]->stop();
} }
} }
@ -339,7 +358,8 @@ void Sequence::update(float t)
// FIXME: Bug. this case doesn't contemplate when _last==-1, found=0 and in "reverse mode" // FIXME: Bug. this case doesn't contemplate when _last==-1, found=0 and in "reverse mode"
// since it will require a hack to know if an action is on reverse mode or not. // since it will require a hack to know if an action is on reverse mode or not.
// "step" should be overriden, and the "reverseMode" value propagated to inner Sequences. // "step" should be overriden, and the "reverseMode" value propagated to inner Sequences.
_actions[1]->update(0); if (!(sendUpdateEventToScript(0, _actions[1])))
_actions[1]->update(0);
_actions[1]->stop(); _actions[1]->stop();
} }
// Last action found and it is done. // Last action found and it is done.
@ -353,8 +373,8 @@ void Sequence::update(float t)
{ {
_actions[found]->startWithTarget(_target); _actions[found]->startWithTarget(_target);
} }
if (!(sendUpdateEventToScript(new_t, _actions[found])))
_actions[found]->update(new_t); _actions[found]->update(new_t);
_last = found; _last = found;
} }
@ -436,8 +456,8 @@ void Repeat::update(float dt)
{ {
while (dt > _nextDt && _total < _times) while (dt > _nextDt && _total < _times)
{ {
if (!(sendUpdateEventToScript(1.0f, _innerAction)))
_innerAction->update(1.0f); _innerAction->update(1.0f);
_total++; _total++;
_innerAction->stop(); _innerAction->stop();
@ -456,19 +476,22 @@ void Repeat::update(float dt)
{ {
if (_total == _times) if (_total == _times)
{ {
_innerAction->update(1); if (!(sendUpdateEventToScript(1, _innerAction)))
_innerAction->update(1);
_innerAction->stop(); _innerAction->stop();
} }
else else
{ {
// issue #390 prevent jerk, use right update // issue #390 prevent jerk, use right update
_innerAction->update(dt - (_nextDt - _innerAction->getDuration()/_duration)); if (!(sendUpdateEventToScript(dt - (_nextDt - _innerAction->getDuration()/_duration), _innerAction)))
_innerAction->update(dt - (_nextDt - _innerAction->getDuration()/_duration));
} }
} }
} }
else else
{ {
_innerAction->update(fmodf(dt * _times,1.0f)); if (!(sendUpdateEventToScript(fmodf(dt * _times,1.0f), _innerAction)))
_innerAction->update(fmodf(dt * _times,1.0f));
} }
} }
@ -710,11 +733,13 @@ void Spawn::update(float time)
{ {
if (_one) if (_one)
{ {
_one->update(time); if (!(sendUpdateEventToScript(time, _one)))
_one->update(time);
} }
if (_two) if (_two)
{ {
_two->update(time); if (!(sendUpdateEventToScript(time, _two)))
_two->update(time);
} }
} }
@ -2241,7 +2266,8 @@ void ReverseTime::update(float time)
{ {
if (_other) if (_other)
{ {
_other->update(1 - time); if (!(sendUpdateEventToScript(1 - time, _other)))
_other->update(1 - time);
} }
} }
@ -2502,7 +2528,8 @@ void TargetedAction::stop()
void TargetedAction::update(float time) void TargetedAction::update(float time)
{ {
_action->update(time); if (!(sendUpdateEventToScript(time, _action)))
_action->update(time);
} }
bool TargetedAction::isDone(void) const bool TargetedAction::isDone(void) const

View File

@ -112,6 +112,9 @@ CC_CONSTRUCTOR_ACCESS:
protected: protected:
float _elapsed; float _elapsed;
bool _firstTick; bool _firstTick;
protected:
bool sendUpdateEventToScript(float dt, Action *actionObject);
}; };
/** @class Sequence /** @class Sequence

View File

@ -49,6 +49,22 @@ public:
* @lua NA * @lua NA
*/ */
virtual ~ComponentContainer(void); virtual ~ComponentContainer(void);
template<typename T>
T* getComponent() const
{
if (_components)
{
for (const auto &iter : *_components)
{
if (dynamic_cast<T*>(iter.second) != nullptr)
return static_cast<T*>(iter.second);
}
}
return nullptr;
}
/** /**
* @js getComponent * @js getComponent
*/ */

View File

@ -63,7 +63,7 @@ public:
@param gridSize the size of the grid. @param gridSize the size of the grid.
@param texture The texture used for grab. @param texture The texture used for grab.
@param flipped whether or not the grab texture should be flip by Y or not. @param flipped whether or not the grab texture should be flip by Y or not.
@param rect The effct grid rect. @param rect The effective grid rect.
*/ */
bool initWithSize(const Size& gridSize); bool initWithSize(const Size& gridSize);
bool initWithSize(const Size& gridSize, const Rect& rect); bool initWithSize(const Size& gridSize, const Rect& rect);
@ -155,7 +155,7 @@ class CC_DLL Grid3D : public GridBase
public: public:
/** create one Grid. */ /** create one Grid. */
static Grid3D* create(const Size& gridSize); static Grid3D* create(const Size& gridSize);
/** craete one Grid. */ /** create one Grid. */
static Grid3D* create(const Size& gridSize, const Rect& rect); static Grid3D* create(const Size& gridSize, const Rect& rect);
/** create one Grid. */ /** create one Grid. */
static Grid3D* create(const Size& gridSize, Texture2D *texture, bool flipped); static Grid3D* create(const Size& gridSize, Texture2D *texture, bool flipped);
@ -197,7 +197,7 @@ public:
*/ */
void setVertex(const Vec2& pos, const Vec3& vertex); void setVertex(const Vec2& pos, const Vec3& vertex);
/**@{ /**@{
Implementations for interfaces in base calss. Implementations for interfaces in base class.
*/ */
virtual void beforeBlit() override; virtual void beforeBlit() override;
virtual void afterBlit() override; virtual void afterBlit() override;
@ -275,7 +275,7 @@ public:
void setTile(const Vec2& pos, const Quad3& coords); void setTile(const Vec2& pos, const Quad3& coords);
/**@{ /**@{
Implementations for interfaces in base calss. Implementations for interfaces in base class.
*/ */
virtual void blit() override; virtual void blit() override;
virtual void reuse() override; virtual void reuse() override;

View File

@ -44,10 +44,6 @@ THE SOFTWARE.
#include "deprecated/CCString.h" #include "deprecated/CCString.h"
#if CC_USE_PHYSICS
#include "physics/CCPhysicsBody.h"
#endif
NS_CC_BEGIN NS_CC_BEGIN
// Layer // Layer

View File

@ -84,7 +84,7 @@ public:
*/ */
/** Callback function for touch began. /** Callback function for touch began.
* *
* @param touch Touch infomation. * @param touch Touch information.
* @param unused_event Event information. * @param unused_event Event information.
* @return if return false, onTouchMoved, onTouchEnded, onTouchCancelled will never called. * @return if return false, onTouchMoved, onTouchEnded, onTouchCancelled will never called.
* @js NA * @js NA
@ -92,21 +92,21 @@ public:
virtual bool onTouchBegan(Touch *touch, Event *unused_event); virtual bool onTouchBegan(Touch *touch, Event *unused_event);
/** Callback function for touch moved. /** Callback function for touch moved.
* *
* @param touch Touch infomation. * @param touch Touch information.
* @param unused_event Event information. * @param unused_event Event information.
* @js NA * @js NA
*/ */
virtual void onTouchMoved(Touch *touch, Event *unused_event); virtual void onTouchMoved(Touch *touch, Event *unused_event);
/** Callback function for touch ended. /** Callback function for touch ended.
* *
* @param touch Touch infomation. * @param touch Touch information.
* @param unused_event Event information. * @param unused_event Event information.
* @js NA * @js NA
*/ */
virtual void onTouchEnded(Touch *touch, Event *unused_event); virtual void onTouchEnded(Touch *touch, Event *unused_event);
/** Callback function for touch cancelled. /** Callback function for touch cancelled.
* *
* @param touch Touch infomation. * @param touch Touch information.
* @param unused_event Event information. * @param unused_event Event information.
* @js NA * @js NA
*/ */
@ -149,7 +149,7 @@ public:
/* Callback function should not be deprecated, it will generate lots of warnings. /* Callback function should not be deprecated, it will generate lots of warnings.
Since 'setAccelerometerEnabled' was deprecated, it will make warnings if developer overrides onAcceleration and invokes setAccelerometerEnabled(true) instead of using EventDispatcher::addEventListenerWithXXX. Since 'setAccelerometerEnabled' was deprecated, it will make warnings if developer overrides onAcceleration and invokes setAccelerometerEnabled(true) instead of using EventDispatcher::addEventListenerWithXXX.
*/ */
/** Callback funtion for acceleration. /** Callback function for acceleration.
* @param acc Acceleration information. * @param acc Acceleration information.
* @param unused_event Event information. * @param unused_event Event information.
* @js NA * @js NA
@ -297,19 +297,19 @@ public:
// //
virtual GLubyte getOpacity() const override { return Layer::getOpacity(); } virtual GLubyte getOpacity() const override { return Layer::getOpacity(); }
virtual GLubyte getDisplayedOpacity() const override { return Layer::getDisplayedOpacity(); } virtual GLubyte getDisplayedOpacity() const override { return Layer::getDisplayedOpacity(); }
virtual void setOpacity(GLubyte opacity) override { return Layer::setOpacity(opacity); } virtual void setOpacity(GLubyte opacity) override { Layer::setOpacity(opacity); }
virtual void updateDisplayedOpacity(GLubyte parentOpacity) override { return Layer::updateDisplayedOpacity(parentOpacity); } virtual void updateDisplayedOpacity(GLubyte parentOpacity) override { Layer::updateDisplayedOpacity(parentOpacity); }
virtual bool isCascadeOpacityEnabled() const override { return Layer::isCascadeOpacityEnabled(); } virtual bool isCascadeOpacityEnabled() const override { return Layer::isCascadeOpacityEnabled(); }
virtual void setCascadeOpacityEnabled(bool cascadeOpacityEnabled) override { return Layer::setCascadeOpacityEnabled(cascadeOpacityEnabled); } virtual void setCascadeOpacityEnabled(bool cascadeOpacityEnabled) override { Layer::setCascadeOpacityEnabled(cascadeOpacityEnabled); }
virtual const Color3B& getColor() const override { return Layer::getColor(); } virtual const Color3B& getColor() const override { return Layer::getColor(); }
virtual const Color3B& getDisplayedColor() const override { return Layer::getDisplayedColor(); } virtual const Color3B& getDisplayedColor() const override { return Layer::getDisplayedColor(); }
virtual void setColor(const Color3B& color) override { return Layer::setColor(color); } virtual void setColor(const Color3B& color) override { Layer::setColor(color); }
virtual void updateDisplayedColor(const Color3B& parentColor) override { return Layer::updateDisplayedColor(parentColor); } virtual void updateDisplayedColor(const Color3B& parentColor) override { Layer::updateDisplayedColor(parentColor); }
virtual bool isCascadeColorEnabled() const override { return Layer::isCascadeOpacityEnabled(); } virtual bool isCascadeColorEnabled() const override { return Layer::isCascadeOpacityEnabled(); }
virtual void setCascadeColorEnabled(bool cascadeColorEnabled) override { return Layer::setCascadeColorEnabled(cascadeColorEnabled); } virtual void setCascadeColorEnabled(bool cascadeColorEnabled) override { Layer::setCascadeColorEnabled(cascadeColorEnabled); }
virtual void setOpacityModifyRGB(bool bValue) override { return Layer::setOpacityModifyRGB(bValue); } virtual void setOpacityModifyRGB(bool bValue) override { Layer::setOpacityModifyRGB(bValue); }
virtual bool isOpacityModifyRGB() const override { return Layer::isOpacityModifyRGB(); } virtual bool isOpacityModifyRGB() const override { return Layer::isOpacityModifyRGB(); }
CC_CONSTRUCTOR_ACCESS: CC_CONSTRUCTOR_ACCESS:

View File

@ -41,19 +41,12 @@ THE SOFTWARE.
#include "2d/CCActionManager.h" #include "2d/CCActionManager.h"
#include "2d/CCScene.h" #include "2d/CCScene.h"
#include "2d/CCComponent.h" #include "2d/CCComponent.h"
#include "2d/CCComponentContainer.h"
#include "renderer/CCGLProgram.h" #include "renderer/CCGLProgram.h"
#include "renderer/CCGLProgramState.h" #include "renderer/CCGLProgramState.h"
#include "renderer/CCMaterial.h" #include "renderer/CCMaterial.h"
#include "math/TransformUtils.h" #include "math/TransformUtils.h"
#include "deprecated/CCString.h" #include "deprecated/CCString.h"
#if CC_USE_PHYSICS
#include "physics/CCPhysicsBody.h"
#include "physics/CCPhysicsWorld.h"
#endif
#if CC_NODE_RENDER_SUBPIXEL #if CC_NODE_RENDER_SUBPIXEL
#define RENDER_IN_SUBPIXEL #define RENDER_IN_SUBPIXEL
@ -118,17 +111,6 @@ Node::Node(void)
, _updateScriptHandler(0) , _updateScriptHandler(0)
#endif #endif
, _componentContainer(nullptr) , _componentContainer(nullptr)
#if CC_USE_PHYSICS
, _physicsBody(nullptr)
, _physicsScaleStartX(1.0f)
, _physicsScaleStartY(1.0f)
, _physicsRotation(0.0f)
, _physicsTransformDirty(true)
, _updateTransformFromPhysics(true)
, _physicsWorld(nullptr)
, _physicsBodyAssociatedWith(0)
, _physicsRotationOffset(0.0f)
#endif
, _displayedOpacity(255) , _displayedOpacity(255)
, _realOpacity(255) , _realOpacity(255)
, _displayedColor(Color3B::WHITE) , _displayedColor(Color3B::WHITE)
@ -194,11 +176,6 @@ Node::~Node()
CC_SAFE_DELETE(_componentContainer); CC_SAFE_DELETE(_componentContainer);
#if CC_USE_PHYSICS
setPhysicsBody(nullptr);
#endif
stopAllActions(); stopAllActions();
unscheduleAllCallbacks(); unscheduleAllCallbacks();
CC_SAFE_RELEASE_NULL(_actionManager); CC_SAFE_RELEASE_NULL(_actionManager);
@ -259,13 +236,6 @@ void Node::setSkewX(float skewX)
if (_skewX == skewX) if (_skewX == skewX)
return; return;
#if CC_USE_PHYSICS
if (_physicsBody != nullptr)
{
CCLOG("Node WARNING: PhysicsBody doesn't support setSkewX");
}
#endif
_skewX = skewX; _skewX = skewX;
_transformUpdated = _transformDirty = _inverseDirty = true; _transformUpdated = _transformDirty = _inverseDirty = true;
} }
@ -280,13 +250,6 @@ void Node::setSkewY(float skewY)
if (_skewY == skewY) if (_skewY == skewY)
return; return;
#if CC_USE_PHYSICS
if (_physicsBody != nullptr)
{
CCLOG("Node WARNING: PhysicsBody doesn't support setSkewY");
}
#endif
_skewY = skewY; _skewY = skewY;
_transformUpdated = _transformDirty = _inverseDirty = true; _transformUpdated = _transformDirty = _inverseDirty = true;
} }
@ -336,12 +299,6 @@ void Node::setRotation(float rotation)
_rotationZ_X = _rotationZ_Y = rotation; _rotationZ_X = _rotationZ_Y = rotation;
_transformUpdated = _transformDirty = _inverseDirty = true; _transformUpdated = _transformDirty = _inverseDirty = true;
#if CC_USE_PHYSICS
if (_physicsWorld && _physicsBodyAssociatedWith > 0)
{
_physicsWorld->_updateBodyTransform = true;
}
#endif
updateRotationQuat(); updateRotationQuat();
} }
@ -367,13 +324,6 @@ void Node::setRotation3D(const Vec3& rotation)
_rotationZ_Y = _rotationZ_X = rotation.z; _rotationZ_Y = _rotationZ_X = rotation.z;
updateRotationQuat(); updateRotationQuat();
#if CC_USE_PHYSICS
if (_physicsBody != nullptr)
{
CCLOG("Node WARNING: PhysicsBody doesn't support setRotation3D");
}
#endif
} }
Vec3 Node::getRotation3D() const Vec3 Node::getRotation3D() const
@ -429,13 +379,6 @@ void Node::setRotationSkewX(float rotationX)
if (_rotationZ_X == rotationX) if (_rotationZ_X == rotationX)
return; return;
#if CC_USE_PHYSICS
if (_physicsBody != nullptr)
{
CCLOG("Node WARNING: PhysicsBody doesn't support setRotationSkewX");
}
#endif
_rotationZ_X = rotationX; _rotationZ_X = rotationX;
_transformUpdated = _transformDirty = _inverseDirty = true; _transformUpdated = _transformDirty = _inverseDirty = true;
@ -452,13 +395,6 @@ void Node::setRotationSkewY(float rotationY)
if (_rotationZ_Y == rotationY) if (_rotationZ_Y == rotationY)
return; return;
#if CC_USE_PHYSICS
if (_physicsBody != nullptr)
{
CCLOG("Node WARNING: PhysicsBody doesn't support setRotationSkewY");
}
#endif
_rotationZ_Y = rotationY; _rotationZ_Y = rotationY;
_transformUpdated = _transformDirty = _inverseDirty = true; _transformUpdated = _transformDirty = _inverseDirty = true;
@ -480,12 +416,6 @@ void Node::setScale(float scale)
_scaleX = _scaleY = _scaleZ = scale; _scaleX = _scaleY = _scaleZ = scale;
_transformUpdated = _transformDirty = _inverseDirty = true; _transformUpdated = _transformDirty = _inverseDirty = true;
#if CC_USE_PHYSICS
if (_physicsWorld && _physicsBodyAssociatedWith > 0)
{
_physicsWorld->_updateBodyTransform = true;
}
#endif
} }
/// scaleX getter /// scaleX getter
@ -503,12 +433,6 @@ void Node::setScale(float scaleX,float scaleY)
_scaleX = scaleX; _scaleX = scaleX;
_scaleY = scaleY; _scaleY = scaleY;
_transformUpdated = _transformDirty = _inverseDirty = true; _transformUpdated = _transformDirty = _inverseDirty = true;
#if CC_USE_PHYSICS
if (_physicsWorld && _physicsBodyAssociatedWith > 0)
{
_physicsWorld->_updateBodyTransform = true;
}
#endif
} }
/// scaleX setter /// scaleX setter
@ -519,12 +443,6 @@ void Node::setScaleX(float scaleX)
_scaleX = scaleX; _scaleX = scaleX;
_transformUpdated = _transformDirty = _inverseDirty = true; _transformUpdated = _transformDirty = _inverseDirty = true;
#if CC_USE_PHYSICS
if (_physicsWorld && _physicsBodyAssociatedWith > 0)
{
_physicsWorld->_updateBodyTransform = true;
}
#endif
} }
/// scaleY getter /// scaleY getter
@ -539,13 +457,6 @@ void Node::setScaleZ(float scaleZ)
if (_scaleZ == scaleZ) if (_scaleZ == scaleZ)
return; return;
#if CC_USE_PHYSICS
if (_physicsBody != nullptr)
{
CCLOG("Node WARNING: PhysicsBody doesn't support setScaleZ");
}
#endif
_scaleZ = scaleZ; _scaleZ = scaleZ;
_transformUpdated = _transformDirty = _inverseDirty = true; _transformUpdated = _transformDirty = _inverseDirty = true;
} }
@ -564,12 +475,6 @@ void Node::setScaleY(float scaleY)
_scaleY = scaleY; _scaleY = scaleY;
_transformUpdated = _transformDirty = _inverseDirty = true; _transformUpdated = _transformDirty = _inverseDirty = true;
#if CC_USE_PHYSICS
if (_physicsWorld && _physicsBodyAssociatedWith > 0)
{
_physicsWorld->_updateBodyTransform = true;
}
#endif
} }
@ -601,12 +506,6 @@ void Node::setPosition(float x, float y)
_transformUpdated = _transformDirty = _inverseDirty = true; _transformUpdated = _transformDirty = _inverseDirty = true;
_usingNormalizedPosition = false; _usingNormalizedPosition = false;
#if CC_USE_PHYSICS
if (_physicsWorld && _physicsBodyAssociatedWith > 0)
{
_physicsWorld->_updateBodyTransform = true;
}
#endif
} }
void Node::setPosition3D(const Vec3& position) void Node::setPosition3D(const Vec3& position)
@ -671,12 +570,6 @@ void Node::setNormalizedPosition(const Vec2& position)
_usingNormalizedPosition = true; _usingNormalizedPosition = true;
_normalizedPositionDirty = true; _normalizedPositionDirty = true;
_transformUpdated = _transformDirty = _inverseDirty = true; _transformUpdated = _transformDirty = _inverseDirty = true;
#if CC_USE_PHYSICS
if (_physicsWorld && _physicsBodyAssociatedWith > 0)
{
_physicsWorld->_updateBodyTransform = true;
}
#endif
} }
ssize_t Node::getChildrenCount() const ssize_t Node::getChildrenCount() const
@ -1059,24 +952,6 @@ void Node::addChildHelper(Node* child, int localZOrder, int tag, const std::stri
child->setParent(this); child->setParent(this);
child->setOrderOfArrival(s_globalOrderOfArrival++); child->setOrderOfArrival(s_globalOrderOfArrival++);
#if CC_USE_PHYSICS
_physicsBodyAssociatedWith += child->_physicsBodyAssociatedWith;
auto parentNode = this;
while (parentNode->_parent)
{
parentNode = parentNode->_parent;
parentNode->_physicsBodyAssociatedWith += child->_physicsBodyAssociatedWith;
}
auto scene = dynamic_cast<Scene*>(parentNode);
// Recursive add children with which have physics body.
if (scene && scene->getPhysicsWorld())
{
scene->addChildToPhysicsWorld(child);
}
#endif
if( _running ) if( _running )
{ {
child->onEnter(); child->onEnter();
@ -1177,21 +1052,6 @@ void Node::removeAllChildren()
this->removeAllChildrenWithCleanup(true); this->removeAllChildrenWithCleanup(true);
} }
#if CC_USE_PHYSICS
void Node::removeFromPhysicsWorld()
{
if (_physicsBody != nullptr)
{
_physicsBody->removeFromWorld();
}
for (auto child : _children)
{
child->removeFromPhysicsWorld();
}
}
#endif
void Node::removeAllChildrenWithCleanup(bool cleanup) void Node::removeAllChildrenWithCleanup(bool cleanup)
{ {
// not using detachChild improves speed here // not using detachChild improves speed here
@ -1206,10 +1066,6 @@ void Node::removeAllChildrenWithCleanup(bool cleanup)
child->onExit(); child->onExit();
} }
#if CC_USE_PHYSICS
child->removeFromPhysicsWorld();
#endif
if (cleanup) if (cleanup)
{ {
child->cleanup(); child->cleanup();
@ -1232,10 +1088,6 @@ void Node::detachChild(Node *child, ssize_t childIndex, bool doCleanup)
child->onExit(); child->onExit();
} }
#if CC_USE_PHYSICS
child->removeFromPhysicsWorld();
#endif
// If you don't do cleanup, the child's actions will not get removed and the // If you don't do cleanup, the child's actions will not get removed and the
// its scheduledSelectors_ dict will not get released! // its scheduledSelectors_ dict will not get released!
if (doCleanup) if (doCleanup)
@ -1297,12 +1149,6 @@ void Node::visit()
uint32_t Node::processParentFlags(const Mat4& parentTransform, uint32_t parentFlags) uint32_t Node::processParentFlags(const Mat4& parentTransform, uint32_t parentFlags)
{ {
#if CC_USE_PHYSICS
if (_physicsBody && _updateTransformFromPhysics)
{
updateTransformFromPhysics(parentTransform, parentFlags);
}
#endif
if(_usingNormalizedPosition) if(_usingNormalizedPosition)
{ {
CCASSERT(_parent, "setNormalizedPosition() doesn't work with orphan nodes"); CCASSERT(_parent, "setNormalizedPosition() doesn't work with orphan nodes");
@ -1330,15 +1176,8 @@ uint32_t Node::processParentFlags(const Mat4& parentTransform, uint32_t parentFl
if(flags & FLAGS_DIRTY_MASK) if(flags & FLAGS_DIRTY_MASK)
_modelViewTransform = this->transform(parentTransform); _modelViewTransform = this->transform(parentTransform);
#if CC_USE_PHYSICS
if (_updateTransformFromPhysics) {
_transformUpdated = false;
_contentSizeDirty = false;
}
#else
_transformUpdated = false; _transformUpdated = false;
_contentSizeDirty = false; _contentSizeDirty = false;
#endif
return flags; return flags;
} }
@ -1813,7 +1652,7 @@ const Mat4& Node::getNodeToParentTransform() const
Vec2 anchorPoint(_anchorPointInPoints.x * _scaleX, _anchorPointInPoints.y * _scaleY); Vec2 anchorPoint(_anchorPointInPoints.x * _scaleX, _anchorPointInPoints.y * _scaleY);
// caculate real position // calculate real position
if (! needsSkewMatrix && !_anchorPointInPoints.isZero()) if (! needsSkewMatrix && !_anchorPointInPoints.isZero())
{ {
x += -anchorPoint.x; x += -anchorPoint.x;
@ -2065,120 +1904,6 @@ void Node::removeAllComponents()
_componentContainer->removeAll(); _componentContainer->removeAll();
} }
#if CC_USE_PHYSICS
// MARK: Physics
void Node::setPhysicsBody(PhysicsBody* body)
{
if (_physicsBody == body)
{
return;
}
if (_physicsBody)
{
_physicsBody->removeFromWorld();
_physicsBody->_node = nullptr;
_physicsBody->release();
_physicsBody = nullptr;
_physicsBodyAssociatedWith--;
auto parentNode = this;
while (parentNode->_parent)
{
parentNode = parentNode->_parent;
parentNode->_physicsBodyAssociatedWith--;
}
}
if (body)
{
if (body->getNode())
{
body->getNode()->setPhysicsBody(nullptr);
}
body->_node = this;
body->retain();
_physicsBody = body;
_physicsScaleStartX = _scaleX;
_physicsScaleStartY = _scaleY;
_physicsRotationOffset = _rotationZ_X;
_physicsBodyAssociatedWith++;
auto parentNode = this;
while (parentNode->_parent)
{
parentNode = parentNode->_parent;
parentNode->_physicsBodyAssociatedWith++;
}
auto scene = dynamic_cast<Scene*>(parentNode);
if (scene && scene->getPhysicsWorld())
{
_physicsTransformDirty = true;
scene->getPhysicsWorld()->addBody(body);
}
}
}
void Node::updatePhysicsBodyTransform(const Mat4& parentTransform, uint32_t parentFlags, float parentScaleX, float parentScaleY)
{
_updateTransformFromPhysics = false;
auto flags = processParentFlags(parentTransform, parentFlags);
_updateTransformFromPhysics = true;
auto scaleX = parentScaleX * _scaleX;
auto scaleY = parentScaleY * _scaleY;
if (_parent)
{
_physicsRotation = _parent->_physicsRotation + _rotationZ_X;
}
if (_physicsBody && ((flags & FLAGS_DIRTY_MASK) || _physicsTransformDirty))
{
_physicsTransformDirty = false;
Vec3 vec3(_contentSize.width * 0.5f, _contentSize.height * 0.5f, 0);
Vec3 ret;
_modelViewTransform.transformPoint(vec3, &ret);
_physicsBody->setPosition(Vec2(ret.x, ret.y));
parentTransform.getInversed().transformPoint(&ret);
_offsetX = ret.x - _position.x;
_offsetY = ret.y - _position.y;
_physicsBody->setScale(scaleX / _physicsScaleStartX, scaleY / _physicsScaleStartY);
_physicsBody->setRotation(_physicsRotation - _physicsRotationOffset);
}
for (auto node : _children)
{
node->updatePhysicsBodyTransform(_modelViewTransform, flags, scaleX, scaleY);
}
}
void Node::updateTransformFromPhysics(const Mat4& parentTransform, uint32_t parentFlags)
{
auto& newPosition = _physicsBody->getPosition();
auto& recordedPosition = _physicsBody->_recordedPosition;
auto updateBodyTransform = _physicsWorld->_updateBodyTransform;
if (parentFlags || recordedPosition.x != newPosition.x || recordedPosition.y != newPosition.y)
{
recordedPosition = newPosition;
Vec3 vec3(newPosition.x, newPosition.y, 0);
Vec3 ret;
parentTransform.getInversed().transformPoint(vec3, &ret);
setPosition(ret.x - _offsetX, ret.y - _offsetY);
}
_physicsRotation = _physicsBody->getRotation();
setRotation(_physicsRotation - _parent->_physicsRotation + _physicsRotationOffset);
_physicsWorld->_updateBodyTransform = updateBodyTransform;
}
#endif //CC_USE_PHYSICS
// MARK: Opacity and Color // MARK: Opacity and Color
GLubyte Node::getOpacity(void) const GLubyte Node::getOpacity(void) const

View File

@ -35,6 +35,7 @@
#include "base/CCScriptSupport.h" #include "base/CCScriptSupport.h"
#include "math/CCAffineTransform.h" #include "math/CCAffineTransform.h"
#include "math/CCMath.h" #include "math/CCMath.h"
#include "2d/CCComponentContainer.h"
NS_CC_BEGIN NS_CC_BEGIN
@ -53,10 +54,6 @@ class Director;
class GLProgram; class GLProgram;
class GLProgramState; class GLProgramState;
class Material; class Material;
#if CC_USE_PHYSICS
class PhysicsBody;
class PhysicsWorld;
#endif
class Camera; class Camera;
/** /**
@ -1560,7 +1557,6 @@ public:
virtual Mat4 getWorldToNodeTransform() const; virtual Mat4 getWorldToNodeTransform() const;
virtual AffineTransform getWorldToNodeAffineTransform() const; virtual AffineTransform getWorldToNodeAffineTransform() const;
/** @deprecated Use getWorldToNodeTransform() instead */ /** @deprecated Use getWorldToNodeTransform() instead */
CC_DEPRECATED_ATTRIBUTE inline virtual AffineTransform worldToNodeTransform() const { return getWorldToNodeAffineTransform(); } CC_DEPRECATED_ATTRIBUTE inline virtual AffineTransform worldToNodeTransform() const { return getWorldToNodeAffineTransform(); }
@ -1645,6 +1641,22 @@ public:
*/ */
Component* getComponent(const std::string& name); Component* getComponent(const std::string& name);
/**
* Get a component by the type T.
* @lua NA
* @js NA
*
* @return The component that match the type T.
*/
template<typename T>
T* getComponent() const
{
if (_componentContainer)
return _componentContainer->getComponent<T>();
else
return nullptr;
}
/** /**
* Adds a component. * Adds a component.
* *
@ -1674,39 +1686,6 @@ public:
virtual void removeAllComponents(); virtual void removeAllComponents();
/// @} end of component functions /// @} end of component functions
#if CC_USE_PHYSICS
/**
* Set the PhysicsBody that let the sprite effect with physics.
* @note This method will set anchor point to Vec2::ANCHOR_MIDDLE if body not null, and you cann't change anchor point if node has a physics body.
*
* @param body A given physics body.
*/
void setPhysicsBody(PhysicsBody* body);
/**
* Get the PhysicsBody the sprite have.
*
* @return The PhysicsBody the sprite have.
*/
PhysicsBody* getPhysicsBody() const { return _physicsBody; }
/**
* Remove this node from physics world. it will remove all the physics bodies in it's children too.
*/
void removeFromPhysicsWorld();
/**
* Update the transform matrix from physics.
*/
void updateTransformFromPhysics(const Mat4& parentTransform, uint32_t parentFlags);
/**
* Update physics body transform matrix.
*/
virtual void updatePhysicsBodyTransform(const Mat4& parentTransform, uint32_t parentFlags, float parentScaleX, float parentScaleY);
#endif
// overrides // overrides
virtual GLubyte getOpacity() const; virtual GLubyte getOpacity() const;
virtual GLubyte getDisplayedOpacity() const; virtual GLubyte getDisplayedOpacity() const;
@ -1864,22 +1843,6 @@ protected:
ComponentContainer *_componentContainer; ///< Dictionary of components ComponentContainer *_componentContainer; ///< Dictionary of components
#if CC_USE_PHYSICS
PhysicsBody* _physicsBody; ///< the physicsBody the node have
float _physicsScaleStartX; ///< the scale x value when setPhysicsBody
float _physicsScaleStartY; ///< the scale y value when setPhysicsBody
float _physicsRotation;
bool _physicsTransformDirty;
bool _updateTransformFromPhysics;
PhysicsWorld* _physicsWorld; /** The PhysicsWorld associated with the node.*/
int _physicsBodyAssociatedWith; /** The count of PhysicsBody associated with the node and children.*/
float _physicsRotationOffset; /** Record the rotation value when invoke Node::setPhysicsBody.*/
float _offsetX;
float _offsetY;
#endif
// opacity controls // opacity controls
GLubyte _displayedOpacity; GLubyte _displayedOpacity;
GLubyte _realOpacity; GLubyte _realOpacity;
@ -1900,10 +1863,6 @@ protected:
private: private:
CC_DISALLOW_COPY_AND_ASSIGN(Node); CC_DISALLOW_COPY_AND_ASSIGN(Node);
#if CC_USE_PHYSICS
friend class Scene;
#endif //CC_USTPS
}; };

View File

@ -29,10 +29,6 @@
#include "CCProtectedNode.h" #include "CCProtectedNode.h"
#include "base/CCDirector.h" #include "base/CCDirector.h"
#if CC_USE_PHYSICS
#include "physics/CCPhysicsBody.h"
#endif
#include "2d/CCScene.h" #include "2d/CCScene.h"
NS_CC_BEGIN NS_CC_BEGIN
@ -108,19 +104,6 @@ void ProtectedNode::addProtectedChild(Node *child, int zOrder, int tag)
child->setParent(this); child->setParent(this);
child->setOrderOfArrival(s_globalOrderOfArrival++); child->setOrderOfArrival(s_globalOrderOfArrival++);
#if CC_USE_PHYSICS
// Recursive add children with which have physics body.
for (Node* node = this; node != nullptr; node = node->getParent())
{
Scene* scene = dynamic_cast<Scene*>(node);
if (scene != nullptr && scene->getPhysicsWorld() != nullptr)
{
scene->addChildToPhysicsWorld(child);
break;
}
}
#endif
if( _running ) if( _running )
{ {
child->onEnter(); child->onEnter();
@ -178,13 +161,6 @@ void ProtectedNode::removeProtectedChild(cocos2d::Node *child, bool cleanup)
child->onExit(); child->onExit();
} }
#if CC_USE_PHYSICS
if (child->getPhysicsBody() != nullptr)
{
child->getPhysicsBody()->removeFromWorld();
}
#endif
// If you don't do cleanup, the child's actions will not get removed and the // If you don't do cleanup, the child's actions will not get removed and the
// its scheduledSelectors_ dict will not get released! // its scheduledSelectors_ dict will not get released!
if (cleanup) if (cleanup)
@ -218,13 +194,6 @@ void ProtectedNode::removeAllProtectedChildrenWithCleanup(bool cleanup)
child->onExit(); child->onExit();
} }
#if CC_USE_PHYSICS
if (child->getPhysicsBody() != nullptr)
{
child->getPhysicsBody()->removeFromWorld();
}
#endif
if (cleanup) if (cleanup)
{ {
child->cleanup(); child->cleanup();

View File

@ -35,7 +35,7 @@ THE SOFTWARE.
#include "deprecated/CCString.h" #include "deprecated/CCString.h"
#if CC_USE_PHYSICS #if CC_USE_PHYSICS
#include "physics/CCPhysicsWorld.h" #include "physics/CCPhysicsManager.h"
#endif #endif
#if CC_USE_3D_PHYSICS && CC_ENABLE_BULLET_INTEGRATION #if CC_USE_3D_PHYSICS && CC_ENABLE_BULLET_INTEGRATION
@ -50,9 +50,6 @@ THE SOFTWARE.
NS_CC_BEGIN NS_CC_BEGIN
Scene::Scene() Scene::Scene()
#if CC_USE_PHYSICS
: _physicsWorld(nullptr)
#endif
{ {
#if CC_USE_3D_PHYSICS && CC_ENABLE_BULLET_INTEGRATION #if CC_USE_3D_PHYSICS && CC_ENABLE_BULLET_INTEGRATION
_physics3DWorld = nullptr; _physics3DWorld = nullptr;
@ -61,6 +58,9 @@ Scene::Scene()
#if CC_USE_NAVMESH #if CC_USE_NAVMESH
_navMesh = nullptr; _navMesh = nullptr;
_navMeshDebugCamera = nullptr; _navMeshDebugCamera = nullptr;
#endif
#if CC_USE_PHYSICS
_physicsManager = nullptr;
#endif #endif
_ignoreAnchorPointForPosition = true; _ignoreAnchorPointForPosition = true;
setAnchorPoint(Vec2(0.5f, 0.5f)); setAnchorPoint(Vec2(0.5f, 0.5f));
@ -79,9 +79,6 @@ Scene::Scene()
Scene::~Scene() Scene::~Scene()
{ {
#if CC_USE_PHYSICS
CC_SAFE_DELETE(_physicsWorld);
#endif
#if CC_USE_3D_PHYSICS && CC_ENABLE_BULLET_INTEGRATION #if CC_USE_3D_PHYSICS && CC_ENABLE_BULLET_INTEGRATION
CC_SAFE_RELEASE(_physics3DWorld); CC_SAFE_RELEASE(_physics3DWorld);
CC_SAFE_RELEASE(_physics3dDebugCamera); CC_SAFE_RELEASE(_physics3dDebugCamera);
@ -91,6 +88,10 @@ Scene::~Scene()
#endif #endif
Director::getInstance()->getEventDispatcher()->removeEventListener(_event); Director::getInstance()->getEventDispatcher()->removeEventListener(_event);
CC_SAFE_RELEASE(_event); CC_SAFE_RELEASE(_event);
#if CC_USE_PHYSICS
delete _physicsManager;
#endif
} }
#if CC_USE_NAVMESH #if CC_USE_NAVMESH
@ -260,21 +261,6 @@ void Scene::setNavMeshDebugCamera(Camera *camera)
#endif #endif
#if (CC_USE_PHYSICS || (CC_USE_3D_PHYSICS && CC_ENABLE_BULLET_INTEGRATION)) #if (CC_USE_PHYSICS || (CC_USE_3D_PHYSICS && CC_ENABLE_BULLET_INTEGRATION))
void Scene::addChild(Node* child, int zOrder, int tag)
{
Node::addChild(child, zOrder, tag);
#if CC_USE_PHYSICS
addChildToPhysicsWorld(child);
#endif
}
void Scene::addChild(Node* child, int zOrder, const std::string &name)
{
Node::addChild(child, zOrder, name);
#if CC_USE_PHYSICS
addChildToPhysicsWorld(child);
#endif
}
Scene* Scene::createWithPhysics() Scene* Scene::createWithPhysics()
{ {
@ -293,6 +279,9 @@ Scene* Scene::createWithPhysics()
bool Scene::initWithPhysics() bool Scene::initWithPhysics()
{ {
_physicsManager = new (std::nothrow) PhysicsManager(this);
_physicsWorld = _physicsManager->getPhysicsWorld();
bool ret = false; bool ret = false;
do do
{ {
@ -300,9 +289,6 @@ bool Scene::initWithPhysics()
CC_BREAK_IF( ! (director = Director::getInstance()) ); CC_BREAK_IF( ! (director = Director::getInstance()) );
this->setContentSize(director->getWinSize()); this->setContentSize(director->getWinSize());
#if CC_USE_PHYSICS
CC_BREAK_IF(! (_physicsWorld = PhysicsWorld::construct(*this)));
#endif
#if CC_USE_3D_PHYSICS && CC_ENABLE_BULLET_INTEGRATION #if CC_USE_3D_PHYSICS && CC_ENABLE_BULLET_INTEGRATION
Physics3DWorldDes info; Physics3DWorldDes info;
@ -316,43 +302,16 @@ bool Scene::initWithPhysics()
return ret; return ret;
} }
void Scene::addChildToPhysicsWorld(Node* child)
{
#if CC_USE_PHYSICS
if (_physicsWorld)
{
std::function<void(Node*)> addToPhysicsWorldFunc = nullptr;
addToPhysicsWorldFunc = [this, &addToPhysicsWorldFunc](Node* node) -> void
{
node->_physicsWorld = _physicsWorld;
if (node->getPhysicsBody())
{
_physicsWorld->addBody(node->getPhysicsBody());
}
auto& children = node->getChildren();
for( const auto &n : children) {
addToPhysicsWorldFunc(n);
}
};
addToPhysicsWorldFunc(child);
}
#endif
}
#endif #endif
#if (CC_USE_PHYSICS || (CC_USE_3D_PHYSICS && CC_ENABLE_BULLET_INTEGRATION) || CC_USE_NAVMESH) #if (CC_USE_PHYSICS || (CC_USE_3D_PHYSICS && CC_ENABLE_BULLET_INTEGRATION) || CC_USE_NAVMESH)
void Scene::stepPhysicsAndNavigation(float deltaTime) void Scene::stepPhysicsAndNavigation(float deltaTime)
{ {
#if CC_USE_PHYSICS #if CC_USE_PHYSICS
if (_physicsWorld && _physicsWorld->isAutoStep()) if (_physicsManager)
{ _physicsManager->update(deltaTime);
_physicsWorld->update(deltaTime, false);
}
#endif #endif
#if CC_USE_3D_PHYSICS && CC_ENABLE_BULLET_INTEGRATION #if CC_USE_3D_PHYSICS && CC_ENABLE_BULLET_INTEGRATION
if (_physics3DWorld) if (_physics3DWorld)
{ {

View File

@ -40,6 +40,7 @@ class EventListenerCustom;
class EventCustom; class EventCustom;
#if CC_USE_PHYSICS #if CC_USE_PHYSICS
class PhysicsWorld; class PhysicsWorld;
class PhysicsManager;
#endif #endif
#if CC_USE_3D_PHYSICS && CC_ENABLE_BULLET_INTEGRATION #if CC_USE_3D_PHYSICS && CC_ENABLE_BULLET_INTEGRATION
class Physics3DWorld; class Physics3DWorld;
@ -145,15 +146,21 @@ private:
#if (CC_USE_PHYSICS || (CC_USE_3D_PHYSICS && CC_ENABLE_BULLET_INTEGRATION)) #if (CC_USE_PHYSICS || (CC_USE_3D_PHYSICS && CC_ENABLE_BULLET_INTEGRATION))
public: public:
virtual void addChild(Node* child, int zOrder, int tag) override;
virtual void addChild(Node* child, int zOrder, const std::string &name) override;
#if CC_USE_PHYSICS #if CC_USE_PHYSICS
/** Get the physics world of the scene. /** Get the physics world of the scene.
* @return The physics world of the scene. * @return The physics world of the scene.
* @js NA * @js NA
*/ */
inline PhysicsWorld* getPhysicsWorld() { return _physicsWorld; } inline PhysicsWorld* getPhysicsWorld() const { return _physicsWorld; }
/**
* Get the `PhysicsManager` belongs to this `Scene`.
*
* @return PhysicsManager of the scene.
* @js NA
*/
PhysicsManager* getPhysicsManager() const { return _physicsManager; }
#endif #endif
#if CC_USE_3D_PHYSICS && CC_ENABLE_BULLET_INTEGRATION #if CC_USE_3D_PHYSICS && CC_ENABLE_BULLET_INTEGRATION
@ -183,6 +190,7 @@ protected:
#if CC_USE_PHYSICS #if CC_USE_PHYSICS
PhysicsWorld* _physicsWorld; PhysicsWorld* _physicsWorld;
PhysicsManager* _physicsManager;
#endif #endif
#if CC_USE_3D_PHYSICS && CC_ENABLE_BULLET_INTEGRATION #if CC_USE_3D_PHYSICS && CC_ENABLE_BULLET_INTEGRATION
@ -203,8 +211,8 @@ public:
void setNavMeshDebugCamera(Camera *camera); void setNavMeshDebugCamera(Camera *camera);
protected: protected:
NavMesh* _navMesh; NavMesh* _navMesh;
Camera * _navMeshDebugCamera; Camera * _navMeshDebugCamera;
#endif #endif
#if (CC_USE_PHYSICS || (CC_USE_3D_PHYSICS && CC_ENABLE_BULLET_INTEGRATION) || CC_USE_NAVMESH) #if (CC_USE_PHYSICS || (CC_USE_3D_PHYSICS && CC_ENABLE_BULLET_INTEGRATION) || CC_USE_NAVMESH)

View File

@ -1129,7 +1129,7 @@ void Sprite::updateBlendFunc(void)
{ {
CCASSERT(! _batchNode, "CCSprite: updateBlendFunc doesn't work when the sprite is rendered using a SpriteBatchNode"); CCASSERT(! _batchNode, "CCSprite: updateBlendFunc doesn't work when the sprite is rendered using a SpriteBatchNode");
// it is possible to have an untextured spritec // it is possible to have an untextured sprite
if (! _texture || ! _texture->hasPremultipliedAlpha()) if (! _texture || ! _texture->hasPremultipliedAlpha())
{ {
_blendFunc = BlendFunc::ALPHA_NON_PREMULTIPLIED; _blendFunc = BlendFunc::ALPHA_NON_PREMULTIPLIED;

View File

@ -367,13 +367,6 @@ void SpriteBatchNode::draw(Renderer *renderer, const Mat4 &transform, uint32_t f
for (const auto &child : _children) for (const auto &child : _children)
{ {
#if CC_USE_PHYSICS
auto physicsBody = child->getPhysicsBody();
if (physicsBody)
{
child->updateTransformFromPhysics(transform, flags);
}
#endif
child->updateTransform(); child->updateTransform();
} }

View File

@ -131,7 +131,7 @@ void SpriteFrameCache::addSpriteFramesWithDictionary(ValueMap& dictionary, Textu
// check ow/oh // check ow/oh
if(!ow || !oh) if(!ow || !oh)
{ {
CCLOGWARN("cocos2d: WARNING: originalWidth/Height not found on the SpriteFrame. AnchorPoint won't work as expected. Regenrate the .plist"); CCLOGWARN("cocos2d: WARNING: originalWidth/Height not found on the SpriteFrame. AnchorPoint won't work as expected. Regenerate the .plist");
} }
// abs ow/oh // abs ow/oh
ow = abs(ow); ow = abs(ow);

View File

@ -587,9 +587,11 @@ xcopy /Y /Q "$(ProjectDir)..\..\external\chipmunk\prebuilt\win32\release-lib\*.*
<ClCompile Include="..\physics3d\CCPhysics3DShape.cpp" /> <ClCompile Include="..\physics3d\CCPhysics3DShape.cpp" />
<ClCompile Include="..\physics3d\CCPhysics3DWorld.cpp" /> <ClCompile Include="..\physics3d\CCPhysics3DWorld.cpp" />
<ClCompile Include="..\physics3d\CCPhysicsSprite3D.cpp" /> <ClCompile Include="..\physics3d\CCPhysicsSprite3D.cpp" />
<ClCompile Include="..\physics\CCComponentPhysics2d.cpp" />
<ClCompile Include="..\physics\CCPhysicsBody.cpp" /> <ClCompile Include="..\physics\CCPhysicsBody.cpp" />
<ClCompile Include="..\physics\CCPhysicsContact.cpp" /> <ClCompile Include="..\physics\CCPhysicsContact.cpp" />
<ClCompile Include="..\physics\CCPhysicsJoint.cpp" /> <ClCompile Include="..\physics\CCPhysicsJoint.cpp" />
<ClCompile Include="..\physics\CCPhysicsManager.cpp" />
<ClCompile Include="..\physics\CCPhysicsShape.cpp" /> <ClCompile Include="..\physics\CCPhysicsShape.cpp" />
<ClCompile Include="..\physics\CCPhysicsWorld.cpp" /> <ClCompile Include="..\physics\CCPhysicsWorld.cpp" />
<ClCompile Include="..\platform\CCFileUtils.cpp" /> <ClCompile Include="..\platform\CCFileUtils.cpp" />
@ -1195,10 +1197,12 @@ xcopy /Y /Q "$(ProjectDir)..\..\external\chipmunk\prebuilt\win32\release-lib\*.*
<ClInclude Include="..\physics3d\CCPhysics3DShape.h" /> <ClInclude Include="..\physics3d\CCPhysics3DShape.h" />
<ClInclude Include="..\physics3d\CCPhysics3DWorld.h" /> <ClInclude Include="..\physics3d\CCPhysics3DWorld.h" />
<ClInclude Include="..\physics3d\CCPhysicsSprite3D.h" /> <ClInclude Include="..\physics3d\CCPhysicsSprite3D.h" />
<ClInclude Include="..\physics\CCComponentPhysics2d.h" />
<ClInclude Include="..\physics\CCPhysicsBody.h" /> <ClInclude Include="..\physics\CCPhysicsBody.h" />
<ClInclude Include="..\physics\CCPhysicsContact.h" /> <ClInclude Include="..\physics\CCPhysicsContact.h" />
<ClInclude Include="..\physics\CCPhysicsHelper.h" /> <ClInclude Include="..\physics\CCPhysicsHelper.h" />
<ClInclude Include="..\physics\CCPhysicsJoint.h" /> <ClInclude Include="..\physics\CCPhysicsJoint.h" />
<ClInclude Include="..\physics\CCPhysicsManager.h" />
<ClInclude Include="..\physics\CCPhysicsShape.h" /> <ClInclude Include="..\physics\CCPhysicsShape.h" />
<ClInclude Include="..\physics\CCPhysicsWorld.h" /> <ClInclude Include="..\physics\CCPhysicsWorld.h" />
<ClInclude Include="..\platform\CCApplicationProtocol.h" /> <ClInclude Include="..\platform\CCApplicationProtocol.h" />

View File

@ -285,6 +285,9 @@
</Filter> </Filter>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="..\physics\CCComponentPhysics2d.cpp">
<Filter>physics</Filter>
</ClCompile>
<ClCompile Include="..\physics\CCPhysicsBody.cpp"> <ClCompile Include="..\physics\CCPhysicsBody.cpp">
<Filter>physics</Filter> <Filter>physics</Filter>
</ClCompile> </ClCompile>
@ -294,6 +297,9 @@
<ClCompile Include="..\physics\CCPhysicsJoint.cpp"> <ClCompile Include="..\physics\CCPhysicsJoint.cpp">
<Filter>physics</Filter> <Filter>physics</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\physics\CCPhysicsManager.cpp">
<Filter>physics</Filter>
</ClCompile>
<ClCompile Include="..\physics\CCPhysicsShape.cpp"> <ClCompile Include="..\physics\CCPhysicsShape.cpp">
<Filter>physics</Filter> <Filter>physics</Filter>
</ClCompile> </ClCompile>
@ -1936,6 +1942,9 @@
</ClCompile> </ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="..\physics\CCComponentPhysics2d.h">
<Filter>physics</Filter>
</ClInclude>
<ClInclude Include="..\physics\CCPhysicsBody.h"> <ClInclude Include="..\physics\CCPhysicsBody.h">
<Filter>physics</Filter> <Filter>physics</Filter>
</ClInclude> </ClInclude>
@ -1945,6 +1954,9 @@
<ClInclude Include="..\physics\CCPhysicsJoint.h"> <ClInclude Include="..\physics\CCPhysicsJoint.h">
<Filter>physics</Filter> <Filter>physics</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\physics\CCPhysicsManager.h">
<Filter>physics</Filter>
</ClInclude>
<ClInclude Include="..\physics\CCPhysicsShape.h"> <ClInclude Include="..\physics\CCPhysicsShape.h">
<Filter>physics</Filter> <Filter>physics</Filter>
</ClInclude> </ClInclude>

View File

@ -468,10 +468,12 @@
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\physics3d\CCPhysics3DShape.h" /> <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\physics3d\CCPhysics3DShape.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\physics3d\CCPhysics3DWorld.h" /> <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\physics3d\CCPhysics3DWorld.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\physics3d\CCPhysicsSprite3D.h" /> <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\physics3d\CCPhysicsSprite3D.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\physics\CCComponentPhysics2d.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\physics\CCPhysicsBody.h" /> <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\physics\CCPhysicsBody.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\physics\CCPhysicsContact.h" /> <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\physics\CCPhysicsContact.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\physics\CCPhysicsHelper.h" /> <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\physics\CCPhysicsHelper.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\physics\CCPhysicsJoint.h" /> <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\physics\CCPhysicsJoint.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\physics\CCPhysicsManager.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\physics\CCPhysicsShape.h" /> <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\physics\CCPhysicsShape.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\physics\CCPhysicsWorld.h" /> <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\physics\CCPhysicsWorld.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\platform\CCApplication.h" /> <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\platform\CCApplication.h" />
@ -1071,9 +1073,11 @@
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\physics3d\CCPhysics3DShape.cpp" /> <ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\physics3d\CCPhysics3DShape.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\physics3d\CCPhysics3DWorld.cpp" /> <ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\physics3d\CCPhysics3DWorld.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\physics3d\CCPhysicsSprite3D.cpp" /> <ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\physics3d\CCPhysicsSprite3D.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\physics\CCComponentPhysics2d.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\physics\CCPhysicsBody.cpp" /> <ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\physics\CCPhysicsBody.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\physics\CCPhysicsContact.cpp" /> <ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\physics\CCPhysicsContact.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\physics\CCPhysicsJoint.cpp" /> <ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\physics\CCPhysicsJoint.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\physics\CCPhysicsManager.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\physics\CCPhysicsShape.cpp" /> <ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\physics\CCPhysicsShape.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\physics\CCPhysicsWorld.cpp" /> <ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\physics\CCPhysicsWorld.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\platform\CCFileUtils.cpp" /> <ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\platform\CCFileUtils.cpp" />

View File

@ -210,6 +210,12 @@
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\physics\CCPhysicsWorld.h"> <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\physics\CCPhysicsWorld.h">
<Filter>physics</Filter> <Filter>physics</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\physics\CCComponentPhysics2d.h">
<Filter>physics</Filter>
</ClInclude>
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\physics\CCPhysicsManager.h">
<Filter>physics</Filter>
</ClInclude>
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\editor-support\cocostudio\CocosStudioExport.h"> <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\editor-support\cocostudio\CocosStudioExport.h">
<Filter>cocostudio</Filter> <Filter>cocostudio</Filter>
</ClInclude> </ClInclude>
@ -2054,6 +2060,12 @@
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\physics\CCPhysicsWorld.cpp"> <ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\physics\CCPhysicsWorld.cpp">
<Filter>physics</Filter> <Filter>physics</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\physics\CCComponentPhysics2d.cpp">
<Filter>physics</Filter>
</ClCompile>
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\physics\CCPhysicsManager.cpp">
<Filter>physics</Filter>
</ClCompile>
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\editor-support\cocostudio\CCActionFrame.cpp"> <ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\editor-support\cocostudio\CCActionFrame.cpp">
<Filter>cocostudio\action</Filter> <Filter>cocostudio\action</Filter>
</ClCompile> </ClCompile>

View File

@ -565,9 +565,11 @@
<ClCompile Include="..\..\physics3d\CCPhysics3DShape.cpp" /> <ClCompile Include="..\..\physics3d\CCPhysics3DShape.cpp" />
<ClCompile Include="..\..\physics3d\CCPhysics3DWorld.cpp" /> <ClCompile Include="..\..\physics3d\CCPhysics3DWorld.cpp" />
<ClCompile Include="..\..\physics3d\CCPhysicsSprite3D.cpp" /> <ClCompile Include="..\..\physics3d\CCPhysicsSprite3D.cpp" />
<ClCompile Include="..\..\physics\CCComponentPhysics2d.cpp" />
<ClCompile Include="..\..\physics\CCPhysicsBody.cpp" /> <ClCompile Include="..\..\physics\CCPhysicsBody.cpp" />
<ClCompile Include="..\..\physics\CCPhysicsContact.cpp" /> <ClCompile Include="..\..\physics\CCPhysicsContact.cpp" />
<ClCompile Include="..\..\physics\CCPhysicsJoint.cpp" /> <ClCompile Include="..\..\physics\CCPhysicsJoint.cpp" />
<ClCompile Include="..\..\physics\CCPhysicsManager.cpp" />
<ClCompile Include="..\..\physics\CCPhysicsShape.cpp" /> <ClCompile Include="..\..\physics\CCPhysicsShape.cpp" />
<ClCompile Include="..\..\physics\CCPhysicsWorld.cpp" /> <ClCompile Include="..\..\physics\CCPhysicsWorld.cpp" />
<ClCompile Include="..\..\platform\CCFileUtils.cpp" /> <ClCompile Include="..\..\platform\CCFileUtils.cpp" />
@ -1179,10 +1181,12 @@
<ClInclude Include="..\..\physics3d\CCPhysics3DShape.h" /> <ClInclude Include="..\..\physics3d\CCPhysics3DShape.h" />
<ClInclude Include="..\..\physics3d\CCPhysics3DWorld.h" /> <ClInclude Include="..\..\physics3d\CCPhysics3DWorld.h" />
<ClInclude Include="..\..\physics3d\CCPhysicsSprite3D.h" /> <ClInclude Include="..\..\physics3d\CCPhysicsSprite3D.h" />
<ClInclude Include="..\..\physics\CCComponentPhysics2d.h" />
<ClInclude Include="..\..\physics\CCPhysicsBody.h" /> <ClInclude Include="..\..\physics\CCPhysicsBody.h" />
<ClInclude Include="..\..\physics\CCPhysicsContact.h" /> <ClInclude Include="..\..\physics\CCPhysicsContact.h" />
<ClInclude Include="..\..\physics\CCPhysicsHelper.h" /> <ClInclude Include="..\..\physics\CCPhysicsHelper.h" />
<ClInclude Include="..\..\physics\CCPhysicsJoint.h" /> <ClInclude Include="..\..\physics\CCPhysicsJoint.h" />
<ClInclude Include="..\..\physics\CCPhysicsManager.h" />
<ClInclude Include="..\..\physics\CCPhysicsShape.h" /> <ClInclude Include="..\..\physics\CCPhysicsShape.h" />
<ClInclude Include="..\..\physics\CCPhysicsWorld.h" /> <ClInclude Include="..\..\physics\CCPhysicsWorld.h" />
<ClInclude Include="..\..\platform\CCApplication.h" /> <ClInclude Include="..\..\platform\CCApplication.h" />

View File

@ -1578,6 +1578,9 @@
<ClCompile Include="..\..\network\WebSocket.cpp"> <ClCompile Include="..\..\network\WebSocket.cpp">
<Filter>network</Filter> <Filter>network</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\physics\CCComponentPhysics2d.cpp">
<Filter>physics</Filter>
</ClCompile>
<ClCompile Include="..\..\physics\CCPhysicsBody.cpp"> <ClCompile Include="..\..\physics\CCPhysicsBody.cpp">
<Filter>physics</Filter> <Filter>physics</Filter>
</ClCompile> </ClCompile>
@ -1587,6 +1590,9 @@
<ClCompile Include="..\..\physics\CCPhysicsJoint.cpp"> <ClCompile Include="..\..\physics\CCPhysicsJoint.cpp">
<Filter>physics</Filter> <Filter>physics</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\physics\CCPhysicsManager.cpp">
<Filter>physics</Filter>
</ClCompile>
<ClCompile Include="..\..\physics\CCPhysicsShape.cpp"> <ClCompile Include="..\..\physics\CCPhysicsShape.cpp">
<Filter>physics</Filter> <Filter>physics</Filter>
</ClCompile> </ClCompile>
@ -3389,6 +3395,9 @@
<ClInclude Include="..\..\network\WebSocket.h"> <ClInclude Include="..\..\network\WebSocket.h">
<Filter>network</Filter> <Filter>network</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\..\physics\CCComponentPhysics2d.h">
<Filter>physics</Filter>
</ClInclude>
<ClInclude Include="..\..\physics\CCPhysicsBody.h"> <ClInclude Include="..\..\physics\CCPhysicsBody.h">
<Filter>physics</Filter> <Filter>physics</Filter>
</ClInclude> </ClInclude>
@ -3401,6 +3410,9 @@
<ClInclude Include="..\..\physics\CCPhysicsJoint.h"> <ClInclude Include="..\..\physics\CCPhysicsJoint.h">
<Filter>physics</Filter> <Filter>physics</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\..\physics\CCPhysicsManager.h">
<Filter>physics</Filter>
</ClInclude>
<ClInclude Include="..\..\physics\CCPhysicsShape.h"> <ClInclude Include="..\..\physics\CCPhysicsShape.h">
<Filter>physics</Filter> <Filter>physics</Filter>
</ClInclude> </ClInclude>

View File

@ -36,7 +36,7 @@ NS_CC_BEGIN
*/ */
/** /**
* Axis Aligned Bounding Box (AABB), usually caculate some rough but fast collision detection. * Axis Aligned Bounding Box (AABB), usually calculate some rough but fast collision detection.
*/ */
class CC_DLL AABB class CC_DLL AABB
{ {

View File

@ -224,7 +224,7 @@ void Animate3D::startWithTarget(Node *target)
if (!hasCurve) if (!hasCurve)
{ {
CCLOG("warning: no animation finde for the skeleton"); CCLOG("warning: no animation found for the skeleton");
} }
} }

View File

@ -41,7 +41,7 @@ class EventCustom;
enum class Animate3DQuality enum class Animate3DQuality
{ {
QUALITY_NONE = 0, // it'll be ignore the curve-evaluating(the animation looks like stop), just acculate transition time. QUALITY_NONE = 0, // it'll be ignore the curve-evaluating(the animation looks like stop), just accumulate transition time.
QUALITY_LOW, // low animation quality, it'll be more efficient. QUALITY_LOW, // low animation quality, it'll be more efficient.
QUALITY_HIGH, // high animation quality. QUALITY_HIGH, // high animation quality.
}; };
@ -161,7 +161,7 @@ protected:
float _last; //last time 0 - 1, used to generate sub Animate3D float _last; //last time 0 - 1, used to generate sub Animate3D
bool _playReverse; // is playing reverse bool _playReverse; // is playing reverse
static float _transTime; //transition time from one animate3d to another static float _transTime; //transition time from one animate3d to another
float _accTransTime; // acculate transition time float _accTransTime; // accumulate transition time
float _lastTime; // last t (0 - 1) float _lastTime; // last t (0 - 1)
float _originInterval;// save origin interval time float _originInterval;// save origin interval time
float _frameRate; float _frameRate;

View File

@ -66,7 +66,7 @@ public:
static AnimationCurve* create(float* keytime, float* value, int count); static AnimationCurve* create(float* keytime, float* value, int count);
/** /**
* evalute value of time * evaluate value of time
* @param time Time to be estimated * @param time Time to be estimated
* @param dst Estimated value of that time * @param dst Estimated value of that time
* @param type EvaluateType * @param type EvaluateType

View File

@ -111,7 +111,7 @@ CC_CONSTRUCTOR_ACCESS:
protected: protected:
/** /**
* calculate a model matrix which keep orignal translate & scaling but always face to the camera * calculate a model matrix which keep original translate & scaling but always face to the camera
*/ */
bool calculateBillbaordTransform(); bool calculateBillbaordTransform();

View File

@ -1261,7 +1261,7 @@ bool Bundle3D::loadSkinDataJson(SkinData* skindata)
skindata->inverseBindPoseMatrices.push_back(mat_bind_pos); skindata->inverseBindPoseMatrices.push_back(mat_bind_pos);
} }
// set root bone infomation // set root bone information
const rapidjson::Value& skin_data_1 = skin_data_array[1]; const rapidjson::Value& skin_data_1 = skin_data_array[1];
// parent and child relationship map // parent and child relationship map
@ -1815,7 +1815,7 @@ NodeData* Bundle3D::parseNodesRecursivelyBinary(bool& skeleton, bool singleSprit
bool skeleton_; bool skeleton_;
if (_binaryReader.read(&skeleton_, 1, 1) != 1) if (_binaryReader.read(&skeleton_, 1, 1) != 1)
{ {
CCLOG("warning: Failed to read is sleleton"); CCLOG("warning: Failed to read is skeleton");
return nullptr; return nullptr;
} }
if (skeleton_) if (skeleton_)

View File

@ -48,12 +48,12 @@ class BundleReader: public cocos2d::Ref
{ {
public: public:
/** /**
* Structor * Constructor
*/ */
BundleReader(); BundleReader();
/** /**
* inicial * Destructor
*/ */
~BundleReader(); ~BundleReader();
@ -163,7 +163,7 @@ inline bool BundleReader::readArray(unsigned int *length, std::vector<T> *values
} }
/** /**
* specalization for char * specialization for char
*/ */
template<> template<>
inline bool BundleReader::read<char>(char *ptr) inline bool BundleReader::read<char>(char *ptr)
@ -180,7 +180,7 @@ inline bool BundleReader::read<char>(char *ptr)
} }
/** /**
* specalization for std::string * specialization for std::string
*/ */
template<> template<>
inline bool BundleReader::read<std::string>(std::string *ptr) inline bool BundleReader::read<std::string>(std::string *ptr)

View File

@ -358,9 +358,9 @@ void Mesh::draw(Renderer* renderer, float globalZOrder, const Mat4& transform, u
flags); flags);
if (isTransparent && !forceDepthWrite) // if (isTransparent && !forceDepthWrite)
_material->getStateBlock()->setDepthWrite(false); // _material->getStateBlock()->setDepthWrite(false);
else // else
_material->getStateBlock()->setDepthWrite(true); _material->getStateBlock()->setDepthWrite(true);

View File

@ -59,7 +59,7 @@ class CC_DLL Mesh : public Ref
friend class Sprite3D; friend class Sprite3D;
public: public:
typedef std::vector<unsigned short> IndexArray; typedef std::vector<unsigned short> IndexArray;
/**create mesh from positions, normals, and so on, sigle SubMesh*/ /**create mesh from positions, normals, and so on, single SubMesh*/
static Mesh* create(const std::vector<float>& positions, const std::vector<float>& normals, const std::vector<float>& texs, const IndexArray& indices); static Mesh* create(const std::vector<float>& positions, const std::vector<float>& normals, const std::vector<float>& texs, const IndexArray& indices);
/**create mesh with vertex attributes*/ /**create mesh with vertex attributes*/
CC_DEPRECATED_ATTRIBUTE static Mesh* create(const std::vector<float>& vertices, int perVertexSizeInFloat, const IndexArray& indices, int numIndex, const std::vector<MeshVertexAttrib>& attribs, int attribCount){ return create(vertices, perVertexSizeInFloat, indices, attribs); } CC_DEPRECATED_ATTRIBUTE static Mesh* create(const std::vector<float>& vertices, int perVertexSizeInFloat, const IndexArray& indices, int numIndex, const std::vector<MeshVertexAttrib>& attribs, int attribCount){ return create(vertices, perVertexSizeInFloat, indices, attribs); }

View File

@ -97,7 +97,7 @@ protected:
std::vector<Mat4> _invBindPoses; //inverse bind pose of bone std::vector<Mat4> _invBindPoses; //inverse bind pose of bone
Bone3D* _rootBone; Bone3D* _rootBone;
Skeleton3D* _skeleton; //skeleton the skin refered Skeleton3D* _skeleton; //skeleton the skin referred
// Pointer to the array of palette matrices. // Pointer to the array of palette matrices.
// This array is passed to the vertex shader as a uniform. // This array is passed to the vertex shader as a uniform.

View File

@ -35,8 +35,8 @@ NS_CC_BEGIN
*/ */
/** /**
* Oritened Bounding Box(OBB) * Oriented Bounding Box(OBB)
* @brief the OBB is similar to the AABB but the bounding box has the same direction as Sprite3D. so it's collistion detection more precise than AABB * @brief the OBB is similar to the AABB but the bounding box has the same direction as Sprite3D. so it's collision detection more precise than AABB
* @js NA * @js NA
*/ */
class CC_DLL OBB class CC_DLL OBB
@ -119,7 +119,7 @@ protected:
void getInterval(const OBB& box, const Vec3& axis, float &min, float &max) const; void getInterval(const OBB& box, const Vec3& axis, float &min, float &max) const;
/* /*
* Get the edege of x y z axis direction * Get the edge of x y z axis direction
*/ */
Vec3 getEdgeDirection(int index) const; Vec3 getEdgeDirection(int index) const;
@ -131,7 +131,7 @@ protected:
public: public:
Vec3 _center; // obb center Vec3 _center; // obb center
Vec3 _xAxis; // x axis of obb, unit vector Vec3 _xAxis; // x axis of obb, unit vector
Vec3 _yAxis; // y axis of obb, unit vecotr Vec3 _yAxis; // y axis of obb, unit vector
Vec3 _zAxis; // z axis of obb, unit vector Vec3 _zAxis; // z axis of obb, unit vector
Vec3 _extentX; // _xAxis * _extents.x Vec3 _extentX; // _xAxis * _extents.x
Vec3 _extentY; // _yAxis * _extents.y Vec3 _extentY; // _yAxis * _extents.y

View File

@ -38,7 +38,7 @@ NS_CC_BEGIN
*/ */
/** /**
* @brief Defines a basic hierachial structure of transformation spaces. * @brief Defines a basic hierarchical structure of transformation spaces.
* @lua NA * @lua NA
*/ */
class CC_DLL Bone3D : public Ref class CC_DLL Bone3D : public Ref
@ -57,7 +57,7 @@ public:
/**update own world matrix and children's*/ /**update own world matrix and children's*/
void updateWorldMat(); void updateWorldMat();
/**get wrod matrix*/ /**get world matrix*/
const Mat4& getWorldMat(); const Mat4& getWorldMat();
/**get bone name*/ /**get bone name*/

View File

@ -40,7 +40,7 @@ NS_CC_BEGIN
class TextureCube; class TextureCube;
/** /**
* Sky box technology usually used to simulate infinity sky, mountains and other phenomena. * Sky box technology is usually used to simulate infinity sky, mountains and other phenomena.
*/ */
class CC_DLL Skybox : public Node class CC_DLL Skybox : public Node
{ {
@ -49,7 +49,7 @@ public:
/** create skybox from 6 textures. /** create skybox from 6 textures.
@param positive_x texture for the right side of the texture cube face. @param positive_x texture for the right side of the texture cube face.
@param negative_x texture for the up side of the texture cube face. @param negative_x texture for the left side of the texture cube face.
@param positive_y texture for the top side of the texture cube face @param positive_y texture for the top side of the texture cube face
@param negative_y texture for the bottom side of the texture cube face @param negative_y texture for the bottom side of the texture cube face
@param positive_z texture for the forward side of the texture cube face. @param positive_z texture for the forward side of the texture cube face.

View File

@ -51,7 +51,7 @@ class Texture2D;
class MeshSkin; class MeshSkin;
class AttachNode; class AttachNode;
struct NodeData; struct NodeData;
/** @brief Sprite3D: A sprite can be loaded from 3D model files, .obj, .c3t, .c3b, then can be drawed as sprite */ /** @brief Sprite3D: A sprite can be loaded from 3D model files, .obj, .c3t, .c3b, then can be drawn as sprite */
class CC_DLL Sprite3D : public Node, public BlendProtocol class CC_DLL Sprite3D : public Node, public BlendProtocol
{ {
public: public:
@ -70,7 +70,7 @@ public:
/** create 3d sprite asynchronously /** create 3d sprite asynchronously
* If the 3d model was previously loaded, it will create a new 3d sprite and the callback will be called at once. * If the 3d model was previously loaded, it will create a new 3d sprite and the callback will be called at once.
* Otherwise it will load the model file in a new thread, and when the 3d sprite is loaded, the callback will be called with the created Sprite3D and a userdefined parameter. * Otherwise it will load the model file in a new thread, and when the 3d sprite is loaded, the callback will be called with the created Sprite3D and a user-defined parameter.
* The callback will be called from the main thread, so it is safe to create any cocos2d object from the callback. * The callback will be called from the main thread, so it is safe to create any cocos2d object from the callback.
* @param modelPath model to be loaded * @param modelPath model to be loaded
* @param callback callback after loading * @param callback callback after loading
@ -124,12 +124,12 @@ public:
// overrides // overrides
/** set GLProgramState, you should bind attributes by yourself */ /** set GLProgramState, you should bind attributes by yourself */
virtual void setGLProgramState(GLProgramState *glProgramState) override; virtual void setGLProgramState(GLProgramState *glProgramState) override;
/** just rember bind attributes */ /** just remember bind attributes */
virtual void setGLProgram(GLProgram *glprogram) override; virtual void setGLProgram(GLProgram *glprogram) override;
/* /*
* Get AABB * Get AABB
* If the sprite has animation, it can't be calculated accuratly, * If the sprite has animation, it can't be calculated accurately,
* because bone can drive the vertices, we just use the origin vertices * because bone can drive the vertices, we just use the origin vertices
* to calculate the AABB. * to calculate the AABB.
*/ */
@ -161,7 +161,7 @@ public:
/** /**
* Returns 2d bounding-box * Returns 2d bounding-box
* Note: the bouding-box is just get from the AABB which as Z=0, so that is not very accurate. * Note: the bounding-box is just get from the AABB which as Z=0, so that is not very accurate.
*/ */
virtual Rect getBoundingBox() const override; virtual Rect getBoundingBox() const override;
@ -332,7 +332,7 @@ protected:
static Sprite3DCache* _cacheInstance; static Sprite3DCache* _cacheInstance;
std::unordered_map<std::string, Sprite3DData*> _spriteDatas; //cached sprite datas std::unordered_map<std::string, Sprite3DData*> _spriteDatas; //cached sprite data
}; };
// end of 3d group // end of 3d group

View File

@ -924,7 +924,7 @@ void Terrain::reload()
void Terrain::Chunk::finish() void Terrain::Chunk::finish()
{ {
//genearate two VBO ,the first for vertices, we just setup datas once ,won't changed at all //generate two VBO ,the first for vertices, we just setup datas once ,won't changed at all
//the second vbo for the indices, because we use level of detail technique to each chunk, so we will modified frequently //the second vbo for the indices, because we use level of detail technique to each chunk, so we will modified frequently
glGenBuffers(1,&_vbo); glGenBuffers(1,&_vbo);
@ -939,7 +939,7 @@ void Terrain::Chunk::finish()
for(int i =0;i<4;i++) for(int i =0;i<4;i++)
{ {
int step = 1<<_currentLod; int step = 1<<_currentLod;
//reserve the indices size, the first part is the core part of the chunk, the second part & thid part is for fix crack //reserve the indices size, the first part is the core part of the chunk, the second part & third part is for fix crack
int indicesAmount =(_terrain->_chunkSize.width/step+1)*(_terrain->_chunkSize.height/step+1)*6+(_terrain->_chunkSize.height/step)*6 int indicesAmount =(_terrain->_chunkSize.width/step+1)*(_terrain->_chunkSize.height/step+1)*6+(_terrain->_chunkSize.height/step)*6
+(_terrain->_chunkSize.width/step)*6; +(_terrain->_chunkSize.width/step)*6;
_lod[i]._indices.reserve(indicesAmount); _lod[i]._indices.reserve(indicesAmount);

View File

@ -44,7 +44,7 @@ NS_CC_BEGIN
*/ */
/** /**
* the maximum amount of the chunkes * the maximum amount of the chunks
**/ **/
#define MAX_CHUNKES 256 #define MAX_CHUNKES 256
@ -70,12 +70,12 @@ NS_CC_BEGIN
* via the chunkSize property in TerrainData. * via the chunkSize property in TerrainData.
* *
* Chunks are managed under the QuadTree.As DE FACTO terminal Node of the QuadTree; * Chunks are managed under the QuadTree.As DE FACTO terminal Node of the QuadTree;
* let us cull chunks efficientlly to reduce drawCall amount And reduce the VBOs'Size that pass to the GPU. * let us cull chunks efficiently to reduce drawCall amount And reduce the VBOs'Size that pass to the GPU.
* *
* Level of detail (LOD) is supported using a technique that is similar to texture mipmapping -- called GeoMapping. * Level of detail (LOD) is supported using a technique that is similar to texture mipmapping -- called GeoMapping.
* A distance-to-camera based test used to decide * A distance-to-camera based test used to decide
* the appropriate LOD for a terrain chunk. The number of LOD levels is 0 by default (which * the appropriate LOD for a terrain chunk. The number of LOD levels is 0 by default (which
* means only the base level is used),the maxium number of LOD levels is 4. Of course ,you can hack the value individually. * means only the base level is used),the maximum number of LOD levels is 4. Of course ,you can hack the value individually.
* *
* Finally, when LOD is enabled, cracks can begin to appear between terrain Chunks of * Finally, when LOD is enabled, cracks can begin to appear between terrain Chunks of
* different LOD levels. An acceptable solution might be to simply reduce the lower LOD(high detail,smooth) chunks border, * different LOD levels. An acceptable solution might be to simply reduce the lower LOD(high detail,smooth) chunks border,
@ -136,7 +136,7 @@ public:
/**constructor, this constructor construct a terrain which have 3 detailmaps, 1 alpha map*/ /**constructor, this constructor construct a terrain which have 3 detailmaps, 1 alpha map*/
TerrainData(const char* heightMapsrc, const char * alphamap, const DetailMap& detail1,const DetailMap& detail2, const DetailMap& detail3, const Size & chunksize = Size(32,32), float mapHeight = 2, float mapScale = 0.1); TerrainData(const char* heightMapsrc, const char * alphamap, const DetailMap& detail1,const DetailMap& detail2, const DetailMap& detail3, const Size & chunksize = Size(32,32), float mapHeight = 2, float mapScale = 0.1);
/** /**
*deterimine the chunk size,chunk is the minimal subdivision of the Terrain *determine the chunk size,chunk is the minimal subdivision of the Terrain
*/ */
Size _chunkSize; Size _chunkSize;
/**height Map source path*/ /**height Map source path*/
@ -285,7 +285,7 @@ private:
QuadTree * _tr; QuadTree * _tr;
QuadTree * _bl; QuadTree * _bl;
QuadTree * _br; QuadTree * _br;
/**A flag present current quadTree node whether a terminal node,the terminal node is de facto the chunck*/ /**A flag present current quadTree node whether a terminal node,the terminal node is de facto the chunk*/
bool _isTerminal; bool _isTerminal;
Chunk * _chunk; Chunk * _chunk;
int _posX; int _posX;
@ -336,7 +336,7 @@ public:
**/ **/
float getHeight(Vec2 pos, Vec3*Normal = nullptr) const; float getHeight(Vec2 pos, Vec3*Normal = nullptr) const;
/**get the normal of the specified pistion in terrain /**get the normal of the specified position in terrain
* @return the normal vector of the specified position of the terrain. * @return the normal vector of the specified position of the terrain.
* @note the fast normal calculation may not get precise normal vector. * @note the fast normal calculation may not get precise normal vector.
**/ **/
@ -348,7 +348,7 @@ public:
**/ **/
void setDrawWire(bool boolValue); void setDrawWire(bool boolValue);
/** /**
* Set threshold distance of each LOD level,must equal or gereater than the chunk size * Set threshold distance of each LOD level,must equal or greater than the chunk size
* @Note when invoke initHeightMap, the LOD distance will be automatic calculated. * @Note when invoke initHeightMap, the LOD distance will be automatic calculated.
*/ */
void setLODDistance(float lod1, float lod2, float lod3); void setLODDistance(float lod1, float lod2, float lod3);
@ -374,7 +374,7 @@ public:
/** /**
* Ray-Terrain intersection. * Ray-Terrain intersection.
* @param ray to hit the terrain * @param ray to hit the terrain
* @param intersectionPoint hit point if hitted * @param intersectionPoint hit point if hit
* @return true if hit, false otherwise * @return true if hit, false otherwise
*/ */
bool getIntersectionPoint(const Ray & ray, Vec3 & intersectionPoint) const; bool getIntersectionPoint(const Ray & ray, Vec3 & intersectionPoint) const;
@ -395,12 +395,12 @@ public:
void resetHeightMap(const char * heightMap); void resetHeightMap(const char * heightMap);
/** /**
* get the terrain's mininal height. * get the terrain's minimal height.
*/ */
float getMinHeight(); float getMinHeight();
/** /**
* get the terrain's maximum height. * get the terrain's maximal height.
*/ */
float getMaxHeight(); float getMaxHeight();
@ -440,7 +440,7 @@ protected:
/** /**
* recursively set each chunk's LOD * recursively set each chunk's LOD
* @param cameraPos the camera postion in world space * @param cameraPos the camera position in world space
**/ **/
void setChunksLOD(Vec3 cameraPos); void setChunksLOD(Vec3 cameraPos);
@ -458,7 +458,7 @@ protected:
virtual void onEnter() override; virtual void onEnter() override;
/** /**
* cache all unifrom loactions in GLSL. * cache all uniform locations in GLSL.
**/ **/
void cacheUniformAttribLocation(); void cacheUniformAttribLocation();

View File

@ -200,6 +200,8 @@ physics/CCPhysicsContact.cpp \
physics/CCPhysicsJoint.cpp \ physics/CCPhysicsJoint.cpp \
physics/CCPhysicsShape.cpp \ physics/CCPhysicsShape.cpp \
physics/CCPhysicsWorld.cpp \ physics/CCPhysicsWorld.cpp \
physics/CCComponentPhysics2d.cpp \
physics/CCPhysicsManager.cpp \
physics3d/CCPhysics3D.cpp \ physics3d/CCPhysics3D.cpp \
physics3d/CCPhysics3DWorld.cpp \ physics3d/CCPhysics3DWorld.cpp \
physics3d/CCPhysics3DComponent.cpp \ physics3d/CCPhysics3DComponent.cpp \

View File

@ -75,7 +75,7 @@ void AudioEngineInterruptionListenerCallback(void* user_data, UInt32 interruptio
{ {
if ([[[UIDevice currentDevice] systemVersion] intValue] > 5) { if ([[[UIDevice currentDevice] systemVersion] intValue] > 5) {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleInterruption:) name:AVAudioSessionInterruptionNotification object:[AVAudioSession sharedInstance]]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleInterruption:) name:AVAudioSessionInterruptionNotification object:[AVAudioSession sharedInstance]];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleInterruption:) name:UIApplicationDidBecomeActiveNotification object:[AVAudioSession sharedInstance]]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleInterruption:) name:UIApplicationDidBecomeActiveNotification object:nil];
} }
else { else {
AudioSessionInitialize(NULL, NULL, AudioEngineInterruptionListenerCallback, self); AudioSessionInitialize(NULL, NULL, AudioEngineInterruptionListenerCallback, self);

View File

@ -61,7 +61,6 @@ THE SOFTWARE.
#include "base/CCConfiguration.h" #include "base/CCConfiguration.h"
#include "base/CCAsyncTaskPool.h" #include "base/CCAsyncTaskPool.h"
#include "platform/CCApplication.h" #include "platform/CCApplication.h"
//#include "platform/CCGLViewImpl.h"
#if CC_ENABLE_SCRIPT_BINDING #if CC_ENABLE_SCRIPT_BINDING
#include "CCScriptSupport.h" #include "CCScriptSupport.h"

View File

@ -154,12 +154,12 @@ public:
/** Gets the FPS value. */ /** Gets the FPS value. */
inline float getAnimationInterval() { return _animationInterval; } inline float getAnimationInterval() { return _animationInterval; }
/** Sets the FPS value. FPS = 1/internal. */ /** Sets the FPS value. FPS = 1/interval. */
virtual void setAnimationInterval(float interval) = 0; virtual void setAnimationInterval(float interval) = 0;
/** Whether or not to display the FPS on the bottom-left corner. */ /** Whether or not displaying the FPS on the bottom-left corner of the screen. */
inline bool isDisplayStats() { return _displayStats; } inline bool isDisplayStats() { return _displayStats; }
/** Display the FPS on the bottom-left corner. */ /** Display the FPS on the bottom-left corner of the screen. */
inline void setDisplayStats(bool displayStats) { _displayStats = displayStats; } inline void setDisplayStats(bool displayStats) { _displayStats = displayStats; }
/** Get seconds per frame. */ /** Get seconds per frame. */
@ -260,8 +260,8 @@ public:
Vec2 convertToUI(const Vec2& point); Vec2 convertToUI(const Vec2& point);
/** /**
* Gets the distance between camera and near clipping frane. * Gets the distance between camera and near clipping frame.
* It is correct for default camera that near clipping frane is the same as screen. * It is correct for default camera that near clipping frame is same as the screen.
*/ */
float getZEye() const; float getZEye() const;

View File

@ -82,19 +82,19 @@ bool EventListenerMouse::init()
{ {
case EventMouse::MouseEventType::MOUSE_DOWN: case EventMouse::MouseEventType::MOUSE_DOWN:
if(onMouseDown != nullptr) if(onMouseDown != nullptr)
onMouseDown(event); onMouseDown(mouseEvent);
break; break;
case EventMouse::MouseEventType::MOUSE_UP: case EventMouse::MouseEventType::MOUSE_UP:
if(onMouseUp != nullptr) if(onMouseUp != nullptr)
onMouseUp(event); onMouseUp(mouseEvent);
break; break;
case EventMouse::MouseEventType::MOUSE_MOVE: case EventMouse::MouseEventType::MOUSE_MOVE:
if(onMouseMove != nullptr) if(onMouseMove != nullptr)
onMouseMove(event); onMouseMove(mouseEvent);
break; break;
case EventMouse::MouseEventType::MOUSE_SCROLL: case EventMouse::MouseEventType::MOUSE_SCROLL:
if(onMouseScroll != nullptr) if(onMouseScroll != nullptr)
onMouseScroll(event); onMouseScroll(mouseEvent);
break; break;
default: default:
break; break;

View File

@ -57,10 +57,10 @@ public:
virtual EventListenerMouse* clone() override; virtual EventListenerMouse* clone() override;
virtual bool checkAvailable() override; virtual bool checkAvailable() override;
std::function<void(Event* event)> onMouseDown; std::function<void(EventMouse* event)> onMouseDown;
std::function<void(Event* event)> onMouseUp; std::function<void(EventMouse* event)> onMouseUp;
std::function<void(Event* event)> onMouseMove; std::function<void(EventMouse* event)> onMouseMove;
std::function<void(Event* event)> onMouseScroll; std::function<void(EventMouse* event)> onMouseScroll;
CC_CONSTRUCTOR_ACCESS: CC_CONSTRUCTOR_ACCESS:
EventListenerMouse(); EventListenerMouse();

View File

@ -163,6 +163,18 @@ void ScriptEngineManager::destroyInstance()
} }
} }
bool ScriptEngineManager::sendActionEventToJS(Action* actionObject, int eventType, void* param)
{
auto scriptEngine = getInstance()->getScriptEngine();
ActionObjectScriptData data(actionObject,(int*)&eventType, param);
ScriptEvent scriptEvent(kScriptActionEvent,(void*)&data);
if (scriptEngine->sendEvent(&scriptEvent))
return true;
return false;
}
bool ScriptEngineManager::sendNodeEventToJS(Node* node, int action) bool ScriptEngineManager::sendNodeEventToJS(Node* node, int action)
{ {
auto scriptEngine = getInstance()->getScriptEngine(); auto scriptEngine = getInstance()->getScriptEngine();

View File

@ -51,6 +51,7 @@ class Layer;
class MenuItem; class MenuItem;
class CallFunc; class CallFunc;
class Acceleration; class Acceleration;
class Action;
enum ccScriptType { enum ccScriptType {
kScriptTypeNone = 0, kScriptTypeNone = 0,
@ -259,7 +260,8 @@ enum ScriptEventType
kControlEvent, kControlEvent,
kCommonEvent, kCommonEvent,
kComponentEvent, kComponentEvent,
kRestartGame kRestartGame,
kScriptActionEvent
}; };
/** /**
@ -296,6 +298,48 @@ struct BasicScriptData
} }
}; };
/**
* For Lua, Wrapper the script data that should be used to find the handler corresponding to the Lua function by the nativeobject pointer and store the value pointer which would be converted concretely by the different events,then the converted data would be passed into the Lua stack.
* @js NA
*/
struct ActionObjectScriptData
{
/**
* For Lua, nativeobject is used to get handler corresponding to the Lua function.
*
* @js NA
* @lua NA
*/
void* nativeObject;
/**
* A pointer point to the value data which event action
*
* @js NA
* @lua NA
*/
int* eventType;
/**
* A pointer point to the value data which would be converted by different events.
*
* @js NA
* @lua NA
*/
void* param;
/**
* Constructor of BasicScriptData.
*
* @js NA
* @lua NA
*/
ActionObjectScriptData(void* inObject,int* inValue = nullptr, void* inParam = nullptr)
: nativeObject(inObject),eventType(inValue), param(inParam)
{
}
};
/** /**
* For Lua, the SchedulerScriptData is used to find the Lua function pointer by the handler, then call the Lua function by push the elapse into the Lua stack as a parameter when scheduler update event is triggered. * For Lua, the SchedulerScriptData is used to find the Lua function pointer by the handler, then call the Lua function by push the elapse into the Lua stack as a parameter when scheduler update event is triggered.
* @js NA * @js NA
@ -770,6 +814,13 @@ public:
* @js NA * @js NA
*/ */
static void destroyInstance(); static void destroyInstance();
/**
*
*
* @lua NA
* @js NA
*/
static bool sendActionEventToJS(Action* actionObject, int eventType, void* param);
/** /**
* *
* *

View File

@ -29,8 +29,8 @@ THE SOFTWARE.
#define __COCOS2D_H__ #define __COCOS2D_H__
// 0x00 HI ME LO // 0x00 HI ME LO
// 00 03 07 00 // 00 03 08 00
#define COCOS2D_VERSION 0x00030700 #define COCOS2D_VERSION 0x00030800
// //
// all cocos2d include files // all cocos2d include files
@ -186,6 +186,8 @@ THE SOFTWARE.
#include "physics/CCPhysicsJoint.h" #include "physics/CCPhysicsJoint.h"
#include "physics/CCPhysicsShape.h" #include "physics/CCPhysicsShape.h"
#include "physics/CCPhysicsWorld.h" #include "physics/CCPhysicsWorld.h"
#include "physics/CCComponentPhysics2d.h"
#include "physics/CCPhysicsManager.h"
// platform // platform
#include "platform/CCCommon.h" #include "platform/CCCommon.h"

View File

@ -400,54 +400,33 @@ namespace cocostudio
bool touchScaleEnabled = options->touchScaleEnable() != 0; bool touchScaleEnabled = options->touchScaleEnable() != 0;
label->setTouchScaleChangeEnabled(touchScaleEnabled); label->setTouchScaleChangeEnabled(touchScaleEnabled);
std::string text = options->text()->c_str();
label->setString(text);
int fontSize = options->fontSize(); int fontSize = options->fontSize();
label->setFontSize(fontSize); label->setFontSize(fontSize);
std::string fontName = options->fontName()->c_str();
label->setFontName(fontName);
Size areaSize = Size(options->areaWidth(), options->areaHeight()); Size areaSize = Size(options->areaWidth(), options->areaHeight());
if (!areaSize.equals(Size::ZERO)) if (!areaSize.equals(Size::ZERO))
{ {
label->setTextAreaSize(areaSize); label->setTextAreaSize(areaSize);
} }
auto resourceData = options->fontResource();
std::string path = resourceData->path()->c_str();
if (!path.empty() && FileUtils::getInstance()->isFileExist(path))
{
label->setFontName(path);
}
else
{
std::string fontName = options->fontName()->c_str();
label->setFontName(fontName);
}
TextHAlignment h_alignment = (TextHAlignment)options->hAlignment(); TextHAlignment h_alignment = (TextHAlignment)options->hAlignment();
label->setTextHorizontalAlignment(h_alignment); label->setTextHorizontalAlignment(h_alignment);
TextVAlignment v_alignment = (TextVAlignment)options->vAlignment(); TextVAlignment v_alignment = (TextVAlignment)options->vAlignment();
label->setTextVerticalAlignment((TextVAlignment)v_alignment); label->setTextVerticalAlignment((TextVAlignment)v_alignment);
bool fileExist = false;
std::string errorFilePath = "";
auto resourceData = options->fontResource();
std::string path = resourceData->path()->c_str();
if (path != "")
{
if (FileUtils::getInstance()->isFileExist(path))
{
fileExist = true;
}
else
{
errorFilePath = path;
fileExist = false;
}
if (fileExist)
{
label->setFontName(path);
}
//else
//{
// auto alert = Label::create();
// alert->setString(__String::createWithFormat("%s missed", errorFilePath.c_str())->getCString());
// label->addChild(alert);
//}
}
bool outlineEnabled = options->outlineEnabled() != 0; bool outlineEnabled = options->outlineEnabled() != 0;
if (outlineEnabled) if (outlineEnabled)
{ {
@ -470,6 +449,9 @@ namespace cocostudio
} }
} }
std::string text = options->text()->c_str();
label->setString(text);
// Save node color before set widget properties // Save node color before set widget properties
auto oldColor = node->getColor(); auto oldColor = node->getColor();
@ -494,7 +476,6 @@ namespace cocostudio
Size contentSize(widgetOptions->size()->width(), widgetOptions->size()->height()); Size contentSize(widgetOptions->size()->width(), widgetOptions->size()->height());
label->setContentSize(contentSize); label->setContentSize(contentSize);
} }
} }
Node* TextReader::createNodeWithFlatBuffers(const flatbuffers::Table *textOptions) Node* TextReader::createNodeWithFlatBuffers(const flatbuffers::Table *textOptions)

View File

@ -1097,6 +1097,11 @@ void SIOClient::fireEvent(const std::string& eventName, const std::string& data)
CCLOGINFO("SIOClient::fireEvent no native event with name %s found", eventName.c_str()); CCLOGINFO("SIOClient::fireEvent no native event with name %s found", eventName.c_str());
} }
void SIOClient::setTag(const char* tag)
{
_tag = tag;
}
//begin SocketIO methods //begin SocketIO methods
SocketIO *SocketIO::_inst = nullptr; SocketIO *SocketIO::_inst = nullptr;

View File

@ -262,10 +262,8 @@ public:
* The tag is used to distinguish the various SIOClient objects. * The tag is used to distinguish the various SIOClient objects.
* @param tag string object. * @param tag string object.
*/ */
inline void setTag(const char* tag) void setTag(const char* tag);
{
_tag = tag;
};
/** /**
* Get tag of SIOClient. * Get tag of SIOClient.
* @return const char* the pointer point to the _tag. * @return const char* the pointer point to the _tag.

View File

@ -0,0 +1,263 @@
/****************************************************************************
Copyright (c) 2015 Chukong Technologies Inc.
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#include "base/ccConfig.h" // to include defination of CC_USE_PHYSICS
#if CC_USE_PHYSICS
#include "physics/CCComponentPhysics2d.h"
#include "physics/CCPhysicsBody.h"
#include "physics/CCPhysicsManager.h"
#include "2d/CCNode.h"
#include "base/CCDirector.h"
NS_CC_BEGIN
const std::string ComponentPhysics2d::COMPONENT_NAME = "physics2d";
ComponentPhysics2d* ComponentPhysics2d::create()
{
return create(nullptr);
}
ComponentPhysics2d* ComponentPhysics2d::create(PhysicsBody *physicsBody)
{
auto ret = new (std::nothrow) ComponentPhysics2d(physicsBody);
if (ret)
ret->autorelease();
return ret;
}
ComponentPhysics2d::ComponentPhysics2d()
: _physicsBody(nullptr)
, _physicsRotation(0.0f)
, _ownerOriginRotation(0.0f)
{
_name = COMPONENT_NAME;
}
ComponentPhysics2d::ComponentPhysics2d(PhysicsBody* physicsBody)
: _physicsRotation(0.0f)
, _ownerOriginRotation(0.0f)
, _physicsBody(nullptr) // should set to null to invoke setPhysicsBody()
{
_name = COMPONENT_NAME;
setPhysicsBody(physicsBody);
}
ComponentPhysics2d::~ComponentPhysics2d()
{
removePhysicsBody();
}
// true if two Vec3 equals, false else
bool ComponentPhysics2d::isVec3Equal(const cocos2d::Vec3 &v1, const cocos2d::Vec3 &v2) const
{
return fabs(v1.x - v2.x) < FLT_EPSILON &&
fabs(v1.x - v2.y) < FLT_EPSILON;
}
void ComponentPhysics2d::beforeSimulation()
{
if (nullptr == _physicsBody)
return;
_nodeToWorldTransform = _owner->getNodeToWorldTransform();
// set scale
_nodeToWorldTransform.getScale(&_scale);
if (! isVec3Equal(_scale, _recordScale))
{
_physicsBody->setScale(_scale.x, _scale.y);
_recordScale = _scale;
}
// set rotation
if (_owner->getParent())
{
_physicsRotation = getPhysicsRotation(_owner->getParent()) + _owner->getRotation();
}
_physicsBody->setRotation(_physicsRotation - _ownerOriginRotation);
// set position
auto worldPosition = _ownerCenterOffset;
_nodeToWorldTransform.transformPoint(&worldPosition);
_physicsBody->setPosition(Vec2(worldPosition.x, worldPosition.y));
getParentToWorldTransform().getInversed().transformPoint(&worldPosition);
_offset.x = worldPosition.x - _owner->getPosition().x;
_offset.y = worldPosition.y - _owner->getPosition().y;
}
void ComponentPhysics2d::afterSimulation()
{
if (nullptr == _physicsBody)
return;
// set Node position
auto worldPosition = _physicsBody->getPosition();
Vec3 positionInParent(worldPosition.x, worldPosition.y, 0);
getParentToWorldTransform().getInversed().transformPoint(&positionInParent);
_owner->setPosition(positionInParent.x - _offset.x, positionInParent.y - _offset.y);
// set Node rotation
_physicsRotation = _physicsBody->getRotation();
_owner->setRotation(_physicsRotation - getPhysicsRotation(_owner->getParent()) + _ownerOriginRotation);
}
void ComponentPhysics2d::setPhysicsBody(PhysicsBody *physicsBody)
{
removeFromPhysicsManager();
if (physicsBody != _physicsBody)
{
if (nullptr != _physicsBody)
{
_physicsBody->release();
_physicsBody->_componentBelongsTo = nullptr;
}
// two components should not share the same physics body
if (physicsBody && physicsBody->_componentBelongsTo != nullptr)
physicsBody->_componentBelongsTo->_physicsBody = nullptr;
_physicsBody = physicsBody;
if (nullptr != _physicsBody)
{
_physicsBody->retain();
_physicsBody->_componentBelongsTo = this;
}
}
addToPhysicsManager();
}
PhysicsBody* ComponentPhysics2d::getPhysicsBody() const
{
return _physicsBody;
}
void ComponentPhysics2d::setEnabled(bool value)
{
Component::setEnabled(value);
if (value)
addToPhysicsManager();
else
removeFromPhysicsManager();
}
void ComponentPhysics2d::onEnter()
{
addToPhysicsManager();
}
void ComponentPhysics2d::onExit()
{
removeFromPhysicsManager();
}
void ComponentPhysics2d::onAdd()
{
auto contentSize = _owner->getContentSize();
_ownerCenterOffset.x = 0.5 * contentSize.width;
_ownerCenterOffset.y = 0.5 * contentSize.height;
_ownerOriginRotation = _owner->getRotation();
// component may be added after onEnter() has been invoked, so we should add
// this line to make sure physics body is added to physics world
addToPhysicsManager();
}
void ComponentPhysics2d::onRemove()
{
removePhysicsBody();
}
void ComponentPhysics2d::removePhysicsBody()
{
removeFromPhysicsManager();
if (_physicsBody)
{
_physicsBody->_componentBelongsTo = nullptr;
_physicsBody->release();
_physicsBody = nullptr;
}
}
void ComponentPhysics2d::addToPhysicsManager()
{
if (_owner)
{
auto scene = _owner->getScene();
if (scene)
scene->getPhysicsManager()->addPhysicsComponent(this);
}
}
void ComponentPhysics2d::removeFromPhysicsManager()
{
if (_owner)
{
auto scene = _owner->getScene();
if (scene)
scene->getPhysicsManager()->removePhysicsComponent(this);
}
}
Mat4 ComponentPhysics2d::getParentToWorldTransform() const
{
if (_owner->getParent())
return _owner->getParent()->getNodeToWorldTransform();
else
return _owner->getNodeToWorldTransform();
}
float ComponentPhysics2d::getPhysicsRotation(Node *node) const
{
if (!node)
return 0.0f;
auto physicsComponent = node->getComponent<ComponentPhysics2d>();
if (physicsComponent)
{
return physicsComponent->_physicsRotation;
}
else
{
auto parent = node->getParent();
if (parent)
return getPhysicsRotation(parent) + node->getRotation();
else
return 0.0f;
}
}
NS_CC_END
#endif // CC_USE_PHYSICS

View File

@ -0,0 +1,140 @@
/****************************************************************************
Copyright (c) 2015 Chukong Technologies Inc.
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#pragma once
#include "base/ccConfig.h" // to include defination of CC_USE_PHYSICS
#if CC_USE_PHYSICS
#include "platform/CCPlatformMacros.h"
#include "2d/CCComponent.h"
NS_CC_BEGIN
/**
* @addtogroup physics
* @{
* @addtogroup physics_2d
* @{
*/
class PhysicsBody;
class CC_DLL ComponentPhysics2d : public Component
{
public:
/**
* Create a physics component without physics body. Can set phyiscs body later with setPhysicsBody().
* I am not sure if we need this function, because i think physics body is needed when creating a
* physics component. But i think it is needed by editor, so i keep this function.
*
* @return A pointer of `ComponentPhysics2d` that is autoreleased.
*/
static ComponentPhysics2d* create();
/**
* Create a physics component with physics body.
*
* @param physicsBody The physics body that belongs to this component.
* @return A pointer of `ComponentPhysics2d` that is autoreleased.
*/
static ComponentPhysics2d* create(PhysicsBody *physicsBody);
virtual ~ComponentPhysics2d();
/// @cond DO_NOT_SHOW
/**
* Synchronize Node's status(position, rotation, scale) to phyiscs body.
* It is invoked before physics simulation.
*
* @warning Don't invoke this funciton by yourself.
*/
void beforeSimulation();
/**
* Synchronize physics body's status(position, rotation) to phyiscs body.
* It is invoked after physics simulation.
*
* @warning Don't invoke this funciton by yourself.
*/
void afterSimulation();
/// @endcond DO_NOT_SHOW
/**
* Set physics body of this physics component. If the physics body is set to
* another physics component before, will set another physics component's physics
* body to null.
*
* @param physicsBody The physics body belongs to this component.
*/
void setPhysicsBody(PhysicsBody *physicsBody);
/**
* Get the physics body of this component.
*
* @return The physics body of this component.
*/
PhysicsBody* getPhysicsBody() const;
virtual void setEnabled(bool value) override;
virtual void onEnter() override;
virtual void onExit() override;
virtual void onAdd() override;
virtual void onRemove() override;
public:
const static std::string COMPONENT_NAME;
CC_CONSTRUCTOR_ACCESS:
ComponentPhysics2d();
ComponentPhysics2d(PhysicsBody *phsicsBody);
private:
void removePhysicsBody();
void addToPhysicsManager();
void removeFromPhysicsManager();
Mat4 getParentToWorldTransform() const;
float getPhysicsRotation(Node *node) const;
bool isVec3Equal(const Vec3 &v1, const Vec3 &v2) const;
private:
// this physic body of this component
PhysicsBody *_physicsBody;
// offset between owner's center point and down left point
Vec3 _ownerCenterOffset;
Mat4 _nodeToWorldTransform;
// offset of owner's center point and anchor point in parent coordinate
Vec2 _offset;
float _physicsRotation;
// the rotation of owner when the component is added to, the value will not change
float _ownerOriginRotation;
Vec3 _recordScale;
Vec3 _scale;
};
/** @} */
/** @} */
NS_CC_END
#endif // CC_USE_PHYSICS

View File

@ -31,10 +31,11 @@
#include "chipmunk.h" #include "chipmunk.h"
#include "2d/CCScene.h" #include "2d/CCScene.h"
#include "CCPhysicsShape.h" #include "physics/CCPhysicsShape.h"
#include "CCPhysicsJoint.h" #include "physics/CCPhysicsJoint.h"
#include "CCPhysicsWorld.h" #include "physics/CCPhysicsWorld.h"
#include "CCPhysicsHelper.h" #include "physics/CCPhysicsHelper.h"
#include "physics/CCComponentPhysics2d.h"
static inline void cpBodyUpdateVelocityWithoutGravity(cpBody *body, cpVect gravity, cpFloat damping, cpFloat dt) static inline void cpBodyUpdateVelocityWithoutGravity(cpBody *body, cpVect gravity, cpFloat damping, cpFloat dt)
{ {
@ -51,8 +52,7 @@ namespace
} }
PhysicsBody::PhysicsBody() PhysicsBody::PhysicsBody()
: _node(nullptr) : _world(nullptr)
, _world(nullptr)
, _cpBody(nullptr) , _cpBody(nullptr)
, _dynamic(true) , _dynamic(true)
, _enabled(true) , _enabled(true)
@ -68,10 +68,12 @@ PhysicsBody::PhysicsBody()
, _linearDamping(0.0f) , _linearDamping(0.0f)
, _angularDamping(0.0f) , _angularDamping(0.0f)
, _tag(0) , _tag(0)
, _positionInitDirty(true)
, _rotationOffset(0) , _rotationOffset(0)
, _recordedRotation(0.0f) , _recordedRotation(0.0f)
, _recordedAngle(0.0) , _recordedAngle(0.0)
, _componentBelongsTo(nullptr)
, _massSetByUser(false)
, _momentSetByUser(false)
{ {
} }
@ -334,8 +336,6 @@ void PhysicsBody::setGravityEnable(bool enable)
void PhysicsBody::setPosition(const Vec2& position) void PhysicsBody::setPosition(const Vec2& position)
{ {
_positionInitDirty = false;
_recordedPosition = position;
cpBodySetPos(_cpBody, PhysicsHelper::point2cpv(position + _positionOffset)); cpBodySetPos(_cpBody, PhysicsHelper::point2cpv(position + _positionOffset));
} }
@ -350,25 +350,25 @@ void PhysicsBody::setScale(float scaleX, float scaleY)
{ {
for (auto shape : _shapes) for (auto shape : _shapes)
{ {
_area -= shape->getArea();
if (!_massSetByUser)
addMass(-shape->getMass());
if (!_momentSetByUser)
addMoment(-shape->getMoment());
shape->setScale(scaleX, scaleY); shape->setScale(scaleX, scaleY);
_area += shape->getArea();
if (!_massSetByUser)
addMass(shape->getMass());
if (!_momentSetByUser)
addMoment(shape->getMoment());
} }
} }
const Vec2& PhysicsBody::getPosition() Vec2 PhysicsBody::getPosition() const
{ {
if (_positionInitDirty) { return Vec2(_cpBody->p.x - _positionOffset.x, _cpBody->p.y - _positionOffset.y);
if (_node) {
if (_node->getParent()) {
_latestPosition = _node->getParent()->convertToWorldSpace(_node->getPosition());
} else {
_latestPosition = _node->getPosition();
}
}
} else {
_latestPosition.x = _cpBody->p.x - _positionOffset.x;
_latestPosition.y = _cpBody->p.y - _positionOffset.y;
}
return _latestPosition;
} }
float PhysicsBody::getRotation() float PhysicsBody::getRotation()
@ -450,6 +450,7 @@ void PhysicsBody::setMass(float mass)
} }
_mass = mass; _mass = mass;
_massDefault = false; _massDefault = false;
_massSetByUser = true;
// update density // update density
if (_mass == PHYSICS_INFINITY) if (_mass == PHYSICS_INFINITY)
@ -628,6 +629,7 @@ void PhysicsBody::setMoment(float moment)
{ {
_moment = moment; _moment = moment;
_momentDefault = false; _momentDefault = false;
_momentSetByUser = true;
// the static body's mass and moment is always infinity // the static body's mass and moment is always infinity
if (_rotationEnabled && _dynamic) if (_rotationEnabled && _dynamic)
@ -723,6 +725,14 @@ void PhysicsBody::removeFromWorld()
} }
} }
Node* PhysicsBody::getNode() const
{
if (_componentBelongsTo)
return _componentBelongsTo->getOwner();
else
return nullptr;
}
void PhysicsBody::setEnable(bool enable) void PhysicsBody::setEnable(bool enable)
{ {
if (_enabled != enable) if (_enabled != enable)
@ -760,15 +770,12 @@ void PhysicsBody::setResting(bool rest) const
void PhysicsBody::update(float delta) void PhysicsBody::update(float delta)
{ {
if (_node) // damping compute
if (_isDamping && _dynamic && !isResting())
{ {
// damping compute _cpBody->v.x *= cpfclamp(1.0f - delta * _linearDamping, 0.0f, 1.0f);
if (_isDamping && _dynamic && !isResting()) _cpBody->v.y *= cpfclamp(1.0f - delta * _linearDamping, 0.0f, 1.0f);
{ _cpBody->w *= cpfclamp(1.0f - delta * _angularDamping, 0.0f, 1.0f);
_cpBody->v.x *= cpfclamp(1.0f - delta * _linearDamping, 0.0f, 1.0f);
_cpBody->v.y *= cpfclamp(1.0f - delta * _linearDamping, 0.0f, 1.0f);
_cpBody->w *= cpfclamp(1.0f - delta * _angularDamping, 0.0f, 1.0f);
}
} }
} }

View File

@ -41,6 +41,7 @@ class Node;
class Sprite; class Sprite;
class PhysicsWorld; class PhysicsWorld;
class PhysicsJoint; class PhysicsJoint;
class ComponentPhysics2d;
typedef Vec2 Vect; typedef Vec2 Vect;
@ -305,7 +306,7 @@ public:
inline const std::vector<PhysicsJoint*>& getJoints() const { return _joints; } inline const std::vector<PhysicsJoint*>& getJoints() const { return _joints; }
/** get the sprite the body set to. */ /** get the sprite the body set to. */
inline Node* getNode() const { return _node; } Node* getNode() const;
/** /**
* A mask that defines which categories this physics body belongs to. * A mask that defines which categories this physics body belongs to.
@ -368,7 +369,7 @@ public:
int getGroup() const; int getGroup() const;
/** get the body position. */ /** get the body position. */
const Vec2& getPosition(); Vec2 getPosition() const;
/** get the body rotation. */ /** get the body rotation. */
float getRotation(); float getRotation();
@ -505,7 +506,7 @@ public:
Vec2 local2World(const Vec2& point); Vec2 local2World(const Vec2& point);
/** Get the rigid body of chipmunk. */ /** Get the rigid body of chipmunk. */
cpBody* getCPBody() { return _cpBody; } cpBody* getCPBody() const { return _cpBody; }
protected: protected:
@ -525,10 +526,11 @@ protected:
virtual ~PhysicsBody(); virtual ~PhysicsBody();
protected: protected:
Node* _node;
std::vector<PhysicsJoint*> _joints; std::vector<PhysicsJoint*> _joints;
Vector<PhysicsShape*> _shapes; Vector<PhysicsShape*> _shapes;
PhysicsWorld* _world; PhysicsWorld* _world;
// weak reference
ComponentPhysics2d *_componentBelongsTo;
cpBody* _cpBody; cpBody* _cpBody;
bool _dynamic; bool _dynamic;
bool _enabled; bool _enabled;
@ -545,9 +547,11 @@ protected:
float _angularDamping; float _angularDamping;
int _tag; int _tag;
bool _positionInitDirty; // when setMass() is invoked, it means body's mass is not calculated by shapes
Vec2 _recordedPosition; bool _massSetByUser;
Vec2 _latestPosition; // when setMoment() is invoked, it means body's moment is not calculated by shapes
bool _momentSetByUser;
Vec2 _positionOffset; Vec2 _positionOffset;
float _rotationOffset; float _rotationOffset;
float _recordedRotation; float _recordedRotation;
@ -559,6 +563,7 @@ protected:
friend class Node; friend class Node;
friend class Layer; friend class Layer;
friend class ProtectedNode; friend class ProtectedNode;
friend class ComponentPhysics2d;
}; };
/** @} */ /** @} */

View File

@ -0,0 +1,133 @@
/****************************************************************************
Copyright (c) 2015 Chukong Technologies Inc.
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#include "base/ccConfig.h" // to include defination of CC_USE_PHYSICS
#if CC_USE_PHYSICS
#include "physics/CCPhysicsManager.h"
#include "physics/CCComponentPhysics2d.h"
#include "physics/CCPhysicsWorld.h"
#include "2d/CCScene.h"
NS_CC_BEGIN
PhysicsManager::PhysicsManager(Scene *scene)
: _scene(scene)
{
_physicsWorld = PhysicsWorld::construct();
}
PhysicsManager::~PhysicsManager()
{
delete _physicsWorld;
}
void PhysicsManager::update(float dt)
{
// Update physics position, should loop as the same sequence as node tree.
// ComponentPhysics2d::beforeSimulation() will depend on the sequence.
beforeSimulation(_scene);
// do simulation
_physicsWorld->update(dt, false);
// Update physics position, should loop as the same sequence as node tree.
// ComponentPhysics2d::afterSimulation() will depend on the sequence.
afterSimulation(_scene);
}
void PhysicsManager::beforeSimulation(Node *node)
{
auto iter = _owners.find(node);
if (iter != _owners.end())
{
auto component = iter->second;
component->beforeSimulation();
}
for (auto child : node->getChildren())
beforeSimulation(child);
}
void PhysicsManager::afterSimulation(Node *node)
{
auto iter = _owners.find(node);
if (iter != _owners.end())
{
auto component = iter->second;
component->afterSimulation();
}
for (auto child : node->getChildren())
afterSimulation(child);
}
void PhysicsManager::addPhysicsComponent(ComponentPhysics2d* componentPhsics2d)
{
// don't add component again
if (std::find(_components.begin(), _components.end(), componentPhsics2d) != _components.end())
return;
_components.push_back(componentPhsics2d);
// Node::getComponent<>() is a time comsuming operation, so record data to avoid invoking it.
std::pair<Node*, ComponentPhysics2d*> element(componentPhsics2d->getOwner(), componentPhsics2d);
_owners.insert(element);
if (nullptr != componentPhsics2d->getPhysicsBody())
_physicsWorld->addBody(componentPhsics2d->getPhysicsBody());
}
void PhysicsManager::removePhysicsComponent(ComponentPhysics2d* componentPhsics2d)
{
auto iter = std::find(_components.begin(), _components.end(), componentPhsics2d);
if (iter != _components.end())
{
removeElementFromMap(*iter);
_components.erase(iter);
if (componentPhsics2d->getPhysicsBody())
_physicsWorld->removeBody(componentPhsics2d->getPhysicsBody());
}
}
void PhysicsManager::removeElementFromMap(ComponentPhysics2d* component)
{
for (auto element : _owners)
{
if (element.second == component)
{
_owners.erase(element.first);
break;
}
}
}
PhysicsWorld* PhysicsManager::getPhysicsWorld() const
{
return _physicsWorld;
}
NS_CC_END
#endif // CC_USE_PHYSICS

View File

@ -0,0 +1,124 @@
/****************************************************************************
Copyright (c) 2015 Chukong Technologies Inc.
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#pragma once
#include "base/ccConfig.h" // to include defination of CC_USE_PHYSICS
#if CC_USE_PHYSICS
#include <vector>
#include <unordered_map>
#include "platform/CCPlatformMacros.h"
NS_CC_BEGIN
class ComponentPhysics2d;
class PhysicsWorld;
class Scene;
class Node;
/**
* @addtogroup physics
* @{
* @addtogroup physics_2d
* @{
*/
/**
* Now `PhysicsManager` belongs to a `Scene`. `Scene` will create `PhysicsManager` automatically.
* The reason to design like this are:
* - PhysicsManager keeps physics world, it is reasonale that a scene has its own physics world.
* It is useful that when a scene is active again, you don't have to create physics world and
* do all related things again.
* - Keep compatibility
*/
class CC_DLL PhysicsManager
{
public:
/// @cond DO_NOT_SHOW
/**
* Create a PhysicsManager with `Scene`. `Scene` will create it automatically,
* so don't create it yourself.
*
* @scene The scene this `PhysicsManager` belongs to.
*/
PhysicsManager(Scene *scene);
/**
* Destructor.
*/
~PhysicsManager();
/**
* Do physics simulation. It will do the following things:
* - synchronize Node's status(position, rotation, scale) to corresponding physics body
* - do physics simulation
* - synchronize physics body's status(position, rotation) to correspondind Node
*
* It is invoked by `Scene`, don't invoke it yourself.
*/
void update(float dt);
/// @endcond DO_NOT_SHOW
/**
* Get the physics world.
*
* @return Physics world managed by this `PhysicsManager`.
*/
PhysicsWorld* getPhysicsWorld() const;
/**
* Add a physics component to be managed by the `PhysicsManager`. Will register physics
* component's physics body to physics world managed by this `PhysicsManager`.
*
* @param componentPhsics2d The physics component to be managed by this `PhysicsManager`.
*/
void addPhysicsComponent(ComponentPhysics2d* componentPhsics2d);
/**
* Remove a physics component from `PhysiscsManager`. Will remove physics component's physics
* body from the physics world managed by this `PhysicsManager`.
*/
void removePhysicsComponent(ComponentPhysics2d* componentPhsics2d);
private:
void beforeSimulation(Node *node);
void afterSimulation(Node* node);
void removeElementFromMap(ComponentPhysics2d* component);
private:
std::vector<ComponentPhysics2d*> _components;
// record the owners of components for performance
std::unordered_map<Node*, ComponentPhysics2d*> _owners;
PhysicsWorld *_physicsWorld;
Scene *_scene;
};
/** @} */
/** @} */
NS_CC_END
#endif // CC_USE_PHYSICS

View File

@ -114,7 +114,7 @@ void PhysicsShape::setMaterial(const PhysicsMaterial& material)
void PhysicsShape::setScale(float scaleX, float scaleY) void PhysicsShape::setScale(float scaleX, float scaleY)
{ {
if (_scaleX != scaleX || _scaleY != scaleY) if (fabs(_scaleX - scaleX) > FLT_EPSILON || fabs(_scaleY - scaleY) > FLT_EPSILON)
{ {
if (_type == Type::CIRCLE && scaleX != scaleY) if (_type == Type::CIRCLE && scaleX != scaleY)
{ {
@ -123,7 +123,13 @@ void PhysicsShape::setScale(float scaleX, float scaleY)
} }
_newScaleX = scaleX; _newScaleX = scaleX;
_newScaleY = scaleY; _newScaleY = scaleY;
updateScale(); updateScale();
// re-calculate area and mass
_area = calculateArea();
_mass = _material.density * _area;
_moment = calculateDefaultMoment();
} }
} }
@ -649,10 +655,14 @@ void PhysicsShapePolygon::updateScale()
for (int i = 0; i < count; ++i) for (int i = 0; i < count; ++i)
{ {
cpVect n = cpvnormalize(cpvperp(cpvsub(vects[i], vects[(i + 1) % count]))); // cpVect n = cpvnormalize(cpvperp(cpvsub(vects[i], vects[(i + 1) % count])));
//
// planes[i].n = n;
// planes[i].d = cpvdot(n, vects[i]);
planes[i].n = n; // FIXED ME: if update 'planes[i]' as the above codes, then can not query polygon shape by PhysicsWorld::getShapes().
planes[i].d = cpvdot(n, vects[i]); // But modified like this, then ray test can not work correctly on some cases.
planes[i].d = cpvdot(planes[i].n, vects[i]);
} }
PhysicsShape::updateScale(); PhysicsShape::updateScale();

View File

@ -281,7 +281,7 @@ int PhysicsWorld::collisionBeginCallback(PhysicsContact& contact)
{ {
contact.setEventCode(PhysicsContact::EventCode::BEGIN); contact.setEventCode(PhysicsContact::EventCode::BEGIN);
contact.setWorld(this); contact.setWorld(this);
_scene->getEventDispatcher()->dispatchEvent(&contact); Director::getInstance()->getEventDispatcher()->dispatchEvent(&contact);
} }
return ret ? contact.resetResult() : false; return ret ? contact.resetResult() : false;
@ -296,7 +296,7 @@ int PhysicsWorld::collisionPreSolveCallback(PhysicsContact& contact)
contact.setEventCode(PhysicsContact::EventCode::PRESOLVE); contact.setEventCode(PhysicsContact::EventCode::PRESOLVE);
contact.setWorld(this); contact.setWorld(this);
_scene->getEventDispatcher()->dispatchEvent(&contact); Director::getInstance()->getEventDispatcher()->dispatchEvent(&contact);
return contact.resetResult(); return contact.resetResult();
} }
@ -310,7 +310,7 @@ void PhysicsWorld::collisionPostSolveCallback(PhysicsContact& contact)
contact.setEventCode(PhysicsContact::EventCode::POSTSOLVE); contact.setEventCode(PhysicsContact::EventCode::POSTSOLVE);
contact.setWorld(this); contact.setWorld(this);
_scene->getEventDispatcher()->dispatchEvent(&contact); Director::getInstance()->getEventDispatcher()->dispatchEvent(&contact);
} }
void PhysicsWorld::collisionSeparateCallback(PhysicsContact& contact) void PhysicsWorld::collisionSeparateCallback(PhysicsContact& contact)
@ -322,7 +322,7 @@ void PhysicsWorld::collisionSeparateCallback(PhysicsContact& contact)
contact.setEventCode(PhysicsContact::EventCode::SEPARATE); contact.setEventCode(PhysicsContact::EventCode::SEPARATE);
contact.setWorld(this); contact.setWorld(this);
_scene->getEventDispatcher()->dispatchEvent(&contact); Director::getInstance()->getEventDispatcher()->dispatchEvent(&contact);
} }
void PhysicsWorld::rayCast(PhysicsRayCastCallbackFunc func, const Vec2& point1, const Vec2& point2, void* data) void PhysicsWorld::rayCast(PhysicsRayCastCallbackFunc func, const Vec2& point1, const Vec2& point2, void* data)
@ -333,7 +333,6 @@ void PhysicsWorld::rayCast(PhysicsRayCastCallbackFunc func, const Vec2& point1,
{ {
if (!_delayAddBodies.empty() || !_delayRemoveBodies.empty()) if (!_delayAddBodies.empty() || !_delayRemoveBodies.empty())
{ {
_scene->updatePhysicsBodyTransform(_scene->getNodeToParentTransform(), 0, 1.0f, 1.0f);
updateBodies(); updateBodies();
} }
RayCastCallbackInfo info = { this, func, point1, point2, data }; RayCastCallbackInfo info = { this, func, point1, point2, data };
@ -357,7 +356,6 @@ void PhysicsWorld::queryRect(PhysicsQueryRectCallbackFunc func, const Rect& rect
{ {
if (!_delayAddBodies.empty() || !_delayRemoveBodies.empty()) if (!_delayAddBodies.empty() || !_delayRemoveBodies.empty())
{ {
_scene->updatePhysicsBodyTransform(_scene->getNodeToParentTransform(), 0, 1.0f, 1.0f);
updateBodies(); updateBodies();
} }
RectQueryCallbackInfo info = {this, func, data}; RectQueryCallbackInfo info = {this, func, data};
@ -380,7 +378,6 @@ void PhysicsWorld::queryPoint(PhysicsQueryPointCallbackFunc func, const Vec2& po
{ {
if (!_delayAddBodies.empty() || !_delayRemoveBodies.empty()) if (!_delayAddBodies.empty() || !_delayRemoveBodies.empty())
{ {
_scene->updatePhysicsBodyTransform(_scene->getNodeToParentTransform(), 0, 1.0f, 1.0f);
updateBodies(); updateBodies();
} }
PointQueryCallbackInfo info = {this, func, data}; PointQueryCallbackInfo info = {this, func, data};
@ -422,10 +419,10 @@ PhysicsShape* PhysicsWorld::getShape(const Vec2& point) const
return shape == nullptr ? nullptr : s_physicsShapeMap.find(shape)->second; return shape == nullptr ? nullptr : s_physicsShapeMap.find(shape)->second;
} }
PhysicsWorld* PhysicsWorld::construct(Scene& scene) PhysicsWorld* PhysicsWorld::construct()
{ {
PhysicsWorld * world = new (std::nothrow) PhysicsWorld(); PhysicsWorld * world = new (std::nothrow) PhysicsWorld();
if(world && world->init(scene)) if(world && world->init())
{ {
return world; return world;
} }
@ -434,15 +431,13 @@ PhysicsWorld* PhysicsWorld::construct(Scene& scene)
return nullptr; return nullptr;
} }
bool PhysicsWorld::init(Scene& scene) bool PhysicsWorld::init()
{ {
do do
{ {
_cpSpace = cpSpaceNew(); _cpSpace = cpSpaceNew();
CC_BREAK_IF(_cpSpace == nullptr); CC_BREAK_IF(_cpSpace == nullptr);
_scene = &scene;
cpSpaceSetGravity(_cpSpace, PhysicsHelper::point2cpv(_gravity)); cpSpaceSetGravity(_cpSpace, PhysicsHelper::point2cpv(_gravity));
cpSpaceSetDefaultCollisionHandler(_cpSpace, cpSpaceSetDefaultCollisionHandler(_cpSpace,
@ -817,11 +812,9 @@ void PhysicsWorld::step(float delta)
void PhysicsWorld::update(float delta, bool userCall/* = false*/) void PhysicsWorld::update(float delta, bool userCall/* = false*/)
{ {
if(_updateBodyTransform || !_delayAddBodies.empty()) if(!_delayAddBodies.empty())
{ {
_scene->updatePhysicsBodyTransform(_scene->getNodeToParentTransform(), 0, 1.0f, 1.0f);
updateBodies(); updateBodies();
_updateBodyTransform = false;
} }
else if (!_delayRemoveBodies.empty()) else if (!_delayRemoveBodies.empty())
{ {
@ -904,7 +897,7 @@ PhysicsDebugDraw::PhysicsDebugDraw(PhysicsWorld& world)
, _world(world) , _world(world)
{ {
_drawNode = DrawNode::create(); _drawNode = DrawNode::create();
_world.getScene().addChild(_drawNode); Director::getInstance()->getRunningScene()->addChild(_drawNode);
} }
PhysicsDebugDraw::~PhysicsDebugDraw() PhysicsDebugDraw::~PhysicsDebugDraw()

View File

@ -329,8 +329,9 @@ public:
void step(float delta); void step(float delta);
protected: protected:
static PhysicsWorld* construct(Scene& scene); static PhysicsWorld* construct();
bool init(Scene& scene); bool init();
virtual void addBody(PhysicsBody* body); virtual void addBody(PhysicsBody* body);
virtual void addShape(PhysicsShape* shape); virtual void addShape(PhysicsShape* shape);
@ -389,6 +390,7 @@ protected:
friend class PhysicsJoint; friend class PhysicsJoint;
friend class PhysicsWorldCallback; friend class PhysicsWorldCallback;
friend class PhysicsDebugDraw; friend class PhysicsDebugDraw;
friend class PhysicsManager;
}; };
/** A physics helper class. Draw physics shape, joint in debug mode. /** A physics helper class. Draw physics shape, joint in debug mode.

View File

@ -6,5 +6,6 @@ set(COCOS_PHYSICS_SRC
physics/CCPhysicsJoint.cpp physics/CCPhysicsJoint.cpp
physics/CCPhysicsShape.cpp physics/CCPhysicsShape.cpp
physics/CCPhysicsWorld.cpp physics/CCPhysicsWorld.cpp
physics/CCComponentPhysics2d.cpp
physics/CCPhysicsManager.cpp
) )

View File

@ -26,8 +26,11 @@ package org.cocos2dx.lib;
import android.content.Context; import android.content.Context;
import android.graphics.Color; import android.graphics.Color;
import android.graphics.Typeface;
import android.text.InputFilter; import android.text.InputFilter;
import android.text.InputType; import android.text.InputType;
import android.text.method.PasswordTransformationMethod;
import android.util.Log;
import android.view.Gravity; import android.view.Gravity;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.View; import android.view.View;
@ -106,6 +109,12 @@ public class Cocos2dxEditBox extends EditText {
private int mInputModeContraints; private int mInputModeContraints;
private int mMaxLength; private int mMaxLength;
//OpenGL view scaleX
private float mScaleX;
public Cocos2dxEditBox(Context context){ public Cocos2dxEditBox(Context context){
super(context); super(context);
} }
@ -121,6 +130,15 @@ public class Cocos2dxEditBox extends EditText {
this.setLayoutParams(layoutParams); this.setLayoutParams(layoutParams);
} }
public float getOpenGLViewScaleX() {
return mScaleX;
}
public void setOpenGLViewScaleX(float mScaleX) {
this.mScaleX = mScaleX;
}
public void setMaxLength(int maxLength){ public void setMaxLength(int maxLength){
this.mMaxLength = maxLength; this.mMaxLength = maxLength;
@ -210,6 +228,8 @@ public class Cocos2dxEditBox extends EditText {
switch (inputFlag) { switch (inputFlag) {
case kEditBoxInputFlagPassword: case kEditBoxInputFlagPassword:
this.mInputFlagConstraints = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD; this.mInputFlagConstraints = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD;
this.setTypeface(Typeface.DEFAULT);
this.setTransformationMethod(new PasswordTransformationMethod());
break; break;
case kEditBoxInputFlagSensitive: case kEditBoxInputFlagSensitive:
this.mInputFlagConstraints = InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS; this.mInputFlagConstraints = InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS;

View File

@ -75,8 +75,17 @@ public class Cocos2dxEditBoxHelper {
Cocos2dxEditBoxHelper.mEditBoxArray = new SparseArray<Cocos2dxEditBox>(); Cocos2dxEditBoxHelper.mEditBoxArray = new SparseArray<Cocos2dxEditBox>();
} }
public static int convertToSP(float point){
Resources r = mCocos2dxActivity.getResources();
public static int createEditBox(final int left, final int top, final int width, final int height) { int convertedValue = (int)TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_SP, point, r.getDisplayMetrics());
return convertedValue;
}
public static int createEditBox(final int left, final int top, final int width, final int height, final float scaleX) {
final int index = mViewTag; final int index = mViewTag;
mCocos2dxActivity.runOnUiThread(new Runnable() { mCocos2dxActivity.runOnUiThread(new Runnable() {
@Override @Override
@ -92,6 +101,17 @@ public class Cocos2dxEditBoxHelper {
editBox.setBackgroundColor(Color.TRANSPARENT); editBox.setBackgroundColor(Color.TRANSPARENT);
editBox.setTextColor(Color.WHITE); editBox.setTextColor(Color.WHITE);
editBox.setSingleLine(); editBox.setSingleLine();
editBox.setOpenGLViewScaleX(scaleX);
Resources r = mCocos2dxActivity.getResources();
float density = r.getDisplayMetrics().density;
int paddingBottom = (int)(height * 0.33f / density);
paddingBottom = convertToSP(paddingBottom - 5 * scaleX / density);
paddingBottom = paddingBottom / 2;
int paddingTop = paddingBottom;
int paddingLeft = (int)(5 * scaleX / density);
paddingLeft = convertToSP(paddingLeft);
editBox.setPadding(paddingLeft,paddingTop, 0, paddingBottom);
FrameLayout.LayoutParams lParams = new FrameLayout.LayoutParams( FrameLayout.LayoutParams lParams = new FrameLayout.LayoutParams(
@ -101,7 +121,7 @@ public class Cocos2dxEditBoxHelper {
lParams.leftMargin = left; lParams.leftMargin = left;
lParams.topMargin = top; lParams.topMargin = top;
lParams.width = width; lParams.width = width;
lParams.height = height+20; lParams.height = height;
lParams.gravity = Gravity.TOP | Gravity.LEFT; lParams.gravity = Gravity.TOP | Gravity.LEFT;
mFrameLayout.addView(editBox, lParams); mFrameLayout.addView(editBox, lParams);
@ -222,7 +242,10 @@ public class Cocos2dxEditBoxHelper {
} }
//TODO: The font size is not the same across all the anroid devices... //TODO: The font size is not the same across all the anroid devices...
if (fontSize >= 0){ if (fontSize >= 0){
editBox.setTextSize(TypedValue.COMPLEX_UNIT_SP, fontSize); float density = mCocos2dxActivity.getResources().getDisplayMetrics().density;
// Log.e("XXX", "density is " + density);
editBox.setTextSize(TypedValue.COMPLEX_UNIT_SP,
fontSize / density );
} }
editBox.setTypeface(tf); editBox.setTypeface(tf);
} }

View File

@ -390,12 +390,12 @@ void deleteValueForKeyJNI(const char* key)
} }
} }
int addEditBoxJNI(int left, int top, int width, int height){ int addEditBoxJNI(int left, int top, int width, int height, float scaleX){
JniMethodInfo t; JniMethodInfo t;
int ret = -1; int ret = -1;
if (JniHelper::getStaticMethodInfo(t, EDITBOX_CLASS_NAME, "createEditBox", "(IIII)I")) { if (JniHelper::getStaticMethodInfo(t, EDITBOX_CLASS_NAME, "createEditBox", "(IIIIF)I")) {
ret = t.env->CallStaticIntMethod(t.classID, t.methodID, left, top, width, height); ret = t.env->CallStaticIntMethod(t.classID, t.methodID, left, top, width, height, scaleX);
t.env->DeleteLocalRef(t.classID); t.env->DeleteLocalRef(t.classID);
} }
return ret; return ret;

View File

@ -55,7 +55,7 @@ extern void setStringForKeyJNI(const char* key, const char* value);
extern void deleteValueForKeyJNI(const char* key); extern void deleteValueForKeyJNI(const char* key);
extern void conversionEncodingJNI(const char* src, int byteSize, const char* fromCharset, char* dst, const char* newCharset); extern void conversionEncodingJNI(const char* src, int byteSize, const char* fromCharset, char* dst, const char* newCharset);
//Added for new Android EditBox //Added for new Android EditBox
extern int addEditBoxJNI(int left, int top, int width, int height); extern int addEditBoxJNI(int left, int top, int width, int height, float scaleX);
extern void removeEditBoxJNI(int index); extern void removeEditBoxJNI(int index);
extern void setEditBoxViewRectJNI(int index, int left, int top, int width, int height); extern void setEditBoxViewRectJNI(int index, int left, int top, int width, int height);
extern void setMaxLengthJNI(int index, int maxLength); extern void setMaxLengthJNI(int index, int maxLength);

View File

@ -456,7 +456,7 @@ void FrameBuffer::applyFBO()
CHECK_GL_ERROR_DEBUG(); CHECK_GL_ERROR_DEBUG();
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, nullptr == _rtDepthStencil ? 0 : _rtDepthStencil->getBuffer()); glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, nullptr == _rtDepthStencil ? 0 : _rtDepthStencil->getBuffer());
CHECK_GL_ERROR_DEBUG(); CHECK_GL_ERROR_DEBUG();
CCLOG("FBO is %d _fbo %d color, %d ds", _fbo, RenderTargetBase::Type::Texture2D == _rt->getType() ? _rt->getTexture()->getName() : _rt->getBuffer(), _rtDepthStencil->getBuffer()); CCLOG("FBO is %d _fbo %d color, %d ds", _fbo, RenderTargetBase::Type::Texture2D == _rt->getType() ? _rt->getTexture()->getName() : _rt->getBuffer(), nullptr == _rtDepthStencil ? 0 : _rtDepthStencil->getBuffer());
_fboBindingDirty = false; _fboBindingDirty = false;
} }
if(GL_FRAMEBUFFER_COMPLETE != glCheckFramebufferStatus(GL_FRAMEBUFFER)) if(GL_FRAMEBUFFER_COMPLETE != glCheckFramebufferStatus(GL_FRAMEBUFFER))

View File

@ -501,6 +501,7 @@ ssize_t Material::getTechniqueCount() const
return _techniques.size(); return _techniques.size();
} }
// Helpers implementation // Helpers implementation
static bool isValidUniform(const char* name) static bool isValidUniform(const char* name)
{ {

View File

@ -62,7 +62,6 @@ class CC_DLL Material : public RenderState
friend class Mesh; friend class Mesh;
public: public:
/** /**
* Creates a Material using the data from the Properties object defined at the specified URL, * Creates a Material using the data from the Properties object defined at the specified URL,
* where the URL is of the format "<file-path>.<extension>#<namespace-id>/<namespace-id>/.../<namespace-id>" * where the URL is of the format "<file-path>.<extension>#<namespace-id>/<namespace-id>/.../<namespace-id>"
@ -139,6 +138,7 @@ protected:
bool parseUniform(GLProgramState* programState, Properties* properties, const char* uniformName); bool parseUniform(GLProgramState* programState, Properties* properties, const char* uniformName);
bool parseRenderState(RenderState* renderState, Properties* properties); bool parseRenderState(RenderState* renderState, Properties* properties);
// material name // material name
std::string _name; std::string _name;
@ -150,7 +150,6 @@ protected:
// weak reference // weak reference
Node* _target; Node* _target;
}; };
NS_CC_END NS_CC_END

View File

@ -521,6 +521,77 @@ EventTouch : function (
}; };
/**
* @class ComponentContainer
*/
cc.ComponentContainer = {
/**
* @method visit
* @param {float} arg0
*/
visit : function (
float
)
{
},
/**
* @method remove
* @param {cc.Component|String} component
* @return {bool|bool}
*/
remove : function(
str
)
{
return false;
},
/**
* @method removeAll
*/
removeAll : function (
)
{
},
/**
* @method add
* @param {cc.Component} arg0
* @return {bool}
*/
add : function (
component
)
{
return false;
},
/**
* @method isEmpty
* @return {bool}
*/
isEmpty : function (
)
{
return false;
},
/**
* @method get
* @param {String} arg0
* @return {cc.Component}
*/
get : function (
str
)
{
return cc.Component;
},
};
/** /**
* @class Node * @class Node
*/ */
@ -552,16 +623,6 @@ str
return false; return false;
}, },
/**
* @method setPhysicsBody
* @param {cc.PhysicsBody} arg0
*/
setPhysicsBody : function (
physicsbody
)
{
},
/** /**
* @method getGLProgram * @method getGLProgram
* @return {cc.GLProgram} * @return {cc.GLProgram}
@ -572,18 +633,6 @@ getGLProgram : function (
return cc.GLProgram; return cc.GLProgram;
}, },
/**
* @method updateTransformFromPhysics
* @param {mat4_object} arg0
* @param {unsigned int} arg1
*/
updateTransformFromPhysics : function (
mat4,
int
)
{
},
/** /**
* @method getDescription * @method getDescription
* @return {String} * @return {String}
@ -746,14 +795,6 @@ func
{ {
}, },
/**
* @method removeFromPhysicsWorld
*/
removeFromPhysicsWorld : function (
)
{
},
/** /**
* @method removeAllComponents * @method removeAllComponents
*/ */
@ -804,16 +845,6 @@ getonEnterTransitionDidFinishCallback : function (
return std::function<void ()>; return std::function<void ()>;
}, },
/**
* @method isOpacityModifyRGB
* @return {bool}
*/
isOpacityModifyRGB : function (
)
{
return false;
},
/** /**
* @method getNodeToWorldAffineTransform * @method getNodeToWorldAffineTransform
* @return {cc.AffineTransform} * @return {cc.AffineTransform}
@ -1053,13 +1084,13 @@ getOnEnterCallback : function (
}, },
/** /**
* @method getPhysicsBody * @method isOpacityModifyRGB
* @return {cc.PhysicsBody} * @return {bool}
*/ */
getPhysicsBody : function ( isOpacityModifyRGB : function (
) )
{ {
return cc.PhysicsBody; return false;
}, },
/** /**
@ -1418,22 +1449,6 @@ str
{ {
}, },
/**
* @method updatePhysicsBodyTransform
* @param {mat4_object} arg0
* @param {unsigned int} arg1
* @param {float} arg2
* @param {float} arg3
*/
updatePhysicsBodyTransform : function (
mat4,
int,
float,
float
)
{
},
/** /**
* @method getDisplayedOpacity * @method getDisplayedOpacity
* @return {unsigned char} * @return {unsigned char}
@ -2051,6 +2066,16 @@ eventcustom
{ {
}, },
/**
* @method getPhysicsManager
* @return {cc.PhysicsManager}
*/
getPhysicsManager : function (
)
{
return cc.PhysicsManager;
},
/** /**
* @method initWithSize * @method initWithSize
* @param {size_object} arg0 * @param {size_object} arg0
@ -20670,6 +20695,102 @@ TextureCache : function (
}; };
/**
* @class Component
*/
cc.Component = {
/**
* @method setEnabled
* @param {bool} arg0
*/
setEnabled : function (
bool
)
{
},
/**
* @method setName
* @param {String} arg0
*/
setName : function (
str
)
{
},
/**
* @method isEnabled
* @return {bool}
*/
isEnabled : function (
)
{
return false;
},
/**
* @method getOwner
* @return {cc.Node}
*/
getOwner : function (
)
{
return cc.Node;
},
/**
* @method init
* @return {bool}
*/
init : function (
)
{
return false;
},
/**
* @method getName
* @return {String}
*/
getName : function (
)
{
return ;
},
/**
* @method setOwner
* @param {cc.Node} arg0
*/
setOwner : function (
node
)
{
},
/**
* @method create
* @return {cc.Component}
*/
create : function (
)
{
return cc.Component;
},
/**
* @method Component
* @constructor
*/
Component : function (
)
{
},
};
/** /**
* @class Device * @class Device
*/ */
@ -22672,173 +22793,6 @@ TileMapAtlas : function (
}; };
/**
* @class Component
*/
cc.Component = {
/**
* @method setEnabled
* @param {bool} arg0
*/
setEnabled : function (
bool
)
{
},
/**
* @method setName
* @param {String} arg0
*/
setName : function (
str
)
{
},
/**
* @method isEnabled
* @return {bool}
*/
isEnabled : function (
)
{
return false;
},
/**
* @method getOwner
* @return {cc.Node}
*/
getOwner : function (
)
{
return cc.Node;
},
/**
* @method init
* @return {bool}
*/
init : function (
)
{
return false;
},
/**
* @method getName
* @return {String}
*/
getName : function (
)
{
return ;
},
/**
* @method setOwner
* @param {cc.Node} arg0
*/
setOwner : function (
node
)
{
},
/**
* @method create
* @return {cc.Component}
*/
create : function (
)
{
return cc.Component;
},
/**
* @method Component
* @constructor
*/
Component : function (
)
{
},
};
/**
* @class ComponentContainer
*/
cc.ComponentContainer = {
/**
* @method visit
* @param {float} arg0
*/
visit : function (
float
)
{
},
/**
* @method remove
* @param {cc.Component|String} component
* @return {bool|bool}
*/
remove : function(
str
)
{
return false;
},
/**
* @method removeAll
*/
removeAll : function (
)
{
},
/**
* @method add
* @param {cc.Component} arg0
* @return {bool}
*/
add : function (
component
)
{
return false;
},
/**
* @method isEmpty
* @return {bool}
*/
isEmpty : function (
)
{
return false;
},
/**
* @method get
* @param {String} arg0
* @return {cc.Component}
*/
get : function (
str
)
{
return cc.Component;
},
};
/** /**
* @class SimpleAudioEngine * @class SimpleAudioEngine
*/ */

File diff suppressed because it is too large Load Diff

View File

@ -84,6 +84,20 @@ bool js_cocos2dx_EventTouch_getEventCode(JSContext *cx, uint32_t argc, jsval *vp
bool js_cocos2dx_EventTouch_setEventCode(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_EventTouch_setEventCode(JSContext *cx, uint32_t argc, jsval *vp);
bool js_cocos2dx_EventTouch_EventTouch(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_EventTouch_EventTouch(JSContext *cx, uint32_t argc, jsval *vp);
extern JSClass *jsb_cocos2d_ComponentContainer_class;
extern JSObject *jsb_cocos2d_ComponentContainer_prototype;
bool js_cocos2dx_ComponentContainer_constructor(JSContext *cx, uint32_t argc, jsval *vp);
void js_cocos2dx_ComponentContainer_finalize(JSContext *cx, JSObject *obj);
void js_register_cocos2dx_ComponentContainer(JSContext *cx, JS::HandleObject global);
void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj);
bool js_cocos2dx_ComponentContainer_visit(JSContext *cx, uint32_t argc, jsval *vp);
bool js_cocos2dx_ComponentContainer_remove(JSContext *cx, uint32_t argc, jsval *vp);
bool js_cocos2dx_ComponentContainer_removeAll(JSContext *cx, uint32_t argc, jsval *vp);
bool js_cocos2dx_ComponentContainer_add(JSContext *cx, uint32_t argc, jsval *vp);
bool js_cocos2dx_ComponentContainer_isEmpty(JSContext *cx, uint32_t argc, jsval *vp);
bool js_cocos2dx_ComponentContainer_get(JSContext *cx, uint32_t argc, jsval *vp);
extern JSClass *jsb_cocos2d_Node_class; extern JSClass *jsb_cocos2d_Node_class;
extern JSObject *jsb_cocos2d_Node_prototype; extern JSObject *jsb_cocos2d_Node_prototype;
@ -93,9 +107,7 @@ void js_register_cocos2dx_Node(JSContext *cx, JS::HandleObject global);
void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj);
bool js_cocos2dx_Node_addChild(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Node_addChild(JSContext *cx, uint32_t argc, jsval *vp);
bool js_cocos2dx_Node_removeComponent(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Node_removeComponent(JSContext *cx, uint32_t argc, jsval *vp);
bool js_cocos2dx_Node_setPhysicsBody(JSContext *cx, uint32_t argc, jsval *vp);
bool js_cocos2dx_Node_getGLProgram(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Node_getGLProgram(JSContext *cx, uint32_t argc, jsval *vp);
bool js_cocos2dx_Node_updateTransformFromPhysics(JSContext *cx, uint32_t argc, jsval *vp);
bool js_cocos2dx_Node_getDescription(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Node_getDescription(JSContext *cx, uint32_t argc, jsval *vp);
bool js_cocos2dx_Node_setOpacityModifyRGB(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Node_setOpacityModifyRGB(JSContext *cx, uint32_t argc, jsval *vp);
bool js_cocos2dx_Node_setCascadeOpacityEnabled(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Node_setCascadeOpacityEnabled(JSContext *cx, uint32_t argc, jsval *vp);
@ -112,13 +124,11 @@ bool js_cocos2dx_Node_setScaleY(JSContext *cx, uint32_t argc, jsval *vp);
bool js_cocos2dx_Node_setScaleX(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Node_setScaleX(JSContext *cx, uint32_t argc, jsval *vp);
bool js_cocos2dx_Node_getColor(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Node_getColor(JSContext *cx, uint32_t argc, jsval *vp);
bool js_cocos2dx_Node_setonEnterTransitionDidFinishCallback(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Node_setonEnterTransitionDidFinishCallback(JSContext *cx, uint32_t argc, jsval *vp);
bool js_cocos2dx_Node_removeFromPhysicsWorld(JSContext *cx, uint32_t argc, jsval *vp);
bool js_cocos2dx_Node_removeAllComponents(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Node_removeAllComponents(JSContext *cx, uint32_t argc, jsval *vp);
bool js_cocos2dx_Node_getOpacity(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Node_getOpacity(JSContext *cx, uint32_t argc, jsval *vp);
bool js_cocos2dx_Node_setCameraMask(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Node_setCameraMask(JSContext *cx, uint32_t argc, jsval *vp);
bool js_cocos2dx_Node_getTag(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Node_getTag(JSContext *cx, uint32_t argc, jsval *vp);
bool js_cocos2dx_Node_getonEnterTransitionDidFinishCallback(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Node_getonEnterTransitionDidFinishCallback(JSContext *cx, uint32_t argc, jsval *vp);
bool js_cocos2dx_Node_isOpacityModifyRGB(JSContext *cx, uint32_t argc, jsval *vp);
bool js_cocos2dx_Node_getNodeToWorldAffineTransform(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Node_getNodeToWorldAffineTransform(JSContext *cx, uint32_t argc, jsval *vp);
bool js_cocos2dx_Node_getPosition3D(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Node_getPosition3D(JSContext *cx, uint32_t argc, jsval *vp);
bool js_cocos2dx_Node_removeChild(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Node_removeChild(JSContext *cx, uint32_t argc, jsval *vp);
@ -142,7 +152,7 @@ bool js_cocos2dx_Node_getRotation3D(JSContext *cx, uint32_t argc, jsval *vp);
bool js_cocos2dx_Node_getNodeToParentAffineTransform(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Node_getNodeToParentAffineTransform(JSContext *cx, uint32_t argc, jsval *vp);
bool js_cocos2dx_Node_convertTouchToNodeSpaceAR(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Node_convertTouchToNodeSpaceAR(JSContext *cx, uint32_t argc, jsval *vp);
bool js_cocos2dx_Node_getOnEnterCallback(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Node_getOnEnterCallback(JSContext *cx, uint32_t argc, jsval *vp);
bool js_cocos2dx_Node_getPhysicsBody(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Node_isOpacityModifyRGB(JSContext *cx, uint32_t argc, jsval *vp);
bool js_cocos2dx_Node_stopActionByTag(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Node_stopActionByTag(JSContext *cx, uint32_t argc, jsval *vp);
bool js_cocos2dx_Node_reorderChild(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Node_reorderChild(JSContext *cx, uint32_t argc, jsval *vp);
bool js_cocos2dx_Node_ignoreAnchorPointForPosition(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Node_ignoreAnchorPointForPosition(JSContext *cx, uint32_t argc, jsval *vp);
@ -177,7 +187,6 @@ bool js_cocos2dx_Node_getActionByTag(JSContext *cx, uint32_t argc, jsval *vp);
bool js_cocos2dx_Node_setRotationSkewX(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Node_setRotationSkewX(JSContext *cx, uint32_t argc, jsval *vp);
bool js_cocos2dx_Node_setRotationSkewY(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Node_setRotationSkewY(JSContext *cx, uint32_t argc, jsval *vp);
bool js_cocos2dx_Node_setName(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Node_setName(JSContext *cx, uint32_t argc, jsval *vp);
bool js_cocos2dx_Node_updatePhysicsBodyTransform(JSContext *cx, uint32_t argc, jsval *vp);
bool js_cocos2dx_Node_getDisplayedOpacity(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Node_getDisplayedOpacity(JSContext *cx, uint32_t argc, jsval *vp);
bool js_cocos2dx_Node_getLocalZOrder(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Node_getLocalZOrder(JSContext *cx, uint32_t argc, jsval *vp);
bool js_cocos2dx_Node_getScheduler(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Node_getScheduler(JSContext *cx, uint32_t argc, jsval *vp);
@ -253,6 +262,7 @@ bool js_cocos2dx_Scene_setCameraOrderDirty(JSContext *cx, uint32_t argc, jsval *
bool js_cocos2dx_Scene_render(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Scene_render(JSContext *cx, uint32_t argc, jsval *vp);
bool js_cocos2dx_Scene_stepPhysicsAndNavigation(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Scene_stepPhysicsAndNavigation(JSContext *cx, uint32_t argc, jsval *vp);
bool js_cocos2dx_Scene_onProjectionChanged(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Scene_onProjectionChanged(JSContext *cx, uint32_t argc, jsval *vp);
bool js_cocos2dx_Scene_getPhysicsManager(JSContext *cx, uint32_t argc, jsval *vp);
bool js_cocos2dx_Scene_initWithSize(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Scene_initWithSize(JSContext *cx, uint32_t argc, jsval *vp);
bool js_cocos2dx_Scene_getDefaultCamera(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Scene_getDefaultCamera(JSContext *cx, uint32_t argc, jsval *vp);
bool js_cocos2dx_Scene_createWithSize(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Scene_createWithSize(JSContext *cx, uint32_t argc, jsval *vp);
@ -3692,6 +3702,23 @@ bool js_cocos2dx_TextureCache_removeTexture(JSContext *cx, uint32_t argc, jsval
bool js_cocos2dx_TextureCache_waitForQuit(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_TextureCache_waitForQuit(JSContext *cx, uint32_t argc, jsval *vp);
bool js_cocos2dx_TextureCache_TextureCache(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_TextureCache_TextureCache(JSContext *cx, uint32_t argc, jsval *vp);
extern JSClass *jsb_cocos2d_Component_class;
extern JSObject *jsb_cocos2d_Component_prototype;
bool js_cocos2dx_Component_constructor(JSContext *cx, uint32_t argc, jsval *vp);
void js_cocos2dx_Component_finalize(JSContext *cx, JSObject *obj);
void js_register_cocos2dx_Component(JSContext *cx, JS::HandleObject global);
void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj);
bool js_cocos2dx_Component_setEnabled(JSContext *cx, uint32_t argc, jsval *vp);
bool js_cocos2dx_Component_setName(JSContext *cx, uint32_t argc, jsval *vp);
bool js_cocos2dx_Component_isEnabled(JSContext *cx, uint32_t argc, jsval *vp);
bool js_cocos2dx_Component_getOwner(JSContext *cx, uint32_t argc, jsval *vp);
bool js_cocos2dx_Component_init(JSContext *cx, uint32_t argc, jsval *vp);
bool js_cocos2dx_Component_getName(JSContext *cx, uint32_t argc, jsval *vp);
bool js_cocos2dx_Component_setOwner(JSContext *cx, uint32_t argc, jsval *vp);
bool js_cocos2dx_Component_create(JSContext *cx, uint32_t argc, jsval *vp);
bool js_cocos2dx_Component_Component(JSContext *cx, uint32_t argc, jsval *vp);
extern JSClass *jsb_cocos2d_Device_class; extern JSClass *jsb_cocos2d_Device_class;
extern JSObject *jsb_cocos2d_Device_prototype; extern JSObject *jsb_cocos2d_Device_prototype;
@ -3987,37 +4014,6 @@ bool js_cocos2dx_TileMapAtlas_setTGAInfo(JSContext *cx, uint32_t argc, jsval *vp
bool js_cocos2dx_TileMapAtlas_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_TileMapAtlas_create(JSContext *cx, uint32_t argc, jsval *vp);
bool js_cocos2dx_TileMapAtlas_TileMapAtlas(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_TileMapAtlas_TileMapAtlas(JSContext *cx, uint32_t argc, jsval *vp);
extern JSClass *jsb_cocos2d_Component_class;
extern JSObject *jsb_cocos2d_Component_prototype;
bool js_cocos2dx_Component_constructor(JSContext *cx, uint32_t argc, jsval *vp);
void js_cocos2dx_Component_finalize(JSContext *cx, JSObject *obj);
void js_register_cocos2dx_Component(JSContext *cx, JS::HandleObject global);
void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj);
bool js_cocos2dx_Component_setEnabled(JSContext *cx, uint32_t argc, jsval *vp);
bool js_cocos2dx_Component_setName(JSContext *cx, uint32_t argc, jsval *vp);
bool js_cocos2dx_Component_isEnabled(JSContext *cx, uint32_t argc, jsval *vp);
bool js_cocos2dx_Component_getOwner(JSContext *cx, uint32_t argc, jsval *vp);
bool js_cocos2dx_Component_init(JSContext *cx, uint32_t argc, jsval *vp);
bool js_cocos2dx_Component_getName(JSContext *cx, uint32_t argc, jsval *vp);
bool js_cocos2dx_Component_setOwner(JSContext *cx, uint32_t argc, jsval *vp);
bool js_cocos2dx_Component_create(JSContext *cx, uint32_t argc, jsval *vp);
bool js_cocos2dx_Component_Component(JSContext *cx, uint32_t argc, jsval *vp);
extern JSClass *jsb_cocos2d_ComponentContainer_class;
extern JSObject *jsb_cocos2d_ComponentContainer_prototype;
bool js_cocos2dx_ComponentContainer_constructor(JSContext *cx, uint32_t argc, jsval *vp);
void js_cocos2dx_ComponentContainer_finalize(JSContext *cx, JSObject *obj);
void js_register_cocos2dx_ComponentContainer(JSContext *cx, JS::HandleObject global);
void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj);
bool js_cocos2dx_ComponentContainer_visit(JSContext *cx, uint32_t argc, jsval *vp);
bool js_cocos2dx_ComponentContainer_remove(JSContext *cx, uint32_t argc, jsval *vp);
bool js_cocos2dx_ComponentContainer_removeAll(JSContext *cx, uint32_t argc, jsval *vp);
bool js_cocos2dx_ComponentContainer_add(JSContext *cx, uint32_t argc, jsval *vp);
bool js_cocos2dx_ComponentContainer_isEmpty(JSContext *cx, uint32_t argc, jsval *vp);
bool js_cocos2dx_ComponentContainer_get(JSContext *cx, uint32_t argc, jsval *vp);
extern JSClass *jsb_CocosDenshion_SimpleAudioEngine_class; extern JSClass *jsb_CocosDenshion_SimpleAudioEngine_class;
extern JSObject *jsb_CocosDenshion_SimpleAudioEngine_prototype; extern JSObject *jsb_CocosDenshion_SimpleAudioEngine_prototype;

View File

@ -33,6 +33,7 @@
#include "cocos2d_specifics.hpp" #include "cocos2d_specifics.hpp"
#include "jsb_cocos2dx_auto.hpp" #include "jsb_cocos2dx_auto.hpp"
#include "js_bindings_config.h" #include "js_bindings_config.h"
// for debug socket // for debug socket
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 || CC_TARGET_PLATFORM == CC_PLATFORM_WINRT) #if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 || CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
#include <io.h> #include <io.h>
@ -452,6 +453,14 @@ static const JSClass global_class = {
JS_GlobalObjectTraceHook JS_GlobalObjectTraceHook
}; };
ScriptingCore* ScriptingCore::getInstance()
{
static ScriptingCore* instance = nullptr;
if (instance == nullptr)
instance = new ScriptingCore();
return instance;
}
ScriptingCore::ScriptingCore() ScriptingCore::ScriptingCore()
: _rt(nullptr) : _rt(nullptr)
@ -985,6 +994,35 @@ bool ScriptingCore::isFunctionOverridedInJS(JS::HandleObject obj, const std::str
return false; return false;
} }
int ScriptingCore::handleActionEvent(void* data)
{
if (NULL == data)
return 0;
ActionObjectScriptData* actionObjectScriptData = static_cast<ActionObjectScriptData*>(data);
if (NULL == actionObjectScriptData->nativeObject || NULL == actionObjectScriptData->eventType)
return 0;
Action* actionObject = static_cast<Action*>(actionObjectScriptData->nativeObject);
int eventType = *((int*)(actionObjectScriptData->eventType));
js_proxy_t * p = jsb_get_native_proxy(actionObject);
if (!p) return 0;
int ret = 0;
JS::RootedValue retval(_cx);
if (eventType == kActionUpdate)
{
if (isFunctionOverridedInJS(JS::RootedObject(_cx, p->obj.get()), "update", js_cocos2dx_Action_update))
{
jsval dataVal = DOUBLE_TO_JSVAL(*((float *)actionObjectScriptData->param));
ret = executeFunctionWithOwner(OBJECT_TO_JSVAL(p->obj), "update", 1, &dataVal, &retval);
}
}
return ret;
}
int ScriptingCore::handleNodeEvent(void* data) int ScriptingCore::handleNodeEvent(void* data)
{ {
if (NULL == data) if (NULL == data)
@ -1456,6 +1494,11 @@ int ScriptingCore::sendEvent(ScriptEvent* evt)
return handleNodeEvent(evt->data); return handleNodeEvent(evt->data);
} }
break; break;
case kScriptActionEvent:
{
return handleActionEvent(evt->data);
}
break;
case kMenuClickedEvent: case kMenuClickedEvent:
break; break;
case kTouchEvent: case kTouchEvent:

View File

@ -70,13 +70,7 @@ private:
public: public:
~ScriptingCore(); ~ScriptingCore();
static ScriptingCore *getInstance() { static ScriptingCore *getInstance();
static ScriptingCore* pInstance = NULL;
if (pInstance == NULL) {
pInstance = new ScriptingCore();
}
return pInstance;
};
virtual cocos2d::ccScriptType getScriptType() { return cocos2d::kScriptTypeJavascript; }; virtual cocos2d::ccScriptType getScriptType() { return cocos2d::kScriptTypeJavascript; };
@ -263,6 +257,7 @@ private:
public: public:
int handleNodeEvent(void* data); int handleNodeEvent(void* data);
int handleActionEvent(void* data);
int handleComponentEvent(void* data); int handleComponentEvent(void* data);
bool handleTouchesEvent(void* nativeObj, cocos2d::EventTouch::EventCode eventCode, const std::vector<cocos2d::Touch*>& touches, cocos2d::Event* event); bool handleTouchesEvent(void* nativeObj, cocos2d::EventTouch::EventCode eventCode, const std::vector<cocos2d::Touch*>& touches, cocos2d::Event* event);

View File

@ -2182,6 +2182,21 @@ jsval quaternion_to_jsval(JSContext* cx, const cocos2d::Quaternion& q)
return JSVAL_NULL; return JSVAL_NULL;
} }
jsval uniform_to_jsval(JSContext* cx, const cocos2d::Uniform* uniform)
{
JS::RootedObject tmp(cx, JS_NewObject(cx, nullptr, JS::NullPtr(), JS::NullPtr()));
if(!tmp) return JSVAL_NULL;
bool ok = JS_DefineProperty(cx, tmp, "location", uniform->location, JSPROP_ENUMERATE | JSPROP_PERMANENT) &&
JS_DefineProperty(cx, tmp, "size", uniform->size, JSPROP_ENUMERATE | JSPROP_PERMANENT) &&
JS_DefineProperty(cx, tmp, "type", uniform->type, JSPROP_ENUMERATE | JSPROP_PERMANENT) &&
JS_DefineProperty(cx, tmp, "name", JS::RootedValue(cx, std_string_to_jsval(cx, uniform->name)), JSPROP_ENUMERATE | JSPROP_PERMANENT);
if(ok)
return OBJECT_TO_JSVAL(tmp);
return JSVAL_NULL;
}
jsval meshVertexAttrib_to_jsval(JSContext* cx, const cocos2d::MeshVertexAttrib& q) jsval meshVertexAttrib_to_jsval(JSContext* cx, const cocos2d::MeshVertexAttrib& q)
{ {
JS::RootedObject tmp(cx, JS_NewObject(cx, nullptr, JS::NullPtr(), JS::NullPtr())); JS::RootedObject tmp(cx, JS_NewObject(cx, nullptr, JS::NullPtr(), JS::NullPtr()));

View File

@ -271,6 +271,7 @@ jsval ccaffinetransform_to_jsval(JSContext* cx, const cocos2d::AffineTransform&
jsval FontDefinition_to_jsval(JSContext* cx, const cocos2d::FontDefinition& t); jsval FontDefinition_to_jsval(JSContext* cx, const cocos2d::FontDefinition& t);
jsval quaternion_to_jsval(JSContext* cx, const cocos2d::Quaternion& q); jsval quaternion_to_jsval(JSContext* cx, const cocos2d::Quaternion& q);
jsval meshVertexAttrib_to_jsval(JSContext* cx, const cocos2d::MeshVertexAttrib& q); jsval meshVertexAttrib_to_jsval(JSContext* cx, const cocos2d::MeshVertexAttrib& q);
jsval uniform_to_jsval(JSContext* cx, const cocos2d::Uniform* uniform);
template<class T> template<class T>
js_proxy_t *js_get_or_create_proxy(JSContext *cx, T *native_obj); js_proxy_t *js_get_or_create_proxy(JSContext *cx, T *native_obj);

View File

@ -786,6 +786,7 @@ cc.view.setDesignResolutionSize = function(width,height,resolutionPolicy){
cc.winSize = cc.director.getWinSize(); cc.winSize = cc.director.getWinSize();
cc.visibleRect.init(); cc.visibleRect.init();
}; };
cc.view.setRealPixelResolution = cc.view.setDesignResolutionSize;
cc.view.setResolutionPolicy = function(resolutionPolicy){ cc.view.setResolutionPolicy = function(resolutionPolicy){
var size = cc.view.getDesignResolutionSize(); var size = cc.view.getDesignResolutionSize();
cc.view.setDesignResolutionSize(size.width,size.height,resolutionPolicy); cc.view.setDesignResolutionSize(size.width,size.height,resolutionPolicy);
@ -816,6 +817,10 @@ cc.audioEngine.end = function(){
this.stopMusic(); this.stopMusic();
this.stopAllEffects(); this.stopAllEffects();
}; };
cc.audioEngine.features = {
MULTI_CHANNEL: true,
AUTOPLAY: true
};
/** /**
* @type {Object} * @type {Object}
* @name cc.configuration * @name cc.configuration
@ -1365,8 +1370,18 @@ cc._initSys = function(config, CONFIG_KEY){
} }
})(); })();
/**
* Indicate the real pixel resolution of the whole game window
* @memberof cc.sys
* @name windowPixelResolution
* @type {Number}
*/
locSys.windowPixelResolution = cc.view.getFrameSize();
/** The type of browser */ /** The type of browser */
locSys.browserType = null;//null in jsb locSys.browserType = null; //null in jsb
/** The version of browser */
locSys.browserVersion = null; //null in jsb
capabilities = locSys.capabilities = {"opengl":true}; capabilities = locSys.capabilities = {"opengl":true};
if( locSys.isMobile ) { if( locSys.isMobile ) {

View File

@ -1276,49 +1276,6 @@ cc.defineGetterSetter(_proto, "ORANGE", _proto._getOrange);
_proto.GRAY; _proto.GRAY;
cc.defineGetterSetter(_proto, "GRAY", _proto._getGray); cc.defineGetterSetter(_proto, "GRAY", _proto._getGray);
// Extends
cc.Node.extend = cc.Class.extend;
cc.AtlasNode.extend = cc.Class.extend;
cc.Layer.extend = cc.Class.extend;
cc.LayerGradient.extend = cc.Class.extend;
cc.LayerColor.extend = cc.Class.extend;
cc.LayerMultiplex.extend = cc.Class.extend;
cc.Sprite.extend = cc.Class.extend;
cc.SpriteBatchNode.extend = cc.Class.extend;
cc.SpriteFrame.extend = cc.Class.extend;
cc.LabelTTF.extend = cc.Class.extend;
cc.LabelBMFont.extend = cc.Class.extend;
cc.LabelAtlas.extend = cc.Class.extend;
cc.Menu.extend = cc.Class.extend;
cc.MenuItem.extend = cc.Class.extend;
cc.MenuItemLabel.extend = cc.Class.extend;
cc.MenuItemFont.extend = cc.Class.extend;
cc.MenuItemAtlasFont.extend = cc.Class.extend;
cc.MenuItemSprite.extend = cc.Class.extend;
cc.MenuItemImage.extend = cc.Class.extend;
cc.MenuItemToggle.extend = cc.Class.extend;
cc.Scene.extend = cc.Class.extend;
cc.ClippingNode.extend = cc.Class.extend;
cc.ProgressTimer.extend = cc.Class.extend;
cc.ParallaxNode.extend = cc.Class.extend;
cc.DrawNode.extend = cc.Class.extend;
cc.Component.extend = cc.Class.extend;
cc.GridBase.extend = cc.Class.extend;
cc.Grid3D.extend = cc.Class.extend;
cc.TiledGrid3D.extend = cc.Class.extend;
cc.MotionStreak.extend = cc.Class.extend;
cc.ParticleBatchNode.extend = cc.Class.extend;
cc.ParticleSystem.extend = cc.Class.extend;
cc.TextFieldTTF.extend = cc.Class.extend;
cc.RenderTexture.extend = cc.Class.extend;
cc.TileMapAtlas.extend = cc.Class.extend;
cc.TMXLayer.extend = cc.Class.extend;
cc.TMXTiledMap.extend = cc.Class.extend;
cc.TMXMapInfo.extend = cc.Class.extend;
cc.TransitionScene.extend = cc.Class.extend;
cc.GLProgram.extend = cc.Class.extend;
// Cocos2d-html5 supports multi scene resources preloading. // Cocos2d-html5 supports multi scene resources preloading.
// This is a compatible function for JSB. // This is a compatible function for JSB.
cc.Loader = cc.Class.extend({ cc.Loader = cc.Class.extend({

View File

@ -0,0 +1,71 @@
--------------------------------
-- @module ComponentPhysics2d
-- @extend Component
-- @parent_module cc
--------------------------------
-- Set physics body of this physics component. If the physics body is set to<br>
-- another physics component before, will set another physics component's physics<br>
-- body to null.<br>
-- param physicsBody The physics body belongs to this component.
-- @function [parent=#ComponentPhysics2d] setPhysicsBody
-- @param self
-- @param #cc.PhysicsBody physicsBody
-- @return ComponentPhysics2d#ComponentPhysics2d self (return value: cc.ComponentPhysics2d)
--------------------------------
-- Get the physics body of this component.<br>
-- return The physics body of this component.
-- @function [parent=#ComponentPhysics2d] getPhysicsBody
-- @param self
-- @return PhysicsBody#PhysicsBody ret (return value: cc.PhysicsBody)
--------------------------------
-- @overload self, cc.PhysicsBody
-- @overload self
-- @function [parent=#ComponentPhysics2d] create
-- @param self
-- @param #cc.PhysicsBody physicsBody
-- @return ComponentPhysics2d#ComponentPhysics2d ret (return value: cc.ComponentPhysics2d)
--------------------------------
--
-- @function [parent=#ComponentPhysics2d] setEnabled
-- @param self
-- @param #bool value
-- @return ComponentPhysics2d#ComponentPhysics2d self (return value: cc.ComponentPhysics2d)
--------------------------------
--
-- @function [parent=#ComponentPhysics2d] onRemove
-- @param self
-- @return ComponentPhysics2d#ComponentPhysics2d self (return value: cc.ComponentPhysics2d)
--------------------------------
--
-- @function [parent=#ComponentPhysics2d] onEnter
-- @param self
-- @return ComponentPhysics2d#ComponentPhysics2d self (return value: cc.ComponentPhysics2d)
--------------------------------
--
-- @function [parent=#ComponentPhysics2d] onExit
-- @param self
-- @return ComponentPhysics2d#ComponentPhysics2d self (return value: cc.ComponentPhysics2d)
--------------------------------
--
-- @function [parent=#ComponentPhysics2d] onAdd
-- @param self
-- @return ComponentPhysics2d#ComponentPhysics2d self (return value: cc.ComponentPhysics2d)
--------------------------------
-- @overload self, cc.PhysicsBody
-- @overload self
-- @function [parent=#ComponentPhysics2d] ComponentPhysics2d
-- @param self
-- @param #cc.PhysicsBody phsicsBody
-- @return ComponentPhysics2d#ComponentPhysics2d self (return value: cc.ComponentPhysics2d)
return nil

View File

@ -358,7 +358,7 @@
-- @return Director#Director self (return value: cc.Director) -- @return Director#Director self (return value: cc.Director)
-------------------------------- --------------------------------
-- Whether or not to display the FPS on the bottom-left corner. -- Whether or not displaying the FPS on the bottom-left corner of the screen.
-- @function [parent=#Director] isDisplayStats -- @function [parent=#Director] isDisplayStats
-- @param self -- @param self
-- @return bool#bool ret (return value: bool) -- @return bool#bool ret (return value: bool)
@ -390,8 +390,8 @@
-- @return Director#Director self (return value: cc.Director) -- @return Director#Director self (return value: cc.Director)
-------------------------------- --------------------------------
-- Gets the distance between camera and near clipping frane.<br> -- Gets the distance between camera and near clipping frame.<br>
-- It is correct for default camera that near clipping frane is the same as screen. -- It is correct for default camera that near clipping frame is same as the screen.
-- @function [parent=#Director] getZEye -- @function [parent=#Director] getZEye
-- @param self -- @param self
-- @return float#float ret (return value: float) -- @return float#float ret (return value: float)
@ -450,7 +450,7 @@
-- @return bool#bool ret (return value: bool) -- @return bool#bool ret (return value: bool)
-------------------------------- --------------------------------
-- Display the FPS on the bottom-left corner. -- Display the FPS on the bottom-left corner of the screen.
-- @function [parent=#Director] setDisplayStats -- @function [parent=#Director] setDisplayStats
-- @param self -- @param self
-- @param #bool displayStats -- @param #bool displayStats
@ -474,7 +474,7 @@
-- @return Director#Director self (return value: cc.Director) -- @return Director#Director self (return value: cc.Director)
-------------------------------- --------------------------------
-- Sets the FPS value. FPS = 1/internal. -- Sets the FPS value. FPS = 1/interval.
-- @function [parent=#Director] setAnimationInterval -- @function [parent=#Director] setAnimationInterval
-- @param self -- @param self
-- @param #float interval -- @param #float interval

View File

@ -40,7 +40,7 @@
-------------------------------- --------------------------------
-- @{<br> -- @{<br>
-- Implementations for interfaces in base calss. -- Implementations for interfaces in base class.
-- @function [parent=#Grid3D] beforeBlit -- @function [parent=#Grid3D] beforeBlit
-- @param self -- @param self
-- @return Grid3D#Grid3D self (return value: cc.Grid3D) -- @return Grid3D#Grid3D self (return value: cc.Grid3D)

View File

@ -197,7 +197,7 @@
-- @return Node#Node self (return value: cc.Node) -- @return Node#Node self (return value: cc.Node)
-------------------------------- --------------------------------
-- -- / @} end of component functions
-- @function [parent=#Node] getOpacity -- @function [parent=#Node] getOpacity
-- @param self -- @param self
-- @return unsigned char#unsigned char ret (return value: unsigned char) -- @return unsigned char#unsigned char ret (return value: unsigned char)
@ -423,6 +423,12 @@
-- @param #vec2_table worldPoint -- @param #vec2_table worldPoint
-- @return vec2_table#vec2_table ret (return value: vec2_table) -- @return vec2_table#vec2_table ret (return value: vec2_table)
--------------------------------
--
-- @function [parent=#Node] isOpacityModifyRGB
-- @param self
-- @return bool#bool ret (return value: bool)
-------------------------------- --------------------------------
-- @overload self, float, float -- @overload self, float, float
-- @overload self, vec2_table -- @overload self, vec2_table
@ -599,12 +605,6 @@
-- @param #unsigned int parentFlags -- @param #unsigned int parentFlags
-- @return Node#Node self (return value: cc.Node) -- @return Node#Node self (return value: cc.Node)
--------------------------------
--
-- @function [parent=#Node] isOpacityModifyRGB
-- @param self
-- @return bool#bool ret (return value: bool)
-------------------------------- --------------------------------
-- Returns the rotation of the node in degrees.<br> -- Returns the rotation of the node in degrees.<br>
-- see `setRotation(float)`<br> -- see `setRotation(float)`<br>

View File

@ -0,0 +1,39 @@
--------------------------------
-- @module PhysicsManager
-- @parent_module cc
--------------------------------
-- Remove a physics component from `PhysiscsManager`. Will remove physics component's physics<br>
-- body from the physics world managed by this `PhysicsManager`.
-- @function [parent=#PhysicsManager] removePhysicsComponent
-- @param self
-- @param #cc.ComponentPhysics2d componentPhsics2d
-- @return PhysicsManager#PhysicsManager self (return value: cc.PhysicsManager)
--------------------------------
-- Add a physics component to be managed by the `PhysicsManager`. Will register physics <br>
-- component's physics body to physics world managed by this `PhysicsManager`.<br>
-- param componentPhsics2d The physics component to be managed by this `PhysicsManager`.
-- @function [parent=#PhysicsManager] addPhysicsComponent
-- @param self
-- @param #cc.ComponentPhysics2d componentPhsics2d
-- @return PhysicsManager#PhysicsManager self (return value: cc.PhysicsManager)
--------------------------------
-- Get the physics world.<br>
-- return Physics world managed by this `PhysicsManager`.
-- @function [parent=#PhysicsManager] getPhysicsWorld
-- @param self
-- @return PhysicsWorld#PhysicsWorld ret (return value: cc.PhysicsWorld)
--------------------------------
-- Create a PhysicsManager with `Scene`. `Scene` will create it automatically,<br>
-- so don't create it yourself.<br>
-- scene The scene this `PhysicsManager` belongs to.
-- @function [parent=#PhysicsManager] PhysicsManager
-- @param self
-- @param #cc.Scene scene
-- @return PhysicsManager#PhysicsManager self (return value: cc.PhysicsManager)
return nil

View File

@ -58,16 +58,6 @@
-- @param self -- @param self
-- @return Scene#Scene ret (return value: cc.Scene) -- @return Scene#Scene ret (return value: cc.Scene)
--------------------------------
-- @overload self, cc.Node, int, string
-- @overload self, cc.Node, int, int
-- @function [parent=#Scene] addChild
-- @param self
-- @param #cc.Node child
-- @param #int zOrder
-- @param #int tag
-- @return Scene#Scene self (return value: cc.Scene)
-------------------------------- --------------------------------
-- --
-- @function [parent=#Scene] init -- @function [parent=#Scene] init

View File

@ -172,7 +172,7 @@
-- @return Action#Action ret (return value: cc.Action) -- @return Action#Action ret (return value: cc.Action)
-------------------------------- --------------------------------
-- just rember bind attributes -- just remember bind attributes
-- @function [parent=#Sprite3D] setGLProgram -- @function [parent=#Sprite3D] setGLProgram
-- @param self -- @param self
-- @param #cc.GLProgram glprogram -- @param #cc.GLProgram glprogram
@ -180,7 +180,7 @@
-------------------------------- --------------------------------
-- Returns 2d bounding-box<br> -- Returns 2d bounding-box<br>
-- Note: the bouding-box is just get from the AABB which as Z=0, so that is not very accurate. -- Note: the bounding-box is just get from the AABB which as Z=0, so that is not very accurate.
-- @function [parent=#Sprite3D] getBoundingBox -- @function [parent=#Sprite3D] getBoundingBox
-- @param self -- @param self
-- @return rect_table#rect_table ret (return value: rect_table) -- @return rect_table#rect_table ret (return value: rect_table)

View File

@ -97,7 +97,7 @@
-- @return bool#bool ret (return value: bool) -- @return bool#bool ret (return value: bool)
-------------------------------- --------------------------------
-- Set threshold distance of each LOD level,must equal or gereater than the chunk size<br> -- Set threshold distance of each LOD level,must equal or greater than the chunk size<br>
-- Note when invoke initHeightMap, the LOD distance will be automatic calculated. -- Note when invoke initHeightMap, the LOD distance will be automatic calculated.
-- @function [parent=#Terrain] setLODDistance -- @function [parent=#Terrain] setLODDistance
-- @param self -- @param self
@ -113,7 +113,7 @@
-- @return size_table#size_table ret (return value: size_table) -- @return size_table#size_table ret (return value: size_table)
-------------------------------- --------------------------------
-- get the normal of the specified pistion in terrain<br> -- get the normal of the specified position in terrain<br>
-- return the normal vector of the specified position of the terrain.<br> -- return the normal vector of the specified position of the terrain.<br>
-- note the fast normal calculation may not get precise normal vector. -- note the fast normal calculation may not get precise normal vector.
-- @function [parent=#Terrain] getNormal -- @function [parent=#Terrain] getNormal
@ -152,13 +152,13 @@
-- @return Terrain#Terrain self (return value: cc.Terrain) -- @return Terrain#Terrain self (return value: cc.Terrain)
-------------------------------- --------------------------------
-- get the terrain's mininal height. -- get the terrain's minimal height.
-- @function [parent=#Terrain] getMinHeight -- @function [parent=#Terrain] getMinHeight
-- @param self -- @param self
-- @return float#float ret (return value: float) -- @return float#float ret (return value: float)
-------------------------------- --------------------------------
-- get the terrain's maximum height. -- get the terrain's maximal height.
-- @function [parent=#Terrain] getMaxHeight -- @function [parent=#Terrain] getMaxHeight
-- @param self -- @param self
-- @return float#float ret (return value: float) -- @return float#float ret (return value: float)

View File

@ -25,7 +25,7 @@
-------------------------------- --------------------------------
-- @{<br> -- @{<br>
-- Implementations for interfaces in base calss. -- Implementations for interfaces in base class.
-- @function [parent=#TiledGrid3D] blit -- @function [parent=#TiledGrid3D] blit
-- @param self -- @param self
-- @return TiledGrid3D#TiledGrid3D self (return value: cc.TiledGrid3D) -- @return TiledGrid3D#TiledGrid3D self (return value: cc.TiledGrid3D)

View File

@ -1236,6 +1236,11 @@
-- @field [parent=#cc] TextureCache#TextureCache TextureCache preloaded module -- @field [parent=#cc] TextureCache#TextureCache TextureCache preloaded module
--------------------------------------------------------
-- the cc Component
-- @field [parent=#cc] Component#Component Component preloaded module
-------------------------------------------------------- --------------------------------------------------------
-- the cc Device -- the cc Device
-- @field [parent=#cc] Device#Device Device preloaded module -- @field [parent=#cc] Device#Device Device preloaded module
@ -1306,9 +1311,4 @@
-- @field [parent=#cc] TileMapAtlas#TileMapAtlas TileMapAtlas preloaded module -- @field [parent=#cc] TileMapAtlas#TileMapAtlas TileMapAtlas preloaded module
--------------------------------------------------------
-- the cc Component
-- @field [parent=#cc] Component#Component Component preloaded module
return nil return nil

View File

@ -151,4 +151,14 @@
-- @field [parent=#cc] PhysicsDebugDraw#PhysicsDebugDraw PhysicsDebugDraw preloaded module -- @field [parent=#cc] PhysicsDebugDraw#PhysicsDebugDraw PhysicsDebugDraw preloaded module
--------------------------------------------------------
-- the cc ComponentPhysics2d
-- @field [parent=#cc] ComponentPhysics2d#ComponentPhysics2d ComponentPhysics2d preloaded module
--------------------------------------------------------
-- the cc PhysicsManager
-- @field [parent=#cc] PhysicsManager#PhysicsManager PhysicsManager preloaded module
return nil return nil

File diff suppressed because it is too large Load Diff

View File

@ -3802,7 +3802,7 @@ int lua_cocos2dx_physics_PhysicsBody_getPosition(lua_State* tolua_S)
tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_physics_PhysicsBody_getPosition'", nullptr); tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_physics_PhysicsBody_getPosition'", nullptr);
return 0; return 0;
} }
const cocos2d::Vec2& ret = cobj->getPosition(); cocos2d::Vec2 ret = cobj->getPosition();
vec2_to_luaval(tolua_S, ret); vec2_to_luaval(tolua_S, ret);
return 1; return 1;
} }
@ -12611,6 +12611,425 @@ int lua_register_cocos2dx_physics_PhysicsDebugDraw(lua_State* tolua_S)
g_typeCast["PhysicsDebugDraw"] = "cc.PhysicsDebugDraw"; g_typeCast["PhysicsDebugDraw"] = "cc.PhysicsDebugDraw";
return 1; return 1;
} }
int lua_cocos2dx_physics_ComponentPhysics2d_setPhysicsBody(lua_State* tolua_S)
{
int argc = 0;
cocos2d::ComponentPhysics2d* cobj = nullptr;
bool ok = true;
#if COCOS2D_DEBUG >= 1
tolua_Error tolua_err;
#endif
#if COCOS2D_DEBUG >= 1
if (!tolua_isusertype(tolua_S,1,"cc.ComponentPhysics2d",0,&tolua_err)) goto tolua_lerror;
#endif
cobj = (cocos2d::ComponentPhysics2d*)tolua_tousertype(tolua_S,1,0);
#if COCOS2D_DEBUG >= 1
if (!cobj)
{
tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_physics_ComponentPhysics2d_setPhysicsBody'", nullptr);
return 0;
}
#endif
argc = lua_gettop(tolua_S)-1;
if (argc == 1)
{
cocos2d::PhysicsBody* arg0;
ok &= luaval_to_object<cocos2d::PhysicsBody>(tolua_S, 2, "cc.PhysicsBody",&arg0, "cc.ComponentPhysics2d:setPhysicsBody");
if(!ok)
{
tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_physics_ComponentPhysics2d_setPhysicsBody'", nullptr);
return 0;
}
cobj->setPhysicsBody(arg0);
lua_settop(tolua_S, 1);
return 1;
}
luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "cc.ComponentPhysics2d:setPhysicsBody",argc, 1);
return 0;
#if COCOS2D_DEBUG >= 1
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_physics_ComponentPhysics2d_setPhysicsBody'.",&tolua_err);
#endif
return 0;
}
int lua_cocos2dx_physics_ComponentPhysics2d_getPhysicsBody(lua_State* tolua_S)
{
int argc = 0;
cocos2d::ComponentPhysics2d* cobj = nullptr;
bool ok = true;
#if COCOS2D_DEBUG >= 1
tolua_Error tolua_err;
#endif
#if COCOS2D_DEBUG >= 1
if (!tolua_isusertype(tolua_S,1,"cc.ComponentPhysics2d",0,&tolua_err)) goto tolua_lerror;
#endif
cobj = (cocos2d::ComponentPhysics2d*)tolua_tousertype(tolua_S,1,0);
#if COCOS2D_DEBUG >= 1
if (!cobj)
{
tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_physics_ComponentPhysics2d_getPhysicsBody'", nullptr);
return 0;
}
#endif
argc = lua_gettop(tolua_S)-1;
if (argc == 0)
{
if(!ok)
{
tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_physics_ComponentPhysics2d_getPhysicsBody'", nullptr);
return 0;
}
cocos2d::PhysicsBody* ret = cobj->getPhysicsBody();
object_to_luaval<cocos2d::PhysicsBody>(tolua_S, "cc.PhysicsBody",(cocos2d::PhysicsBody*)ret);
return 1;
}
luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "cc.ComponentPhysics2d:getPhysicsBody",argc, 0);
return 0;
#if COCOS2D_DEBUG >= 1
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_physics_ComponentPhysics2d_getPhysicsBody'.",&tolua_err);
#endif
return 0;
}
int lua_cocos2dx_physics_ComponentPhysics2d_create(lua_State* tolua_S)
{
int argc = 0;
bool ok = true;
#if COCOS2D_DEBUG >= 1
tolua_Error tolua_err;
#endif
#if COCOS2D_DEBUG >= 1
if (!tolua_isusertable(tolua_S,1,"cc.ComponentPhysics2d",0,&tolua_err)) goto tolua_lerror;
#endif
argc = lua_gettop(tolua_S)-1;
do
{
if (argc == 1)
{
cocos2d::PhysicsBody* arg0;
ok &= luaval_to_object<cocos2d::PhysicsBody>(tolua_S, 2, "cc.PhysicsBody",&arg0, "cc.ComponentPhysics2d:create");
if (!ok) { break; }
cocos2d::ComponentPhysics2d* ret = cocos2d::ComponentPhysics2d::create(arg0);
object_to_luaval<cocos2d::ComponentPhysics2d>(tolua_S, "cc.ComponentPhysics2d",(cocos2d::ComponentPhysics2d*)ret);
return 1;
}
} while (0);
ok = true;
do
{
if (argc == 0)
{
cocos2d::ComponentPhysics2d* ret = cocos2d::ComponentPhysics2d::create();
object_to_luaval<cocos2d::ComponentPhysics2d>(tolua_S, "cc.ComponentPhysics2d",(cocos2d::ComponentPhysics2d*)ret);
return 1;
}
} while (0);
ok = true;
luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d", "cc.ComponentPhysics2d:create",argc, 0);
return 0;
#if COCOS2D_DEBUG >= 1
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_physics_ComponentPhysics2d_create'.",&tolua_err);
#endif
return 0;
}
int lua_cocos2dx_physics_ComponentPhysics2d_constructor(lua_State* tolua_S)
{
int argc = 0;
cocos2d::ComponentPhysics2d* cobj = nullptr;
bool ok = true;
#if COCOS2D_DEBUG >= 1
tolua_Error tolua_err;
#endif
argc = lua_gettop(tolua_S)-1;
do{
if (argc == 1) {
cocos2d::PhysicsBody* arg0;
ok &= luaval_to_object<cocos2d::PhysicsBody>(tolua_S, 2, "cc.PhysicsBody",&arg0, "cc.ComponentPhysics2d:ComponentPhysics2d");
if (!ok) { break; }
cobj = new cocos2d::ComponentPhysics2d(arg0);
cobj->autorelease();
int ID = (int)cobj->_ID ;
int* luaID = &cobj->_luaID ;
toluafix_pushusertype_ccobject(tolua_S, ID, luaID, (void*)cobj,"cc.ComponentPhysics2d");
return 1;
}
}while(0);
ok = true;
do{
if (argc == 0) {
cobj = new cocos2d::ComponentPhysics2d();
cobj->autorelease();
int ID = (int)cobj->_ID ;
int* luaID = &cobj->_luaID ;
toluafix_pushusertype_ccobject(tolua_S, ID, luaID, (void*)cobj,"cc.ComponentPhysics2d");
return 1;
}
}while(0);
ok = true;
luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "cc.ComponentPhysics2d:ComponentPhysics2d",argc, 0);
return 0;
#if COCOS2D_DEBUG >= 1
tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_physics_ComponentPhysics2d_constructor'.",&tolua_err);
#endif
return 0;
}
static int lua_cocos2dx_physics_ComponentPhysics2d_finalize(lua_State* tolua_S)
{
printf("luabindings: finalizing LUA object (ComponentPhysics2d)");
return 0;
}
int lua_register_cocos2dx_physics_ComponentPhysics2d(lua_State* tolua_S)
{
tolua_usertype(tolua_S,"cc.ComponentPhysics2d");
tolua_cclass(tolua_S,"ComponentPhysics2d","cc.ComponentPhysics2d","cc.Component",nullptr);
tolua_beginmodule(tolua_S,"ComponentPhysics2d");
tolua_function(tolua_S,"new",lua_cocos2dx_physics_ComponentPhysics2d_constructor);
tolua_function(tolua_S,"setPhysicsBody",lua_cocos2dx_physics_ComponentPhysics2d_setPhysicsBody);
tolua_function(tolua_S,"getPhysicsBody",lua_cocos2dx_physics_ComponentPhysics2d_getPhysicsBody);
tolua_function(tolua_S,"create", lua_cocos2dx_physics_ComponentPhysics2d_create);
tolua_endmodule(tolua_S);
std::string typeName = typeid(cocos2d::ComponentPhysics2d).name();
g_luaType[typeName] = "cc.ComponentPhysics2d";
g_typeCast["ComponentPhysics2d"] = "cc.ComponentPhysics2d";
return 1;
}
int lua_cocos2dx_physics_PhysicsManager_removePhysicsComponent(lua_State* tolua_S)
{
int argc = 0;
cocos2d::PhysicsManager* cobj = nullptr;
bool ok = true;
#if COCOS2D_DEBUG >= 1
tolua_Error tolua_err;
#endif
#if COCOS2D_DEBUG >= 1
if (!tolua_isusertype(tolua_S,1,"cc.PhysicsManager",0,&tolua_err)) goto tolua_lerror;
#endif
cobj = (cocos2d::PhysicsManager*)tolua_tousertype(tolua_S,1,0);
#if COCOS2D_DEBUG >= 1
if (!cobj)
{
tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_physics_PhysicsManager_removePhysicsComponent'", nullptr);
return 0;
}
#endif
argc = lua_gettop(tolua_S)-1;
if (argc == 1)
{
cocos2d::ComponentPhysics2d* arg0;
ok &= luaval_to_object<cocos2d::ComponentPhysics2d>(tolua_S, 2, "cc.ComponentPhysics2d",&arg0, "cc.PhysicsManager:removePhysicsComponent");
if(!ok)
{
tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_physics_PhysicsManager_removePhysicsComponent'", nullptr);
return 0;
}
cobj->removePhysicsComponent(arg0);
lua_settop(tolua_S, 1);
return 1;
}
luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "cc.PhysicsManager:removePhysicsComponent",argc, 1);
return 0;
#if COCOS2D_DEBUG >= 1
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_physics_PhysicsManager_removePhysicsComponent'.",&tolua_err);
#endif
return 0;
}
int lua_cocos2dx_physics_PhysicsManager_addPhysicsComponent(lua_State* tolua_S)
{
int argc = 0;
cocos2d::PhysicsManager* cobj = nullptr;
bool ok = true;
#if COCOS2D_DEBUG >= 1
tolua_Error tolua_err;
#endif
#if COCOS2D_DEBUG >= 1
if (!tolua_isusertype(tolua_S,1,"cc.PhysicsManager",0,&tolua_err)) goto tolua_lerror;
#endif
cobj = (cocos2d::PhysicsManager*)tolua_tousertype(tolua_S,1,0);
#if COCOS2D_DEBUG >= 1
if (!cobj)
{
tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_physics_PhysicsManager_addPhysicsComponent'", nullptr);
return 0;
}
#endif
argc = lua_gettop(tolua_S)-1;
if (argc == 1)
{
cocos2d::ComponentPhysics2d* arg0;
ok &= luaval_to_object<cocos2d::ComponentPhysics2d>(tolua_S, 2, "cc.ComponentPhysics2d",&arg0, "cc.PhysicsManager:addPhysicsComponent");
if(!ok)
{
tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_physics_PhysicsManager_addPhysicsComponent'", nullptr);
return 0;
}
cobj->addPhysicsComponent(arg0);
lua_settop(tolua_S, 1);
return 1;
}
luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "cc.PhysicsManager:addPhysicsComponent",argc, 1);
return 0;
#if COCOS2D_DEBUG >= 1
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_physics_PhysicsManager_addPhysicsComponent'.",&tolua_err);
#endif
return 0;
}
int lua_cocos2dx_physics_PhysicsManager_getPhysicsWorld(lua_State* tolua_S)
{
int argc = 0;
cocos2d::PhysicsManager* cobj = nullptr;
bool ok = true;
#if COCOS2D_DEBUG >= 1
tolua_Error tolua_err;
#endif
#if COCOS2D_DEBUG >= 1
if (!tolua_isusertype(tolua_S,1,"cc.PhysicsManager",0,&tolua_err)) goto tolua_lerror;
#endif
cobj = (cocos2d::PhysicsManager*)tolua_tousertype(tolua_S,1,0);
#if COCOS2D_DEBUG >= 1
if (!cobj)
{
tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_physics_PhysicsManager_getPhysicsWorld'", nullptr);
return 0;
}
#endif
argc = lua_gettop(tolua_S)-1;
if (argc == 0)
{
if(!ok)
{
tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_physics_PhysicsManager_getPhysicsWorld'", nullptr);
return 0;
}
cocos2d::PhysicsWorld* ret = cobj->getPhysicsWorld();
object_to_luaval<cocos2d::PhysicsWorld>(tolua_S, "cc.PhysicsWorld",(cocos2d::PhysicsWorld*)ret);
return 1;
}
luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "cc.PhysicsManager:getPhysicsWorld",argc, 0);
return 0;
#if COCOS2D_DEBUG >= 1
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_physics_PhysicsManager_getPhysicsWorld'.",&tolua_err);
#endif
return 0;
}
int lua_cocos2dx_physics_PhysicsManager_constructor(lua_State* tolua_S)
{
int argc = 0;
cocos2d::PhysicsManager* cobj = nullptr;
bool ok = true;
#if COCOS2D_DEBUG >= 1
tolua_Error tolua_err;
#endif
argc = lua_gettop(tolua_S)-1;
if (argc == 1)
{
cocos2d::Scene* arg0;
ok &= luaval_to_object<cocos2d::Scene>(tolua_S, 2, "cc.Scene",&arg0, "cc.PhysicsManager:PhysicsManager");
if(!ok)
{
tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_physics_PhysicsManager_constructor'", nullptr);
return 0;
}
cobj = new cocos2d::PhysicsManager(arg0);
tolua_pushusertype(tolua_S,(void*)cobj,"cc.PhysicsManager");
tolua_register_gc(tolua_S,lua_gettop(tolua_S));
return 1;
}
luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "cc.PhysicsManager:PhysicsManager",argc, 1);
return 0;
#if COCOS2D_DEBUG >= 1
tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_physics_PhysicsManager_constructor'.",&tolua_err);
#endif
return 0;
}
static int lua_cocos2dx_physics_PhysicsManager_finalize(lua_State* tolua_S)
{
printf("luabindings: finalizing LUA object (PhysicsManager)");
return 0;
}
int lua_register_cocos2dx_physics_PhysicsManager(lua_State* tolua_S)
{
tolua_usertype(tolua_S,"cc.PhysicsManager");
tolua_cclass(tolua_S,"PhysicsManager","cc.PhysicsManager","",nullptr);
tolua_beginmodule(tolua_S,"PhysicsManager");
tolua_function(tolua_S,"new",lua_cocos2dx_physics_PhysicsManager_constructor);
tolua_function(tolua_S,"removePhysicsComponent",lua_cocos2dx_physics_PhysicsManager_removePhysicsComponent);
tolua_function(tolua_S,"addPhysicsComponent",lua_cocos2dx_physics_PhysicsManager_addPhysicsComponent);
tolua_function(tolua_S,"getPhysicsWorld",lua_cocos2dx_physics_PhysicsManager_getPhysicsWorld);
tolua_endmodule(tolua_S);
std::string typeName = typeid(cocos2d::PhysicsManager).name();
g_luaType[typeName] = "cc.PhysicsManager";
g_typeCast["PhysicsManager"] = "cc.PhysicsManager";
return 1;
}
TOLUA_API int register_all_cocos2dx_physics(lua_State* tolua_S) TOLUA_API int register_all_cocos2dx_physics(lua_State* tolua_S)
{ {
tolua_open(tolua_S); tolua_open(tolua_S);
@ -12628,6 +13047,7 @@ TOLUA_API int register_all_cocos2dx_physics(lua_State* tolua_S)
lua_register_cocos2dx_physics_PhysicsShape(tolua_S); lua_register_cocos2dx_physics_PhysicsShape(tolua_S);
lua_register_cocos2dx_physics_PhysicsShapePolygon(tolua_S); lua_register_cocos2dx_physics_PhysicsShapePolygon(tolua_S);
lua_register_cocos2dx_physics_PhysicsShapeBox(tolua_S); lua_register_cocos2dx_physics_PhysicsShapeBox(tolua_S);
lua_register_cocos2dx_physics_PhysicsManager(tolua_S);
lua_register_cocos2dx_physics_PhysicsJointMotor(tolua_S); lua_register_cocos2dx_physics_PhysicsJointMotor(tolua_S);
lua_register_cocos2dx_physics_PhysicsJointRatchet(tolua_S); lua_register_cocos2dx_physics_PhysicsJointRatchet(tolua_S);
lua_register_cocos2dx_physics_PhysicsJointDistance(tolua_S); lua_register_cocos2dx_physics_PhysicsJointDistance(tolua_S);
@ -12636,6 +13056,7 @@ TOLUA_API int register_all_cocos2dx_physics(lua_State* tolua_S)
lua_register_cocos2dx_physics_PhysicsJointPin(tolua_S); lua_register_cocos2dx_physics_PhysicsJointPin(tolua_S);
lua_register_cocos2dx_physics_PhysicsContactPreSolve(tolua_S); lua_register_cocos2dx_physics_PhysicsContactPreSolve(tolua_S);
lua_register_cocos2dx_physics_PhysicsDebugDraw(tolua_S); lua_register_cocos2dx_physics_PhysicsDebugDraw(tolua_S);
lua_register_cocos2dx_physics_ComponentPhysics2d(tolua_S);
lua_register_cocos2dx_physics_PhysicsShapeEdgeChain(tolua_S); lua_register_cocos2dx_physics_PhysicsShapeEdgeChain(tolua_S);
lua_register_cocos2dx_physics_PhysicsShapeEdgeSegment(tolua_S); lua_register_cocos2dx_physics_PhysicsShapeEdgeSegment(tolua_S);
lua_register_cocos2dx_physics_PhysicsJointGear(tolua_S); lua_register_cocos2dx_physics_PhysicsJointGear(tolua_S);

View File

@ -270,6 +270,16 @@ int register_all_cocos2dx_physics(lua_State* tolua_S);

View File

@ -2379,157 +2379,6 @@ tolua_lerror:
return 0; return 0;
} }
#if CC_USE_PHYSICS
int lua_cocos2dx_Node_setPhysicsBody(lua_State* tolua_S)
{
int argc = 0;
cocos2d::Node* cobj = nullptr;
bool ok = true;
#if COCOS2D_DEBUG >= 1
tolua_Error tolua_err;
#endif
#if COCOS2D_DEBUG >= 1
if (!tolua_isusertype(tolua_S,1,"cc.Node",0,&tolua_err)) goto tolua_lerror;
#endif
cobj = (cocos2d::Node*)tolua_tousertype(tolua_S,1,0);
#if COCOS2D_DEBUG >= 1
if (!cobj)
{
tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_Node_setPhysicsBody'", nullptr);
return 0;
}
#endif
argc = lua_gettop(tolua_S)-1;
if (argc == 1)
{
cocos2d::PhysicsBody* arg0;
ok &= luaval_to_object<cocos2d::PhysicsBody>(tolua_S, 2, "cc.PhysicsBody",&arg0, "cc.Node:setPhysicsBody");
if(!ok)
{
tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_Node_setPhysicsBody'", nullptr);
return 0;
}
cobj->setPhysicsBody(arg0);
lua_settop(tolua_S, 1);
return 1;
}
luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "cc.Node:setPhysicsBody",argc, 1);
return 0;
#if COCOS2D_DEBUG >= 1
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_Node_setPhysicsBody'.",&tolua_err);
#endif
return 0;
}
int lua_cocos2dx_Node_removeFromPhysicsWorld(lua_State* tolua_S)
{
int argc = 0;
cocos2d::Node* cobj = nullptr;
bool ok = true;
#if COCOS2D_DEBUG >= 1
tolua_Error tolua_err;
#endif
#if COCOS2D_DEBUG >= 1
if (!tolua_isusertype(tolua_S,1,"cc.Node",0,&tolua_err)) goto tolua_lerror;
#endif
cobj = (cocos2d::Node*)tolua_tousertype(tolua_S,1,0);
#if COCOS2D_DEBUG >= 1
if (!cobj)
{
tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_Node_removeFromPhysicsWorld'", nullptr);
return 0;
}
#endif
argc = lua_gettop(tolua_S)-1;
if (argc == 0)
{
if(!ok)
{
tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_Node_removeFromPhysicsWorld'", nullptr);
return 0;
}
cobj->removeFromPhysicsWorld();
lua_settop(tolua_S, 1);
return 1;
}
luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "cc.Node:removeFromPhysicsWorld",argc, 0);
return 0;
#if COCOS2D_DEBUG >= 1
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_Node_removeFromPhysicsWorld'.",&tolua_err);
#endif
return 0;
}
int lua_cocos2dx_Node_getPhysicsBody(lua_State* tolua_S)
{
int argc = 0;
cocos2d::Node* cobj = nullptr;
bool ok = true;
#if COCOS2D_DEBUG >= 1
tolua_Error tolua_err;
#endif
#if COCOS2D_DEBUG >= 1
if (!tolua_isusertype(tolua_S,1,"cc.Node",0,&tolua_err)) goto tolua_lerror;
#endif
cobj = (cocos2d::Node*)tolua_tousertype(tolua_S,1,0);
#if COCOS2D_DEBUG >= 1
if (!cobj)
{
tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_Node_getPhysicsBody'", nullptr);
return 0;
}
#endif
argc = lua_gettop(tolua_S)-1;
if (argc == 0)
{
if(!ok)
{
tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_Node_getPhysicsBody'", nullptr);
return 0;
}
cocos2d::PhysicsBody* ret = cobj->getPhysicsBody();
object_to_luaval<cocos2d::PhysicsBody>(tolua_S, "cc.PhysicsBody",(cocos2d::PhysicsBody*)ret);
return 1;
}
luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "cc.Node:getPhysicsBody",argc, 0);
return 0;
#if COCOS2D_DEBUG >= 1
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_Node_getPhysicsBody'.",&tolua_err);
#endif
return 0;
}
#endif //CC_USE_PHYSICS
#if CC_USE_NAVMESH #if CC_USE_NAVMESH
#include "navmesh/CCNavMesh.h" #include "navmesh/CCNavMesh.h"
int lua_cocos2dx_Scene_setNavMeshDebugCamera(lua_State* tolua_S) int lua_cocos2dx_Scene_setNavMeshDebugCamera(lua_State* tolua_S)
@ -5083,18 +4932,6 @@ static void extendNode(lua_State* tolua_S)
lua_pushstring(tolua_S, "setRotationQuat"); lua_pushstring(tolua_S, "setRotationQuat");
lua_pushcfunction(tolua_S, lua_cocos2dx_Node_setRotationQuat); lua_pushcfunction(tolua_S, lua_cocos2dx_Node_setRotationQuat);
lua_rawset(tolua_S, -3); lua_rawset(tolua_S, -3);
#if CC_USE_PHYSICS
lua_pushstring(tolua_S, "setPhysicsBody");
lua_pushcfunction(tolua_S, lua_cocos2dx_Node_setPhysicsBody);
lua_rawset(tolua_S, -3);
lua_pushstring(tolua_S, "removeFromPhysicsWorld");
lua_pushcfunction(tolua_S, lua_cocos2dx_Node_removeFromPhysicsWorld);
lua_rawset(tolua_S, -3);
lua_pushstring(tolua_S, "getPhysicsBody");
lua_pushcfunction(tolua_S, lua_cocos2dx_Node_getPhysicsBody);
lua_rawset(tolua_S, -3);
#endif //CC_USE_PHYSICS
} }
lua_pop(tolua_S, 1); lua_pop(tolua_S, 1);
} }

View File

@ -42,6 +42,7 @@ UIWebView.cpp \
UIWebViewImpl-android.cpp \ UIWebViewImpl-android.cpp \
UIEditBox/UIEditBox.cpp \ UIEditBox/UIEditBox.cpp \
UIEditBox/UIEditBoxImpl-android.cpp \ UIEditBox/UIEditBoxImpl-android.cpp \
UIEditBox/UIEditBoxImpl-common.cpp \
UILayoutComponent.cpp \ UILayoutComponent.cpp \
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/../editor-support LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/../editor-support

View File

@ -29,13 +29,12 @@
#include "UIEditBox.h" #include "UIEditBox.h"
#include <jni.h> #include <jni.h>
#include "jni/Java_org_cocos2dx_lib_Cocos2dxBitmap.h"
#include "jni/Java_org_cocos2dx_lib_Cocos2dxHelper.h" #include "jni/Java_org_cocos2dx_lib_Cocos2dxHelper.h"
#include "2d/CCLabel.h" #include "2d/CCLabel.h"
#include "base/ccUTF8.h" #include "base/ccUTF8.h"
#include "math/Vec2.h" #include "math/Vec2.h"
#include "ui/UIHelper.h" #include "ui/UIHelper.h"
#include "base/ccUTF8.h" #include "base/CCDirector.h"
NS_CC_BEGIN NS_CC_BEGIN
@ -70,88 +69,9 @@ EditBoxImpl* __createSystemEditBox(EditBox* editBox)
return new EditBoxImplAndroid(editBox); return new EditBoxImplAndroid(editBox);
} }
void EditBoxImplAndroid::editBoxEditingDidBegin()
{
// LOGD("textFieldShouldBeginEditing...");
cocos2d::ui::EditBoxDelegate *pDelegate = _editBox->getDelegate();
if (pDelegate != nullptr)
{
pDelegate->editBoxEditingDidBegin(_editBox);
}
#if CC_ENABLE_SCRIPT_BINDING
if (NULL != _editBox && 0 != _editBox->getScriptEditBoxHandler())
{
cocos2d::CommonScriptData data(_editBox->getScriptEditBoxHandler(), "began", _editBox);
cocos2d::ScriptEvent event(cocos2d::kCommonEvent, (void *)&data);
cocos2d::ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&event);
}
#endif
}
void EditBoxImplAndroid::editBoxEditingDidEnd(const std::string& text)
{
// LOGD("textFieldShouldEndEditing...");
_text = text;
this->refreshInactiveText();
cocos2d::ui::EditBoxDelegate *pDelegate = _editBox->getDelegate();
if (pDelegate != nullptr)
{
pDelegate->editBoxEditingDidEnd(_editBox);
pDelegate->editBoxReturn(_editBox);
}
#if CC_ENABLE_SCRIPT_BINDING
if (_editBox != nullptr && 0 != _editBox->getScriptEditBoxHandler())
{
cocos2d::CommonScriptData data(_editBox->getScriptEditBoxHandler(), "ended", _editBox);
cocos2d::ScriptEvent event(cocos2d::kCommonEvent, (void *)&data);
cocos2d::ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&event);
memset(data.eventName, 0, sizeof(data.eventName));
strncpy(data.eventName, "return", sizeof(data.eventName));
event.data = (void *)&data;
cocos2d::ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&event);
}
#endif
if (_editBox != nullptr)
{
this->onEndEditing(text);
}
}
void EditBoxImplAndroid::editBoxEditingChanged(const std::string& text)
{
// LOGD("editBoxTextChanged...");
cocos2d::ui::EditBoxDelegate *pDelegate = _editBox->getDelegate();
_text = text;
if (pDelegate != nullptr)
{
pDelegate->editBoxTextChanged(_editBox, text);
}
#if CC_ENABLE_SCRIPT_BINDING
if (NULL != _editBox && 0 != _editBox->getScriptEditBoxHandler())
{
cocos2d::CommonScriptData data(_editBox->getScriptEditBoxHandler(), "changed", _editBox);
cocos2d::ScriptEvent event(cocos2d::kCommonEvent, (void *)&data);
cocos2d::ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&event);
}
#endif
}
EditBoxImplAndroid::EditBoxImplAndroid(EditBox* pEditText) EditBoxImplAndroid::EditBoxImplAndroid(EditBox* pEditText)
: EditBoxImpl(pEditText) : EditBoxImplCommon(pEditText)
, _label(nullptr)
, _labelPlaceHolder(nullptr)
, _editBoxInputMode(EditBox::InputMode::SINGLE_LINE)
, _editBoxInputFlag(EditBox::InputFlag::INTIAL_CAPS_ALL_CHARACTERS)
, _keyboardReturnType(EditBox::KeyboardReturnType::DEFAULT)
, _colText(Color3B::WHITE)
, _colPlaceHolder(Color3B::GRAY)
, _maxLength(-1)
, _editBoxIndex(-1) , _editBoxIndex(-1)
{ {
} }
@ -162,124 +82,67 @@ EditBoxImplAndroid::~EditBoxImplAndroid()
removeEditBoxJNI(_editBoxIndex); removeEditBoxJNI(_editBoxIndex);
} }
void EditBoxImplAndroid::doAnimationWhenKeyboardMove(float duration, float distance) void EditBoxImplAndroid::createNativeControl(const Rect& frame)
{ // don't need to be implemented on android platform.
}
static const int CC_EDIT_BOX_PADDING = 5;
bool EditBoxImplAndroid::initWithSize(const Size& size)
{ {
auto rect = Rect(0,0, size.width, size.height); auto director = cocos2d::Director::getInstance();
_editBoxIndex = addEditBoxJNI(rect.origin.x, rect.origin.y, rect.size.width, rect.size.height); auto glView = director->getOpenGLView();
auto frameSize = glView->getFrameSize();
auto winSize = director->getWinSize();
auto leftBottom = _editBox->convertToWorldSpace(Point::ZERO);
auto contentSize = frame.size;
auto rightTop = _editBox->convertToWorldSpace(Point(contentSize.width, contentSize.height));
auto uiLeft = frameSize.width / 2 + (leftBottom.x - winSize.width / 2 ) * glView->getScaleX();
auto uiTop = frameSize.height /2 - (rightTop.y - winSize.height / 2) * glView->getScaleY();
auto uiWidth = (rightTop.x - leftBottom.x) * glView->getScaleX();
auto uiHeight = (rightTop.y - leftBottom.y) * glView->getScaleY();
LOGD("scaleX = %f", glView->getScaleX());
_editBoxIndex = addEditBoxJNI(uiLeft, uiTop, uiWidth, uiHeight, glView->getScaleX());
s_allEditBoxes[_editBoxIndex] = this; s_allEditBoxes[_editBoxIndex] = this;
_label = Label::create();
_label->setSystemFontSize(size.height-12);
// align the text vertically center
_label->setAnchorPoint(Vec2(0, 0.5f));
_label->setPosition(Vec2(CC_EDIT_BOX_PADDING, size.height / 2.0f));
_label->setTextColor(_colText);
_editBox->addChild(_label);
_labelPlaceHolder = Label::create();
_labelPlaceHolder->setSystemFontSize(size.height-12);
// align the text vertically center
_labelPlaceHolder->setAnchorPoint(Vec2(0, 0.5f));
_labelPlaceHolder->setPosition(CC_EDIT_BOX_PADDING, size.height / 2.0f);
_labelPlaceHolder->setVisible(false);
_labelPlaceHolder->setTextColor(_colPlaceHolder);
_editBox->addChild(_labelPlaceHolder);
_editSize = size;
return true;
} }
void EditBoxImplAndroid::setFont(const char* pFontName, int fontSize) void EditBoxImplAndroid::setNativeFont(const char* pFontName, int fontSize)
{ {
if(_label != NULL) auto director = cocos2d::Director::getInstance();
{ auto glView = director->getOpenGLView();
if(strlen(pFontName) > 0) setFontEditBoxJNI(_editBoxIndex, pFontName, fontSize * glView->getScaleX());
{
_label->setSystemFontName(pFontName);
}
if(fontSize > 0)
{
_label->setSystemFontSize(fontSize);
}
}
if(_labelPlaceHolder != NULL)
{
if(strlen(pFontName) > 0)
{
_labelPlaceHolder->setSystemFontName(pFontName);
}
if(fontSize > 0)
{
_labelPlaceHolder->setSystemFontSize(fontSize);
}
}
setFontEditBoxJNI(_editBoxIndex, pFontName, fontSize);
} }
void EditBoxImplAndroid::setFontColor(const Color4B& color) void EditBoxImplAndroid::setNativeFontColor(const Color4B& color)
{ {
_colText = color;
_label->setTextColor(color);
setFontColorEditBoxJNI(_editBoxIndex, color.r, color.g, color.b, color.a); setFontColorEditBoxJNI(_editBoxIndex, color.r, color.g, color.b, color.a);
} }
void EditBoxImplAndroid::setPlaceholderFont(const char* pFontName, int fontSize) void EditBoxImplAndroid::setNativePlaceholderFont(const char* pFontName, int fontSize)
{ {
if(_labelPlaceHolder != NULL) CCLOG("Wraning! You can't change Andriod Hint fontName and fontSize");
{
if(strlen(pFontName) > 0)
{
_labelPlaceHolder->setSystemFontName(pFontName);
}
if(fontSize > 0)
{
_labelPlaceHolder->setSystemFontSize(fontSize);
}
}
CCLOG("Wraning! You can't change Andriod Hint fontName and fontSize");
} }
void EditBoxImplAndroid::setPlaceholderFontColor(const Color4B& color) void EditBoxImplAndroid::setNativePlaceholderFontColor(const Color4B& color)
{ {
_colPlaceHolder = color;
_labelPlaceHolder->setTextColor(color);
setPlaceHolderTextColorEditBoxJNI(_editBoxIndex, color.r, color.g, color.b, color.a); setPlaceHolderTextColorEditBoxJNI(_editBoxIndex, color.r, color.g, color.b, color.a);
} }
void EditBoxImplAndroid::setInputMode(EditBox::InputMode inputMode) void EditBoxImplAndroid::setNativeInputMode(EditBox::InputMode inputMode)
{ {
_editBoxInputMode = inputMode;
setInputModeEditBoxJNI(_editBoxIndex, static_cast<int>(inputMode)); setInputModeEditBoxJNI(_editBoxIndex, static_cast<int>(inputMode));
} }
void EditBoxImplAndroid::setMaxLength(int maxLength) void EditBoxImplAndroid::setNativeMaxLength(int maxLength)
{ {
_maxLength = maxLength; setMaxLengthJNI(_editBoxIndex, maxLength);
setMaxLengthJNI(_editBoxIndex, _maxLength);
} }
int EditBoxImplAndroid::getMaxLength()
{
return _maxLength;
}
void EditBoxImplAndroid::setInputFlag(EditBox::InputFlag inputFlag) void EditBoxImplAndroid::setNativeInputFlag(EditBox::InputFlag inputFlag)
{ {
_editBoxInputFlag = inputFlag;
setInputFlagEditBoxJNI(_editBoxIndex, static_cast<int>(inputFlag)); setInputFlagEditBoxJNI(_editBoxIndex, static_cast<int>(inputFlag));
} }
void EditBoxImplAndroid::setReturnType(EditBox::KeyboardReturnType returnType) void EditBoxImplAndroid::setNativeReturnType(EditBox::KeyboardReturnType returnType)
{ {
_keyboardReturnType = returnType;
setReturnTypeEditBoxJNI(_editBoxIndex, static_cast<int>(returnType)); setReturnTypeEditBoxJNI(_editBoxIndex, static_cast<int>(returnType));
} }
@ -288,129 +151,40 @@ bool EditBoxImplAndroid::isEditing()
return false; return false;
} }
void EditBoxImplAndroid::setInactiveText(const char* pText) void EditBoxImplAndroid::setNativeText(const char* pText)
{
if(EditBox::InputFlag::PASSWORD == _editBoxInputFlag)
{
std::string passwordString;
for(int i = 0; i < strlen(pText); ++i)
passwordString.append("\u25CF");
_label->setString(passwordString.c_str());
}
else
{
_label->setString(pText);
}
// Clip the text width to fit to the text box
float fMaxWidth = _editBox->getContentSize().width - CC_EDIT_BOX_PADDING * 2;
Size labelSize = _label->getContentSize();
if(labelSize.width > fMaxWidth) {
_label->setDimensions(fMaxWidth,labelSize.height);
}
}
void EditBoxImplAndroid::refreshInactiveText()
{
setInactiveText(_text.c_str());
if(_text.size() == 0)
{
_label->setVisible(false);
_labelPlaceHolder->setVisible(true);
}
else
{
_label->setVisible(true);
_labelPlaceHolder->setVisible(false);
}
}
void EditBoxImplAndroid::setText(const char* pText)
{ {
setTextEditBoxJNI(_editBoxIndex, pText); setTextEditBoxJNI(_editBoxIndex, pText);
_text = pText;
refreshInactiveText();
} }
const char* EditBoxImplAndroid::getText(void) void EditBoxImplAndroid::setNativePlaceHolder(const char* pText)
{ {
return _text.c_str(); setPlaceHolderTextEditBoxJNI(_editBoxIndex, pText);
} }
void EditBoxImplAndroid::setPlaceHolder(const char* pText)
{
if (pText != NULL)
{
_placeHolder = pText;
if (_placeHolder.length() > 0 && _text.length() == 0)
{
_labelPlaceHolder->setVisible(true);
}
_labelPlaceHolder->setString(_placeHolder.c_str()); void EditBoxImplAndroid::setNativeVisible(bool visible)
setPlaceHolderTextEditBoxJNI(_editBoxIndex, pText);
}
}
void EditBoxImplAndroid::setPosition(const Vec2& pos)
{ // don't need to be implemented on android platform.
}
void EditBoxImplAndroid::setVisible(bool visible)
{ // don't need to be implemented on android platform. { // don't need to be implemented on android platform.
setVisibleEditBoxJNI(_editBoxIndex, visible); setVisibleEditBoxJNI(_editBoxIndex, visible);
} }
void EditBoxImplAndroid::setContentSize(const Size& size) void EditBoxImplAndroid::updateNativeFrame(const Rect& rect)
{ // don't need to be implemented on android platform.
}
void EditBoxImplAndroid::setAnchorPoint(const Vec2& anchorPoint)
{ // don't need to be implemented on android platform.
}
void EditBoxImplAndroid::draw(Renderer *renderer, const Mat4 &parentTransform, uint32_t parentFlags)
{ // don't need to be implemented on android platform.
if(parentFlags)
{
auto rect = ui::Helper::convertBoundingBoxToScreen(_editBox);
setEditBoxViewRectJNI(_editBoxIndex, rect.origin.x, rect.origin.y, rect.size.width, rect.size.height);
}
}
void EditBoxImplAndroid::onEnter(void)
{ // don't need to be implemented on android platform.
}
void EditBoxImplAndroid::openKeyboard()
{ {
_label->setVisible(false);
_labelPlaceHolder->setVisible(false);
setEditBoxViewRectJNI(_editBoxIndex, rect.origin.x, rect.origin.y, rect.size.width, rect.size.height);
}
void EditBoxImplAndroid::nativeOpenKeyboard()
{
//it will also open up the soft keyboard //it will also open up the soft keyboard
setVisibleEditBoxJNI(_editBoxIndex,true); setVisibleEditBoxJNI(_editBoxIndex,true);
} }
void EditBoxImplAndroid::closeKeyboard() void EditBoxImplAndroid::nativeCloseKeyboard()
{ {
closeEditBoxKeyboardJNI(_editBoxIndex); closeEditBoxKeyboardJNI(_editBoxIndex);
} }
void EditBoxImplAndroid::onEndEditing(const std::string& text)
{
setVisibleEditBoxJNI(_editBoxIndex, false);
if(text.size() == 0)
{
_label->setVisible(false);
_labelPlaceHolder->setVisible(true);
}
else
{
_label->setVisible(true);
_labelPlaceHolder->setVisible(false);
setInactiveText(text.c_str());
}
}
void editBoxEditingDidBegin(int index) void editBoxEditingDidBegin(int index)
{ {
auto it = s_allEditBoxes.find(index); auto it = s_allEditBoxes.find(index);
@ -436,6 +210,12 @@ void editBoxEditingDidEnd(int index, const std::string& text)
s_allEditBoxes[index]->editBoxEditingDidEnd(text); s_allEditBoxes[index]->editBoxEditingDidEnd(text);
} }
} }
const char* EditBoxImplAndroid::getNativeDefaultFontName()
{
return "";
}
} //end of ui namespace } //end of ui namespace
NS_CC_END NS_CC_END

View File

@ -30,7 +30,7 @@
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
#include "UIEditBoxImpl.h" #include "UIEditBoxImpl-common.h"
NS_CC_BEGIN NS_CC_BEGIN
@ -40,7 +40,7 @@ namespace ui {
class EditBox; class EditBox;
class EditBoxImplAndroid : public EditBoxImpl class EditBoxImplAndroid : public EditBoxImplCommon
{ {
public: public:
/** /**
@ -53,63 +53,29 @@ public:
*/ */
virtual ~EditBoxImplAndroid(); virtual ~EditBoxImplAndroid();
virtual bool initWithSize(const Size& size) override;
virtual void setFont(const char* pFontName, int fontSize) override;
virtual void setFontColor(const Color4B& color) override;
virtual void setPlaceholderFont(const char* pFontName, int fontSize) override;
virtual void setPlaceholderFontColor(const Color4B& color) override;
virtual void setInputMode(EditBox::InputMode inputMode) override;
virtual void setInputFlag(EditBox::InputFlag inputFlag) override;
virtual void setMaxLength(int maxLength) override;
virtual int getMaxLength() override;
virtual void setReturnType(EditBox::KeyboardReturnType returnType) override;
virtual bool isEditing() override; virtual bool isEditing() override;
virtual void createNativeControl(const Rect& frame) override;
virtual void setText(const char* pText) override; virtual void setNativeFont(const char* pFontName, int fontSize) override;
virtual const char* getText(void) override; virtual void setNativeFontColor(const Color4B& color) override;
virtual void setPlaceHolder(const char* pText) override; virtual void setNativePlaceholderFont(const char* pFontName, int fontSize) override;
virtual void setPosition(const Vec2& pos) override; virtual void setNativePlaceholderFontColor(const Color4B& color) override;
virtual void setVisible(bool visible) override; virtual void setNativeInputMode(EditBox::InputMode inputMode) override;
virtual void setContentSize(const Size& size) override; virtual void setNativeInputFlag(EditBox::InputFlag inputFlag) override;
virtual void setAnchorPoint(const Vec2& anchorPoint) override; virtual void setNativeReturnType(EditBox::KeyboardReturnType returnType)override;
/** virtual void setNativeText(const char* pText) override;
* @js NA virtual void setNativePlaceHolder(const char* pText) override;
* @lua NA virtual void setNativeVisible(bool visible) override;
*/ virtual void updateNativeFrame(const Rect& rect) override;
virtual void draw(Renderer *renderer, const Mat4 &parentTransform, uint32_t parentFlags) override; virtual void setNativeContentSize(const Size& size) override {};
/** virtual const char* getNativeDefaultFontName() override;
* @js NA virtual void nativeOpenKeyboard() override;
* @lua NA virtual void nativeCloseKeyboard() override;
*/ virtual void setNativeMaxLength(int maxLength);
virtual void onEnter(void) override;
virtual void doAnimationWhenKeyboardMove(float duration, float distance) override;
virtual void openKeyboard() override;
virtual void closeKeyboard() override;
void editBoxEditingDidBegin();
void editBoxEditingChanged(const std::string& text);
void editBoxEditingDidEnd(const std::string& text);
private: private:
void setInactiveText(const char* pText); virtual void doAnimationWhenKeyboardMove(float duration, float distance)override {}
void onEndEditing(const std::string& text);
void refreshInactiveText();
Label* _label;
Label* _labelPlaceHolder;
EditBox::InputMode _editBoxInputMode;
EditBox::InputFlag _editBoxInputFlag;
EditBox::KeyboardReturnType _keyboardReturnType;
std::string _text;
std::string _placeHolder;
Color4B _colText;
Color4B _colPlaceHolder;
int _maxLength;
Size _editSize;
int _editBoxIndex; int _editBoxIndex;
}; };

Some files were not shown because too many files have changed in this diff Show More