├── .gitignore ├── LICENSE ├── Project └── Android │ ├── .gitignore │ ├── .idea │ ├── compiler.xml │ ├── copyright │ │ └── profiles_settings.xml │ ├── encodings.xml │ ├── gradle.xml │ ├── misc.xml │ ├── modules.xml │ └── runConfigurations.xml │ ├── app │ ├── .gitignore │ ├── build.gradle │ ├── proguard-rules.pro │ └── src │ │ └── main │ │ ├── AndroidManifest.xml │ │ ├── assets │ │ ├── Resource │ │ │ ├── Pea.png │ │ │ ├── SpinningPeas.png │ │ │ ├── background.png │ │ │ ├── bh_test.json │ │ │ ├── bh_test_2.json │ │ │ ├── powered.png │ │ │ ├── shader │ │ │ │ ├── flip.fragment.glsl │ │ │ │ └── ice.fragment.glsl │ │ │ └── walkanim.png │ │ └── sfd │ │ │ ├── default.fnt │ │ │ ├── default.png │ │ │ ├── main.fragment.glsl │ │ │ ├── main.vertex.glsl │ │ │ ├── uiskin.atlas │ │ │ ├── uiskin.json │ │ │ └── uiskin.png │ │ ├── java │ │ └── cn │ │ │ └── cocos2d_java │ │ │ └── MainActivity.java │ │ └── res │ │ ├── layout │ │ └── activity_main.xml │ │ ├── mipmap-hdpi │ │ └── ic_launcher.png │ │ ├── mipmap-mdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxxhdpi │ │ └── ic_launcher.png │ │ ├── values-w820dp │ │ └── dimens.xml │ │ └── values │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml │ ├── build.gradle │ ├── gradle.properties │ ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties │ ├── gradlew │ ├── gradlew.bat │ └── settings.gradle ├── README.md ├── Resource ├── Pea.png ├── SpinningPeas.png ├── background.png ├── bh_test.json ├── bh_test_2.json ├── pack.atlas ├── pack.png ├── powered.png ├── shader │ ├── flip.fragment.glsl │ ├── ice.fragment.glsl │ ├── main.fragment.glsl │ └── main.vertex.glsl ├── tiles.png ├── tiles.tmx ├── tiles.tsx └── walkanim.png ├── _record └── record_1.txt ├── external └── com │ └── cocos2dj │ └── module │ ├── box2d │ └── ModuleBox2d.java │ ├── btree │ ├── BHSwitch.java │ ├── BhLeafRunning.java │ ├── BhLeafTask.java │ ├── BhTree.java │ ├── BhTreeHelper.java │ ├── BhTreeLoader.java │ └── BhTreeModel.java │ └── visui │ ├── ModuleVisUI.java │ └── VisUIHelper.java ├── libs ├── gdx-1.9.4.jar ├── gdx-ai-bh.jar ├── gdx-box2d-1.9.4.jar ├── gdx-freetype-1.9.4.jar └── vis-1.2.4.jar ├── platform ├── android │ ├── arm64-v8a │ │ ├── libgdx-box2d.so │ │ └── libgdx.so │ ├── armeabi-v7a │ │ ├── libgdx-box2d.so │ │ └── libgdx.so │ ├── armeabi │ │ ├── libgdx-box2d.so │ │ └── libgdx.so │ ├── gdx-backend-android-1.9.4.jar │ ├── src │ │ └── com │ │ │ └── cocos2dj │ │ │ └── platform │ │ │ └── android │ │ │ └── ApplicationStartup.java │ ├── x86 │ │ ├── libgdx-box2d.so │ │ └── libgdx.so │ └── x86_64 │ │ ├── libgdx-box2d.so │ │ └── libgdx.so └── desktop │ ├── gdx-backend-lwjgl-1.9.4.jar │ ├── gdx-backend-lwjgl-natives.jar │ ├── gdx-box2d-platform-1.9.4-natives-desktop.jar │ ├── gdx-freetype-platform-1.9.4-natives-desktop.jar │ ├── gdx-platform-1.9.4-natives-desktop.jar │ ├── lwjgl-2.9.2.jar │ ├── lwjgl_util-2.9.2.jar │ └── src │ └── com │ └── cocos2dj │ └── platform │ └── desktop │ └── ApplicationStartup.java ├── src └── com │ └── cocos2dj │ ├── base │ ├── ActionManager.java │ ├── AffineTransform.java │ ├── CameraManager.java │ ├── Console.java │ ├── Director.java │ ├── Event.java │ ├── EventCustom.java │ ├── EventDispatcher.java │ ├── EventKeyboard.java │ ├── EventListener.java │ ├── EventListenerCustom.java │ ├── EventListenerFocus.java │ ├── EventListenerKeyboard.java │ ├── EventListenerTouchAllAtOnce.java │ ├── EventListenerTouchOneByOne.java │ ├── EventTouch.java │ ├── Rect.java │ ├── Scheduler.java │ ├── Size.java │ └── Touch.java │ ├── basic │ ├── BaseCoreTimer.java │ ├── BaseGame.java │ ├── BaseInput.java │ ├── BaseLog.java │ ├── BaseRandTimer.java │ ├── BaseScheduler.java │ ├── BaseSystemTimer.java │ ├── BaseTask.java │ ├── BaseTimer.java │ ├── BaseUpdater.java │ ├── Engine.java │ ├── EngineLock.java │ ├── EventManager.java │ ├── IDisposable.java │ └── SConfig.java │ ├── macros │ ├── CC.java │ ├── CCLog.java │ └── CCMacros.java │ ├── module │ ├── Module.java │ ├── ModuleManager.java │ ├── base2d │ │ ├── Base2dNode.java │ │ ├── ComponentPhysics.java │ │ ├── ModuleBase2d.java │ │ ├── framework │ │ │ ├── Base2D.java │ │ │ ├── IPhysicsObject.java │ │ │ ├── PhysicsConfig.java │ │ │ ├── PhysicsGenerator.java │ │ │ ├── PhysicsObject.java │ │ │ ├── PhysicsObjectDynamic.java │ │ │ ├── PhysicsObjectMove.java │ │ │ ├── PhysicsObjectStatic.java │ │ │ ├── PhysicsObjectType.java │ │ │ ├── PhysicsScene.java │ │ │ ├── Simulator.java │ │ │ ├── callback │ │ │ │ ├── ContactListener.java │ │ │ │ ├── DefaultContactListener.java │ │ │ │ ├── MyTreeCallback.java │ │ │ │ ├── MyTreeRayCastCallback.java │ │ │ │ ├── OnContactCallback.java │ │ │ │ ├── UpdateListener.java │ │ │ │ └── VelocityLimitListener.java │ │ │ ├── collision │ │ │ │ ├── AABBShape.java │ │ │ │ ├── Circle.java │ │ │ │ ├── CollideAlgorithms.java │ │ │ │ ├── Contact.java │ │ │ │ ├── ContactAttach.java │ │ │ │ ├── ContactCollisionData.java │ │ │ │ ├── ContactFilter.java │ │ │ │ ├── ContactList.java │ │ │ │ ├── ContactPool.java │ │ │ │ ├── FloatPair.java │ │ │ │ ├── Polygon.java │ │ │ │ ├── Shape.java │ │ │ │ ├── ShapeAlgorithms.java │ │ │ │ └── TileShape.java │ │ │ ├── common │ │ │ │ ├── AABB.java │ │ │ │ ├── M22.java │ │ │ │ ├── MathUtils.java │ │ │ │ ├── Settings.java │ │ │ │ ├── TempArray.java │ │ │ │ ├── TimeInfo.java │ │ │ │ └── V2.java │ │ │ └── pipeline │ │ │ │ ├── BroadPhaseSolver.java │ │ │ │ ├── ContactSolver.java │ │ │ │ └── PosSolver.java │ │ └── jbox2d │ │ │ ├── BroadPhase.java │ │ │ ├── BroadPhaseStrategy.java │ │ │ ├── BufferUtils.java │ │ │ ├── DefaultBroadPhaseBuffer.java │ │ │ ├── DynamicTreeFlatNodes.java │ │ │ ├── Pair.java │ │ │ ├── PairCallback.java │ │ │ ├── RayCastInput.java │ │ │ ├── RayCastOutput.java │ │ │ ├── RaycastResult.java │ │ │ ├── Segment.java │ │ │ ├── SortKeyFunc.java │ │ │ ├── TreeCallback.java │ │ │ ├── TreeRayCastCallback.java │ │ │ └── pooling │ │ │ ├── DefaultWorldPool.java │ │ │ ├── DynamicIntStack.java │ │ │ ├── DynamicTLArray.java │ │ │ ├── IDynamicStack.java │ │ │ ├── IOrderedStack.java │ │ │ ├── IWorldPool.java │ │ │ ├── IntegerArray.java │ │ │ ├── MutableStack.java │ │ │ ├── TLAABB.java │ │ │ ├── TLVec2.java │ │ │ └── Vec2Array.java │ ├── gdxui │ │ ├── GdxUIConfig.java │ │ ├── GdxUIConsole.java │ │ ├── GdxUIDebugInfo.java │ │ ├── GdxUIManager.java │ │ ├── GdxUISkin.java │ │ ├── GdxUIStage.java │ │ ├── ModuleGdxUI.java │ │ └── sfd │ │ │ ├── default.fnt │ │ │ ├── default.png │ │ │ ├── uiskin.atlas │ │ │ ├── uiskin.json │ │ │ └── uiskin.png │ └── typefactory │ │ ├── ModuleTypeFactory.java │ │ ├── NodeFactory.java │ │ ├── NodePool.java │ │ ├── NodePools.java │ │ ├── NodeType.java │ │ ├── PoolListener.java │ │ └── SmartType.java │ ├── platform │ ├── AppDelegate.java │ ├── FileUtils.java │ ├── GLView.java │ └── ResolutionPolicy.java │ ├── protocol │ ├── IAction.java │ ├── ICamera.java │ ├── IComponent.java │ ├── IFunctionOneArg.java │ ├── IFunctionOneArgRet.java │ ├── IFunctionZeroArg.java │ ├── INode.java │ ├── INodePool.java │ ├── INodeType.java │ ├── IScene.java │ ├── ITransitionScene.java │ └── IUpdater.java │ ├── renderer │ ├── FrameBuffer.java │ ├── GLProgramCache.java │ ├── RenderCommand.java │ ├── Renderer.java │ ├── Texture.java │ ├── TextureCache.java │ ├── TextureRegion.java │ └── Viewport.java │ ├── s2d │ ├── Action.java │ ├── ActionCondition.java │ ├── ActionInstant.java │ ├── ActionInterval.java │ ├── Camera.java │ ├── CameraBackgroundBrush.java │ ├── ComponentContainer.java │ ├── DrawNode.java │ ├── Node.java │ ├── PolygonInfo.java │ ├── ProtectedNode.java │ ├── Scene.java │ ├── Sprite.java │ ├── SpriteFrameCache.java │ └── TMXTiledMap.java │ ├── ui │ ├── Button.java │ ├── GUIDefine.java │ ├── Layout.java │ ├── LayoutComponent.java │ ├── LayoutParameter.java │ └── Widget.java │ └── utils │ ├── Direct.java │ ├── IObjectPool.java │ ├── Installation.java │ ├── MessUtils.java │ ├── ObjectLinkedList.java │ ├── ObjectPool.java │ ├── ObjectPoolBuilder.java │ ├── ObjectPoolLinear.java │ ├── QuadTree.java │ ├── QuadTreeV2.java │ ├── SE.java │ ├── Shape3DUtils.java │ └── TransformUtils.java ├── tests ├── src-android │ └── tests │ │ └── Activity_Tests.java ├── src-desktop │ └── tests │ │ ├── Main_Empty.java │ │ ├── Main_GdxUI.java │ │ └── Main_Tests.java └── src │ └── tests │ ├── TestAppDelegate.java │ ├── TestAppDelegate_GdxUI.java │ ├── TestAppDelegate_Tests.java │ ├── TestBase.java │ ├── TestCase.java │ ├── TestController.java │ ├── TestList.java │ ├── TestSuite.java │ └── testcase │ ├── ATempleTests.java │ ├── ActionManagerTests.java │ ├── Base2dTests.java │ ├── Base2dTests2.java │ ├── BehaviorTreeTests.java │ ├── Box2dTests.java │ ├── CCUITests.java │ ├── CameraTests.java │ ├── DrawNodeTests.java │ ├── EventTests.java │ ├── FiniteActionTests.java │ ├── InfiniteActionTests.java │ ├── NodeTests.java │ ├── ShaderTests.java │ ├── SpriteTests.java │ ├── TextureAtlasTests.java │ ├── TiledMapTests.java │ ├── TypeFactoryTests.java │ └── VisUITests.java └── tools ├── bmpToPng.jar ├── in ├── scene_b1.jpg ├── scene_b2.jpg ├── scene_b3.jpg ├── scene_b4.jpg ├── scene_b5.jpg ├── scene_b6.jpg ├── scene_copy.jpg └── scene_del.jpg ├── out ├── pack.atlas └── pack.png ├── runnable-texturepacker.jar └── 工具说明.txt /.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | 3 | /bin/ 4 | *.DS_Store 5 | *.project 6 | *.classpath 7 | 8 | # Mobile Tools for Java (J2ME) 9 | .mtj.tmp/ 10 | 11 | # Package Files #: 12 | *.war 13 | *.ear 14 | 15 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 16 | hs_err_pid* 17 | -------------------------------------------------------------------------------- /Project/Android/.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | .externalNativeBuild 10 | -------------------------------------------------------------------------------- /Project/Android/.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /Project/Android/.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /Project/Android/.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Project/Android/.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 18 | 19 | -------------------------------------------------------------------------------- /Project/Android/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 19 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 46 | 47 | 48 | 49 | 50 | Android API 23 Platform 51 | 52 | 57 | 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /Project/Android/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Project/Android/.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /Project/Android/app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /Project/Android/app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 24 5 | buildToolsVersion "24.0.3" 6 | defaultConfig { 7 | applicationId "cn.cocos2d_java" 8 | minSdkVersion 15 9 | targetSdkVersion 24 10 | versionCode 1 11 | versionName "1.0" 12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 13 | jackOptions { 14 | enabled true 15 | } 16 | } 17 | compileOptions { 18 | sourceCompatibility JavaVersion.VERSION_1_8 19 | targetCompatibility JavaVersion.VERSION_1_8 20 | } 21 | 22 | buildTypes { 23 | release { 24 | minifyEnabled false 25 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 26 | } 27 | } 28 | 29 | sourceSets { 30 | main { 31 | def src = ['src', './../../../src', './../../../external','./../../../platform/android/src', 32 | './../../../tests/src', './../../../tests/src-android'] 33 | java.srcDirs = src 34 | jniLibs.srcDirs = ['jniLibs', './../../../platform/android'] 35 | } 36 | } 37 | } 38 | 39 | dependencies { 40 | compile fileTree(dir: 'libs', include: ['*.jar']) 41 | compile fileTree(dir: './../../../libs', include: ['*.jar']) 42 | compile fileTree(dir: './../../../platform/android', include: ['*.jar']) 43 | // androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 44 | // exclude group: 'com.android.support', module: 'support-annotations' 45 | // }) 46 | compile 'com.android.support:appcompat-v7:24.2.1' 47 | // testCompile 'junit:junit:4.12' 48 | } 49 | -------------------------------------------------------------------------------- /Project/Android/app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/xujun/Library/Android/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /Project/Android/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /Project/Android/app/src/main/assets/Resource/Pea.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mingwuyun/cocos2d-java/f9534d0daa4ded45905ce670936f20ad5a314846/Project/Android/app/src/main/assets/Resource/Pea.png -------------------------------------------------------------------------------- /Project/Android/app/src/main/assets/Resource/SpinningPeas.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mingwuyun/cocos2d-java/f9534d0daa4ded45905ce670936f20ad5a314846/Project/Android/app/src/main/assets/Resource/SpinningPeas.png -------------------------------------------------------------------------------- /Project/Android/app/src/main/assets/Resource/background.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mingwuyun/cocos2d-java/f9534d0daa4ded45905ce670936f20ad5a314846/Project/Android/app/src/main/assets/Resource/background.png -------------------------------------------------------------------------------- /Project/Android/app/src/main/assets/Resource/bh_test.json: -------------------------------------------------------------------------------- 1 | { 2 | "selector":{ 3 | "sequence":{ 4 | "leaf":{"key":"checkA","args":"debug"}, 5 | "leaf":{"key":"a","args":"debug"}, 6 | "leaf":{"key":"ALL1","args":"debug"}, 7 | "leaf":{"key":"ALL2","args":"debug"}, 8 | }, 9 | "sequence":{ 10 | "leaf":{"key":"checkB","args":"debug"}, 11 | "leaf":{"key":"b","args":"debug"}, 12 | "leaf":{"key":"ALL1","args":"debug"}, 13 | "leaf":{"key":"ALL2","args":"debug"}, 14 | }, 15 | } 16 | } -------------------------------------------------------------------------------- /Project/Android/app/src/main/assets/Resource/bh_test_2.json: -------------------------------------------------------------------------------- 1 | { 2 | "selector":{ 3 | "parallel":{ 4 | "leaf":{"key":"atk_checkPlayer"}, 5 | "leaf":{"key":"atk_move"}, 6 | "leaf":{"key":"atk_shot"}, 7 | }, 8 | 9 | "parallel":{ 10 | "leaf":{"key":"idle_checkPlayer"}, 11 | "leaf":{"key":"idle_move"}, 12 | }, 13 | } 14 | } -------------------------------------------------------------------------------- /Project/Android/app/src/main/assets/Resource/powered.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mingwuyun/cocos2d-java/f9534d0daa4ded45905ce670936f20ad5a314846/Project/Android/app/src/main/assets/Resource/powered.png -------------------------------------------------------------------------------- /Project/Android/app/src/main/assets/Resource/shader/flip.fragment.glsl: -------------------------------------------------------------------------------- 1 | // 反色 2 | varying vec2 v_texCoords; 3 | uniform sampler2D u_texture; 4 | 5 | void main() 6 | { 7 | vec4 col = texture2D( u_texture, v_texCoords); 8 | col.g=1.0-col.g; // 9 | col.r=1.0-col.r; // 10 | col.b=1.0-col.b; // 11 | gl_FragColor = col; 12 | // lowp vec4 col = texture2D(u_texture, v_texCoords); 13 | //col.g = 1.0 - col.g; 14 | //gl_FragColor = col; 15 | } -------------------------------------------------------------------------------- /Project/Android/app/src/main/assets/Resource/shader/ice.fragment.glsl: -------------------------------------------------------------------------------- 1 | // 冰花效果 2 | varying vec2 v_texCoords; 3 | uniform sampler2D u_texture; 4 | 5 | float rand(vec2 co) 6 | { 7 | return fract(sin(dot(co.xy ,vec2(100,100))) + 8 | cos(dot(co.xy ,vec2(50,50))) *5.0); 9 | } 10 | 11 | void main() 12 | { 13 | vec2 rnd = vec2(0.0); 14 | rnd = vec2(rand(v_texCoords),rand(v_texCoords)); 15 | gl_FragColor = texture2D(u_texture, v_texCoords+rnd*0.02); 16 | } -------------------------------------------------------------------------------- /Project/Android/app/src/main/assets/Resource/walkanim.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mingwuyun/cocos2d-java/f9534d0daa4ded45905ce670936f20ad5a314846/Project/Android/app/src/main/assets/Resource/walkanim.png -------------------------------------------------------------------------------- /Project/Android/app/src/main/assets/sfd/default.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mingwuyun/cocos2d-java/f9534d0daa4ded45905ce670936f20ad5a314846/Project/Android/app/src/main/assets/sfd/default.png -------------------------------------------------------------------------------- /Project/Android/app/src/main/assets/sfd/uiskin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mingwuyun/cocos2d-java/f9534d0daa4ded45905ce670936f20ad5a314846/Project/Android/app/src/main/assets/sfd/uiskin.png -------------------------------------------------------------------------------- /Project/Android/app/src/main/java/cn/cocos2d_java/MainActivity.java: -------------------------------------------------------------------------------- 1 | package cn.cocos2d_java; 2 | 3 | import tests.Activity_Tests; 4 | 5 | public class MainActivity extends Activity_Tests { 6 | 7 | } 8 | -------------------------------------------------------------------------------- /Project/Android/app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 | 17 | 18 | -------------------------------------------------------------------------------- /Project/Android/app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mingwuyun/cocos2d-java/f9534d0daa4ded45905ce670936f20ad5a314846/Project/Android/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /Project/Android/app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mingwuyun/cocos2d-java/f9534d0daa4ded45905ce670936f20ad5a314846/Project/Android/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /Project/Android/app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mingwuyun/cocos2d-java/f9534d0daa4ded45905ce670936f20ad5a314846/Project/Android/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /Project/Android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mingwuyun/cocos2d-java/f9534d0daa4ded45905ce670936f20ad5a314846/Project/Android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /Project/Android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mingwuyun/cocos2d-java/f9534d0daa4ded45905ce670936f20ad5a314846/Project/Android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /Project/Android/app/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /Project/Android/app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /Project/Android/app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 6 | -------------------------------------------------------------------------------- /Project/Android/app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Cocos2d-Java 3 | 4 | -------------------------------------------------------------------------------- /Project/Android/app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /Project/Android/build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | repositories { 5 | jcenter() 6 | } 7 | dependencies { 8 | classpath 'com.android.tools.build:gradle:2.2.1' 9 | 10 | // NOTE: Do not place your application dependencies here; they belong 11 | // in the individual module build.gradle files 12 | } 13 | } 14 | 15 | allprojects { 16 | repositories { 17 | jcenter() 18 | } 19 | } 20 | 21 | task clean(type: Delete) { 22 | delete rootProject.buildDir 23 | } 24 | -------------------------------------------------------------------------------- /Project/Android/gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | org.gradle.jvmargs=-Xmx1536m 13 | 14 | # When configured, Gradle will run in incubating parallel mode. 15 | # This option should only be used with decoupled projects. More details, visit 16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 17 | # org.gradle.parallel=true 18 | -------------------------------------------------------------------------------- /Project/Android/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mingwuyun/cocos2d-java/f9534d0daa4ded45905ce670936f20ad5a314846/Project/Android/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /Project/Android/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Mon Dec 28 10:00:20 PST 2015 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip 7 | -------------------------------------------------------------------------------- /Project/Android/gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /Project/Android/settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # cocos2d-java 2 | cocos2d java api base libgdx 3 | 4 | # 特别说明 5 | 作者最近用unity去了,暂时不更新了 6 | ------------------------------ 7 | 8 | # 环境部署 9 | 目录结构调整:
10 | src/ —— 引擎代码
11 | platform/{platform}/src —— 引擎与平台相关的代码,各平台对应的ApplicationStartup
12 | tests/src —— 测试工程的代码
13 | tests/src-{platform} —— 测试工程在指定平台上的启动代码
14 | ({platform} = desktop,android)
15 | 16 | ## 桌面版本运行 17 | source: 导入src/,platform/desktop/src,tests/src,tests/src-desktop;运行位于src-desktop中的Main启动函数
18 | libs: 导入libs/下jar包,所有platform/desktop中的jar包
19 | 20 | ## android版本运行 21 | source: 导入src/,platform/android/src,tests/src,tests/src-android; 继承Activity启动类或者直接设置为mainActivity启动;
22 | libs: 导入libs/下jar包,所有platform/android中的jar包,导入所有会指定平台的 **/*.so文件夹
23 | 24 | # 模块系统 25 | Cocos2dJava引擎自带了一套模块系统,可以方便的进行扩展。模块系统位于src/com/cocos2dj/module/路径下。引擎自带的模块源码在该目录下面;扩展模块的相关代码在external/com/cocos2dj/module/路径下。
26 | 当前引擎自带模块:gdxui/base2d/typefactory
27 | 扩展模块:visui/btree(behaviorTree)/box2d(未完成)/spine(计划中)
28 | 29 | 模块系统已经集成到了s2d/scene中,直接在scene的onEnter方法或者回调中添加模块即可,切换场景时引擎负责清理模块。
30 | 详细用法之后我会在wiki中补充。
31 | 32 | ## gdxui 33 | 该模块封装了gdx的scene2d相关内容。可以直接应用libgdx提供的组件。除此之外,引擎提供了两个方便调试的组件:GdxUIConsole和GdxUIDebugInfo。console添加后可以按下~按键呼叫。具体的用法在tests/TestAppDelegate_GdxUI中有例子
34 | 35 | ## base2d 36 | 该模块是系统默认的物理引擎。与box2d不同,该物理引擎基本不提供物理模拟功能,可以方便的制作平台类游戏。我在tests/testcase/Base2dTests中添加了几个例子。分别是:使用node的action驱动物理引擎;地面判定以及斜面跳跃解决方案;碰撞监听和对象休眠。该引擎适合非物理类但需要碰撞检测的游戏。 37 | 38 | ## TypeFactory 39 | 该模块是系统提供的原生对象池管理类。NodeType对象定义了一个对象池,调用getInstance()从池中回去对象,所有的node都可以调用pushBack将对象放回对象池中。该机制的使用在tests/testcase/TypeFactoryTests中有演示 40 | 41 | -------------------------------------------------------------------------------- /Resource/Pea.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mingwuyun/cocos2d-java/f9534d0daa4ded45905ce670936f20ad5a314846/Resource/Pea.png -------------------------------------------------------------------------------- /Resource/SpinningPeas.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mingwuyun/cocos2d-java/f9534d0daa4ded45905ce670936f20ad5a314846/Resource/SpinningPeas.png -------------------------------------------------------------------------------- /Resource/background.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mingwuyun/cocos2d-java/f9534d0daa4ded45905ce670936f20ad5a314846/Resource/background.png -------------------------------------------------------------------------------- /Resource/bh_test.json: -------------------------------------------------------------------------------- 1 | { 2 | "selector":{ 3 | "sequence":{ 4 | "leaf":{"key":"checkA","args":"debug"}, 5 | "leaf":{"key":"a","args":"debug"}, 6 | "leaf":{"key":"ALL1","args":"debug"}, 7 | "leaf":{"key":"ALL2","args":"debug"}, 8 | }, 9 | "sequence":{ 10 | "leaf":{"key":"checkB","args":"debug"}, 11 | "leaf":{"key":"b","args":"debug"}, 12 | "leaf":{"key":"ALL1","args":"debug"}, 13 | "leaf":{"key":"ALL2","args":"debug"}, 14 | }, 15 | } 16 | } -------------------------------------------------------------------------------- /Resource/bh_test_2.json: -------------------------------------------------------------------------------- 1 | { 2 | "selector":{ 3 | "parallel":{ 4 | "leaf":{"key":"atk_checkPlayer"}, 5 | "leaf":{"key":"atk_move"}, 6 | "leaf":{"key":"atk_shot"}, 7 | }, 8 | 9 | "parallel":{ 10 | "leaf":{"key":"idle_checkPlayer"}, 11 | "leaf":{"key":"idle_move"}, 12 | }, 13 | } 14 | } -------------------------------------------------------------------------------- /Resource/pack.atlas: -------------------------------------------------------------------------------- 1 | 2 | pack.png 3 | size: 512,64 4 | format: RGBA8888 5 | filter: Nearest,Nearest 6 | repeat: none 7 | scene_b1 8 | rotate: false 9 | xy: 2, 2 10 | size: 32, 32 11 | orig: 32, 32 12 | offset: 0, 0 13 | index: -1 14 | scene_b2 15 | rotate: false 16 | xy: 36, 2 17 | size: 32, 32 18 | orig: 32, 32 19 | offset: 0, 0 20 | index: -1 21 | scene_b3 22 | rotate: false 23 | xy: 70, 2 24 | size: 32, 32 25 | orig: 32, 32 26 | offset: 0, 0 27 | index: -1 28 | scene_b4 29 | rotate: false 30 | xy: 104, 2 31 | size: 32, 32 32 | orig: 32, 32 33 | offset: 0, 0 34 | index: -1 35 | scene_b5 36 | rotate: false 37 | xy: 138, 2 38 | size: 32, 32 39 | orig: 32, 32 40 | offset: 0, 0 41 | index: -1 42 | scene_b6 43 | rotate: false 44 | xy: 172, 2 45 | size: 32, 32 46 | orig: 32, 32 47 | offset: 0, 0 48 | index: -1 49 | scene_copy 50 | rotate: false 51 | xy: 206, 2 52 | size: 32, 32 53 | orig: 32, 32 54 | offset: 0, 0 55 | index: -1 56 | scene_del 57 | rotate: false 58 | xy: 240, 2 59 | size: 32, 32 60 | orig: 32, 32 61 | offset: 0, 0 62 | index: -1 63 | -------------------------------------------------------------------------------- /Resource/pack.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mingwuyun/cocos2d-java/f9534d0daa4ded45905ce670936f20ad5a314846/Resource/pack.png -------------------------------------------------------------------------------- /Resource/powered.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mingwuyun/cocos2d-java/f9534d0daa4ded45905ce670936f20ad5a314846/Resource/powered.png -------------------------------------------------------------------------------- /Resource/shader/flip.fragment.glsl: -------------------------------------------------------------------------------- 1 | // 反色 2 | varying vec2 v_texCoords; 3 | uniform sampler2D u_texture; 4 | 5 | void main() 6 | { 7 | vec4 col = texture2D( u_texture, v_texCoords); 8 | col.g=1.0-col.g; // 9 | col.r=1.0-col.r; // 10 | col.b=1.0-col.b; // 11 | gl_FragColor = col; 12 | // lowp vec4 col = texture2D(u_texture, v_texCoords); 13 | //col.g = 1.0 - col.g; 14 | //gl_FragColor = col; 15 | } -------------------------------------------------------------------------------- /Resource/shader/ice.fragment.glsl: -------------------------------------------------------------------------------- 1 | // 冰花效果 2 | varying vec2 v_texCoords; 3 | uniform sampler2D u_texture; 4 | 5 | float rand(vec2 co) 6 | { 7 | return fract(sin(dot(co.xy ,vec2(100,100))) + 8 | cos(dot(co.xy ,vec2(50,50))) *5.0); 9 | } 10 | 11 | void main() 12 | { 13 | vec2 rnd = vec2(0.0); 14 | rnd = vec2(rand(v_texCoords),rand(v_texCoords)); 15 | gl_FragColor = texture2D(u_texture, v_texCoords+rnd*0.02); 16 | } -------------------------------------------------------------------------------- /Resource/tiles.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mingwuyun/cocos2d-java/f9534d0daa4ded45905ce670936f20ad5a314846/Resource/tiles.png -------------------------------------------------------------------------------- /Resource/tiles.tmx: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 0,0,0,0,97,98,0,0,0,0,0,97,98,0,0, 7 | 0,0,0,97,105,105,98,0,0,97,101,105,105,98,0, 8 | 0,0,0,99,102,102,100,0,97,105,105,105,105,105,98, 9 | 115,116,0,0,0,0,0,0,99,102,102,102,102,102,100, 10 | 113,114,0,0,0,0,0,0,0,0,0,0,0,0,0, 11 | 113,114,0,0,0,0,0,0,16,0,0,0,0,0,0, 12 | 113,114,115,116,0,0,0,0,0,0,0,0,0,115,116, 13 | 113,114,113,114,0,0,0,0,0,0,0,0,0,113,114, 14 | 113,114,113,114,0,0,0,0,0,0,0,0,0,113,114, 15 | 113,114,113,114,0,0,0,0,0,0,0,0,0,113,114 16 | 17 | 18 | 19 | 20 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 21 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 22 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 23 | 0,0,0,0,0,0,0,0,0,109,5,2,6,108,0, 24 | 0,0,0,0,0,0,0,0,0,0,3,1,4,0,0, 25 | 0,0,0,0,0,0,0,0,0,0,10,11,12,0,0, 26 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 27 | 0,0,0,17,2,2,25,26,0,0,0,0,0,0,0, 28 | 0,0,17,18,57,57,1,24,25,26,0,0,0,0,0, 29 | 2,2,18,1,73,73,1,1,1,24,2,2,2,2,2 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /Resource/tiles.tsx: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /Resource/walkanim.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mingwuyun/cocos2d-java/f9534d0daa4ded45905ce670936f20ad5a314846/Resource/walkanim.png -------------------------------------------------------------------------------- /_record/record_1.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mingwuyun/cocos2d-java/f9534d0daa4ded45905ce670936f20ad5a314846/_record/record_1.txt -------------------------------------------------------------------------------- /external/com/cocos2dj/module/box2d/ModuleBox2d.java: -------------------------------------------------------------------------------- 1 | package com.cocos2dj.module.box2d; 2 | 3 | public class ModuleBox2d { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /external/com/cocos2dj/module/btree/BHSwitch.java: -------------------------------------------------------------------------------- 1 | package com.cocos2dj.module.btree; 2 | 3 | import com.badlogic.gdx.ai.btree.SingleRunningChildBranch; 4 | 5 | /** 6 | * 每次只会执行一个分支 7 | * 8 | * @author xujun 9 | * 10 | */ 11 | public class BHSwitch extends SingleRunningChildBranch { 12 | 13 | } 14 | -------------------------------------------------------------------------------- /external/com/cocos2dj/module/btree/BhLeafRunning.java: -------------------------------------------------------------------------------- 1 | package com.cocos2dj.module.btree; 2 | 3 | import com.badlogic.gdx.ai.btree.LeafTask; 4 | import com.badlogic.gdx.ai.btree.Task; 5 | 6 | public class BhLeafRunning extends LeafTask { 7 | 8 | @Override 9 | public com.badlogic.gdx.ai.btree.Task.Status execute() { 10 | return Status.RUNNING; 11 | } 12 | 13 | @Override 14 | protected Task copyTo(Task task) { 15 | return task; 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /external/com/cocos2dj/module/btree/BhLeafTask.java: -------------------------------------------------------------------------------- 1 | package com.cocos2dj.module.btree; 2 | 3 | import com.badlogic.gdx.ai.btree.LeafTask; 4 | import com.badlogic.gdx.ai.btree.Task; 5 | 6 | /** 7 | * 包装任务——方便先构建结构再写逻辑 8 | * @author xj 9 | * 10 | */ 11 | public class BhLeafTask extends LeafTask { 12 | 13 | @SuppressWarnings("rawtypes") 14 | public static class DebugTask extends BhLeafTask { 15 | 16 | final String name; 17 | public DebugTask(String name) { 18 | this.name = name; 19 | } 20 | 21 | public void start() { 22 | System.out.println("[" + name + "]" + " start"); 23 | super.start(); 24 | } 25 | 26 | @Override 27 | public Status execute() { 28 | Status ret = super.execute(); 29 | // System.out.println("[" + name + "]" + " start"); 30 | return ret; 31 | } 32 | 33 | public void end() { 34 | System.out.println("[" + name + "]" + " end"); 35 | super.end(); 36 | } 37 | 38 | } 39 | 40 | public static interface TaskListener { 41 | public void onStart(BhLeafTask task); 42 | public Status onExecute(BhLeafTask task); 43 | public void onEnd(BhLeafTask task); 44 | // public void onUpdate(); //常规更新,无论是否激活都会调用 45 | 46 | @SuppressWarnings("rawtypes") 47 | public static final TaskListener NULL = new TaskListener() { 48 | public void onStart(BhLeafTask task) {} 49 | public Status onExecute(BhLeafTask task) {return Status.FAILED;} 50 | public void onEnd(BhLeafTask task) {} 51 | }; 52 | } 53 | 54 | 55 | @SuppressWarnings("unchecked") 56 | private TaskListener listener = TaskListener.NULL; 57 | // protected boolean taskEndFlag = false; 58 | private Status forceStatus = null; 59 | 60 | @SuppressWarnings("unchecked") 61 | public void setTaskListener(TaskListener listener) { 62 | this.listener = listener == null ? TaskListener.NULL : listener; 63 | } 64 | 65 | // public final void setEnd(boolean flag) {this.taskEndFlag = flag;} 66 | // public void setTaskEndFlag(boolean flag) {this.taskEndFlag = flag;} 67 | // public final boolean getEnd() {return taskEndFlag;} 68 | // public boolean getTaskEndFlag() {return taskEndFlag;} 69 | /**强制结束 */ 70 | // public void () {taskEndFlag = true;} 71 | public void forceFail() { 72 | forceStatus = Status.FAILED; 73 | } 74 | public void forceSuccess() { 75 | forceStatus = Status.SUCCEEDED; 76 | } 77 | 78 | public void start() { 79 | forceStatus = null; 80 | // taskEndFlag = false; 81 | this.listener.onStart(this); 82 | } 83 | 84 | @Override 85 | public Status execute() { 86 | Status ret = listener.onExecute(this); 87 | if(forceStatus != null) { 88 | return forceStatus; 89 | } 90 | return ret; 91 | } 92 | 93 | public void end() { 94 | listener.onEnd(this); 95 | } 96 | 97 | @Override 98 | protected Task copyTo(Task arg0) { 99 | return arg0; 100 | } 101 | 102 | } 103 | -------------------------------------------------------------------------------- /external/com/cocos2dj/module/btree/BhTreeHelper.java: -------------------------------------------------------------------------------- 1 | package com.cocos2dj.module.btree; 2 | 3 | /** 4 | * BhTreeHelper.java 5 | *

6 | * 7 | * @author Copyright(c) 2017 xujun 8 | */ 9 | public interface BhTreeHelper { 10 | 11 | 12 | } 13 | -------------------------------------------------------------------------------- /external/com/cocos2dj/module/btree/BhTreeLoader.java: -------------------------------------------------------------------------------- 1 | package com.cocos2dj.module.btree; 2 | 3 | import com.badlogic.gdx.Gdx; 4 | import com.badlogic.gdx.utils.GdxRuntimeException; 5 | import com.badlogic.gdx.utils.JsonReader; 6 | import com.badlogic.gdx.utils.JsonValue; 7 | import com.cocos2dj.macros.CCLog; 8 | import com.cocos2dj.module.btree.BhTreeModel.StructBHTNode; 9 | 10 | public class BhTreeLoader { 11 | 12 | static final String TAG = "BhTreeLoader"; 13 | 14 | public BhTree parse(String path) { 15 | return parseJsonModelAndCreate( 16 | new JsonReader().parse(Gdx.files.internal(path)).child); 17 | } 18 | 19 | public BhTree parseJsonModelAndCreate(JsonValue jv_root) { 20 | BhTree bht = new BhTree(); 21 | BhTreeModel model = parseJsonModel(jv_root); 22 | CCLog.debug(TAG, model.toString()); 23 | bht.setup(model); 24 | return bht; 25 | } 26 | 27 | public BhTreeModel parseJsonModel(JsonValue jv_root) { 28 | BhTreeModel model = new BhTreeModel(); 29 | model.root = parseBHTNode(0, jv_root); 30 | return model; 31 | } 32 | 33 | final StructBHTNode parseBHTNode(int depth, JsonValue jv) { 34 | String name = jv.name; 35 | String args = jv.getString("args", null); 36 | String key = jv.getString("key", null); 37 | StructBHTNode BHTNode = new StructBHTNode(); 38 | BHTNode.type = name; 39 | BHTNode.args = args; 40 | BHTNode.key = key; 41 | BHTNode.depth = depth; 42 | 43 | int childrenCount = jv.size; 44 | if(args != null) { 45 | childrenCount -= 1; 46 | } 47 | if(key != null) { 48 | childrenCount -= 1; 49 | } 50 | if(childrenCount > 0) { 51 | BHTNode.children = new StructBHTNode[childrenCount]; 52 | } 53 | 54 | for(int i = 0, count = 0; i < jv.size; ++i) { 55 | JsonValue jv_child = jv.get(i); 56 | if(jv_child.name == null) { 57 | CCLog.error(TAG, "child name cannot be null!"); 58 | throw new GdxRuntimeException("child name cannot be null!"); 59 | } 60 | if(jv_child.name.equals("args") || jv_child.name.equals("key")) { 61 | continue; 62 | } 63 | 64 | BHTNode.children[count++] = parseBHTNode(depth+1, jv_child); 65 | } 66 | return BHTNode; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /external/com/cocos2dj/module/btree/BhTreeModel.java: -------------------------------------------------------------------------------- 1 | package com.cocos2dj.module.btree; 2 | 3 | public class BhTreeModel { 4 | 5 | public static class StructBHTNode { 6 | public String type; 7 | public String key; 8 | public String args; 9 | public StructBHTNode[] children; 10 | public int depth; 11 | final String createTabs() { 12 | StringBuilder sb = new StringBuilder(); 13 | for(int i = 0; i < depth; ++i) { 14 | for(int j = 0; j < 4; ++j) { 15 | sb.append(' '); 16 | } 17 | } 18 | return sb.toString(); 19 | } 20 | public String toString() { 21 | StringBuilder sb = new StringBuilder(); 22 | String tabs = createTabs(); 23 | sb.append(tabs).append("[").append(type).append("], "); 24 | if(key != null) { 25 | sb.append("key = ").append(key).append(", "); 26 | } 27 | if(args != null) { 28 | sb.append("args = ").append(args);//.append("\n"); 29 | } 30 | sb.append('\n'); 31 | if(children != null) { 32 | for(StructBHTNode node : children) { 33 | sb.append(node.toString()); 34 | } 35 | } 36 | // sb.append('\n'); 37 | return sb.toString(); 38 | } 39 | } 40 | 41 | public StructBHTNode root; 42 | 43 | public String toString() { 44 | return root.toString(); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /external/com/cocos2dj/module/visui/ModuleVisUI.java: -------------------------------------------------------------------------------- 1 | package com.cocos2dj.module.visui; 2 | 3 | import com.badlogic.gdx.scenes.scene2d.Actor; 4 | import com.cocos2dj.module.Module; 5 | import com.cocos2dj.module.gdxui.ModuleGdxUI; 6 | import com.cocos2dj.protocol.IScene; 7 | import com.cocos2dj.s2d.Scene; 8 | import com.kotcrab.vis.ui.VisUI; 9 | import com.kotcrab.vis.ui.util.TableUtils; 10 | import com.kotcrab.vis.ui.widget.VisScrollPane; 11 | import com.kotcrab.vis.ui.widget.VisTable; 12 | import com.kotcrab.vis.ui.widget.VisWindow; 13 | import com.kotcrab.vis.ui.widget.file.FileChooser; 14 | 15 | /** 16 | * ModuleVisUI.java 17 | *

18 | * 19 | * 添加逻辑:如果存在ModuleGdxUI则只添加本组件; 20 | * 如果不存在ModuleGdxUI会同GdxUI一起添加
21 | * 22 | * 使用方法: 23 | *

24 |  * scene.addModule(new ModuleVisUI());
25 |  * //gdxui = scene.createModule<'ModuleVisUI>(ModuleVisUI.class);
26 |  * 
27 | * @author Copyright (c) 2017 xu jun 28 | */ 29 | public class ModuleVisUI extends Module { 30 | 31 | public ModuleVisUI() { 32 | super(ModuleId, ModuleType); 33 | } 34 | 35 | public static VisScrollPane warpScrollPane(Actor widget, float width, float height) { 36 | return VisUIHelper.warpScrollPane(widget, width, height); 37 | } 38 | 39 | public static VisTable createTableWithDefaultBg() { 40 | return VisUIHelper.createTableWithDefaultBg(); 41 | } 42 | 43 | public static VisWindow createWindow(String windowName, float width, float height, boolean closeButton) { 44 | return VisUIHelper.createWindow(windowName, width, height, closeButton); 45 | } 46 | 47 | public static FileChooser createOpenFileChooser(float width, float height) { 48 | return VisUIHelper.createOpenFileChooser(width, height); 49 | } 50 | 51 | public static FileChooser createSaveFileChooser(float width, float height) { 52 | return VisUIHelper.createSaveFileChooser(width, height); 53 | } 54 | 55 | public static final String ModuleId = "VisUI"; 56 | public static final String ModuleType = "UIExt"; 57 | 58 | 59 | 60 | @Override 61 | public void onEnter(IScene iscene, Object config) { 62 | Scene scene = (Scene) iscene; 63 | _gdxui = (ModuleGdxUI) scene.getModule(ModuleGdxUI.class); 64 | if(_gdxui == null) { 65 | //gdx ui 不存在自动添加 66 | _gdxui = scene.createModule(ModuleGdxUI.class); 67 | } 68 | if(!VisUI.isLoaded()) { 69 | VisUI.load(); 70 | } 71 | VisUI.getSizes(); 72 | } 73 | 74 | @Override 75 | public void onExit(IScene scene) { 76 | 77 | } 78 | 79 | 80 | //methods>> 81 | public static void disposeVisUI() { 82 | VisUI.dispose(); 83 | } 84 | 85 | 86 | //methods<< 87 | 88 | public final ModuleGdxUI getGdxUI() {return _gdxui;} 89 | 90 | //fields>> 91 | ModuleGdxUI _gdxui; 92 | } 93 | -------------------------------------------------------------------------------- /external/com/cocos2dj/module/visui/VisUIHelper.java: -------------------------------------------------------------------------------- 1 | package com.cocos2dj.module.visui; 2 | 3 | import com.badlogic.gdx.scenes.scene2d.Actor; 4 | import com.kotcrab.vis.ui.util.TableUtils; 5 | import com.kotcrab.vis.ui.widget.VisScrollPane; 6 | import com.kotcrab.vis.ui.widget.VisTable; 7 | import com.kotcrab.vis.ui.widget.VisWindow; 8 | import com.kotcrab.vis.ui.widget.file.FileChooser; 9 | import com.kotcrab.vis.ui.widget.file.FileChooser.Mode; 10 | 11 | /** 12 | * VisUIhelper.java 13 | *

14 | * 15 | * @author Copyright(c) 2017 xujun 16 | */ 17 | public class VisUIHelper { 18 | 19 | public static VisScrollPane warpScrollPane(Actor widget, float width, float height) { 20 | VisScrollPane scrollPane = new VisScrollPane(widget); 21 | scrollPane.setFlickScroll(false); 22 | scrollPane.setFadeScrollBars(false); 23 | scrollPane.setSize(width, height); 24 | return scrollPane; 25 | } 26 | 27 | public static VisTable createTableWithDefaultBg() { 28 | VisTable table = new VisTable(); 29 | table.background("window-bg"); 30 | return table; 31 | } 32 | 33 | public static VisWindow createWindow(String windowName, float width, float height, boolean closeButton) { 34 | VisWindow ret = new VisWindow(windowName); 35 | ret.setSize(width, height); 36 | TableUtils.setSpacingDefaults(ret); 37 | if(closeButton) { 38 | ret.addCloseButton(); 39 | } 40 | return ret; 41 | } 42 | 43 | public static FileChooser createOpenFileChooser(float width, float height) { 44 | FileChooser chooser; 45 | FileChooser.setDefaultPrefsName("com.kotcrab.vis.ui.test.manual"); 46 | FileChooser.setSaveLastDirectory(true); 47 | chooser = new FileChooser(Mode.OPEN); 48 | chooser.setSelectionMode(FileChooser.SelectionMode.FILES_AND_DIRECTORIES); 49 | chooser.setMultiSelectionEnabled(true); 50 | chooser.setFavoriteFolderButtonVisible(true); 51 | 52 | chooser.setSize(width, height); 53 | return chooser; 54 | } 55 | 56 | public static FileChooser createSaveFileChooser(float width, float height) { 57 | FileChooser chooser; 58 | FileChooser.setDefaultPrefsName("com.kotcrab.vis.ui.test.manual"); 59 | FileChooser.setSaveLastDirectory(true); 60 | chooser = new FileChooser(Mode.SAVE); 61 | chooser.setSelectionMode(FileChooser.SelectionMode.FILES_AND_DIRECTORIES); 62 | chooser.setMultiSelectionEnabled(true); 63 | chooser.setFavoriteFolderButtonVisible(true); 64 | 65 | chooser.setSize(width, height); 66 | return chooser; 67 | } 68 | 69 | 70 | } 71 | -------------------------------------------------------------------------------- /libs/gdx-1.9.4.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mingwuyun/cocos2d-java/f9534d0daa4ded45905ce670936f20ad5a314846/libs/gdx-1.9.4.jar -------------------------------------------------------------------------------- /libs/gdx-ai-bh.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mingwuyun/cocos2d-java/f9534d0daa4ded45905ce670936f20ad5a314846/libs/gdx-ai-bh.jar -------------------------------------------------------------------------------- /libs/gdx-box2d-1.9.4.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mingwuyun/cocos2d-java/f9534d0daa4ded45905ce670936f20ad5a314846/libs/gdx-box2d-1.9.4.jar -------------------------------------------------------------------------------- /libs/gdx-freetype-1.9.4.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mingwuyun/cocos2d-java/f9534d0daa4ded45905ce670936f20ad5a314846/libs/gdx-freetype-1.9.4.jar -------------------------------------------------------------------------------- /libs/vis-1.2.4.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mingwuyun/cocos2d-java/f9534d0daa4ded45905ce670936f20ad5a314846/libs/vis-1.2.4.jar -------------------------------------------------------------------------------- /platform/android/arm64-v8a/libgdx-box2d.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mingwuyun/cocos2d-java/f9534d0daa4ded45905ce670936f20ad5a314846/platform/android/arm64-v8a/libgdx-box2d.so -------------------------------------------------------------------------------- /platform/android/arm64-v8a/libgdx.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mingwuyun/cocos2d-java/f9534d0daa4ded45905ce670936f20ad5a314846/platform/android/arm64-v8a/libgdx.so -------------------------------------------------------------------------------- /platform/android/armeabi-v7a/libgdx-box2d.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mingwuyun/cocos2d-java/f9534d0daa4ded45905ce670936f20ad5a314846/platform/android/armeabi-v7a/libgdx-box2d.so -------------------------------------------------------------------------------- /platform/android/armeabi-v7a/libgdx.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mingwuyun/cocos2d-java/f9534d0daa4ded45905ce670936f20ad5a314846/platform/android/armeabi-v7a/libgdx.so -------------------------------------------------------------------------------- /platform/android/armeabi/libgdx-box2d.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mingwuyun/cocos2d-java/f9534d0daa4ded45905ce670936f20ad5a314846/platform/android/armeabi/libgdx-box2d.so -------------------------------------------------------------------------------- /platform/android/armeabi/libgdx.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mingwuyun/cocos2d-java/f9534d0daa4ded45905ce670936f20ad5a314846/platform/android/armeabi/libgdx.so -------------------------------------------------------------------------------- /platform/android/gdx-backend-android-1.9.4.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mingwuyun/cocos2d-java/f9534d0daa4ded45905ce670936f20ad5a314846/platform/android/gdx-backend-android-1.9.4.jar -------------------------------------------------------------------------------- /platform/android/src/com/cocos2dj/platform/android/ApplicationStartup.java: -------------------------------------------------------------------------------- 1 | package com.cocos2dj.platform.android; 2 | 3 | import android.os.Bundle; 4 | 5 | import com.badlogic.gdx.backends.android.AndroidApplication; 6 | import com.badlogic.gdx.backends.android.AndroidApplicationConfiguration; 7 | import com.cocos2dj.basic.BaseGame; 8 | import com.cocos2dj.platform.AppDelegate; 9 | 10 | /** 11 | * ApplicationStartup.java 12 | *

13 | * 14 | * android版本启动函数 15 | *

16 |  *
17 |  * 
18 | * 19 | * @author Copyright (c) 2017 xu jun 20 | */ 21 | public class ApplicationStartup { 22 | 23 | static AndroidApplicationConfiguration configuration; 24 | 25 | public static final AndroidApplicationConfiguration getConfiguration() { 26 | if(configuration == null) { 27 | configuration = new AndroidApplicationConfiguration(); 28 | } 29 | return configuration; 30 | } 31 | 32 | public static final void start(AppDelegate appDelegate, AndroidApplication application) { 33 | application.initialize(new BaseGame(appDelegate), getConfiguration()); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /platform/android/x86/libgdx-box2d.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mingwuyun/cocos2d-java/f9534d0daa4ded45905ce670936f20ad5a314846/platform/android/x86/libgdx-box2d.so -------------------------------------------------------------------------------- /platform/android/x86/libgdx.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mingwuyun/cocos2d-java/f9534d0daa4ded45905ce670936f20ad5a314846/platform/android/x86/libgdx.so -------------------------------------------------------------------------------- /platform/android/x86_64/libgdx-box2d.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mingwuyun/cocos2d-java/f9534d0daa4ded45905ce670936f20ad5a314846/platform/android/x86_64/libgdx-box2d.so -------------------------------------------------------------------------------- /platform/android/x86_64/libgdx.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mingwuyun/cocos2d-java/f9534d0daa4ded45905ce670936f20ad5a314846/platform/android/x86_64/libgdx.so -------------------------------------------------------------------------------- /platform/desktop/gdx-backend-lwjgl-1.9.4.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mingwuyun/cocos2d-java/f9534d0daa4ded45905ce670936f20ad5a314846/platform/desktop/gdx-backend-lwjgl-1.9.4.jar -------------------------------------------------------------------------------- /platform/desktop/gdx-backend-lwjgl-natives.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mingwuyun/cocos2d-java/f9534d0daa4ded45905ce670936f20ad5a314846/platform/desktop/gdx-backend-lwjgl-natives.jar -------------------------------------------------------------------------------- /platform/desktop/gdx-box2d-platform-1.9.4-natives-desktop.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mingwuyun/cocos2d-java/f9534d0daa4ded45905ce670936f20ad5a314846/platform/desktop/gdx-box2d-platform-1.9.4-natives-desktop.jar -------------------------------------------------------------------------------- /platform/desktop/gdx-freetype-platform-1.9.4-natives-desktop.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mingwuyun/cocos2d-java/f9534d0daa4ded45905ce670936f20ad5a314846/platform/desktop/gdx-freetype-platform-1.9.4-natives-desktop.jar -------------------------------------------------------------------------------- /platform/desktop/gdx-platform-1.9.4-natives-desktop.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mingwuyun/cocos2d-java/f9534d0daa4ded45905ce670936f20ad5a314846/platform/desktop/gdx-platform-1.9.4-natives-desktop.jar -------------------------------------------------------------------------------- /platform/desktop/lwjgl-2.9.2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mingwuyun/cocos2d-java/f9534d0daa4ded45905ce670936f20ad5a314846/platform/desktop/lwjgl-2.9.2.jar -------------------------------------------------------------------------------- /platform/desktop/lwjgl_util-2.9.2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mingwuyun/cocos2d-java/f9534d0daa4ded45905ce670936f20ad5a314846/platform/desktop/lwjgl_util-2.9.2.jar -------------------------------------------------------------------------------- /platform/desktop/src/com/cocos2dj/platform/desktop/ApplicationStartup.java: -------------------------------------------------------------------------------- 1 | package com.cocos2dj.platform.desktop; 2 | 3 | import com.badlogic.gdx.backends.lwjgl.LwjglApplication; 4 | import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration; 5 | import com.cocos2dj.basic.BaseGame; 6 | import com.cocos2dj.platform.AppDelegate; 7 | 8 | /** 9 | * ApplicationStartup.java 10 | *

11 | * 12 | * 桌面版本启动函数 13 | *

14 |  * public static void main(String[] args) {
15 |  * 	LwjglApplicationConfiguration config =  ApplicationStartup.getConfiguration();
16 |  * 	//config.width = 1136; config.height = 640;
17 |  * 	ApplicationStartup.start(new MyAppDelegate());
18 |  * }
19 |  * 
20 | * 21 | * @author Copyright (c) 2017 xu jun 22 | */ 23 | public class ApplicationStartup { 24 | 25 | static LwjglApplicationConfiguration configuration; 26 | static LwjglApplication application; 27 | 28 | 29 | public static final LwjglApplicationConfiguration getConfiguration() { 30 | if(configuration == null) { 31 | configuration = new LwjglApplicationConfiguration(); 32 | } 33 | return configuration; 34 | } 35 | 36 | public static final void start(AppDelegate appDelegate) { 37 | application = new LwjglApplication( 38 | new BaseGame(appDelegate), 39 | getConfiguration() 40 | ); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/com/cocos2dj/base/CameraManager.java: -------------------------------------------------------------------------------- 1 | package com.cocos2dj.base; 2 | 3 | import com.cocos2dj.protocol.ICamera; 4 | 5 | /** 6 | * CameraManager.java 7 | *

8 | * 9 | * 相机管理 s2d组件不应该被其他组件引用 10 | * 因此camera系统添加两个辅助类型 11 | * CameraManager和ICamera;用来保存全局状态/代理Camera 12 | * 13 | * @author Copyright (c) 2017 xu jun 14 | * 15 | */ 16 | public final class CameraManager { 17 | 18 | // public 19 | public static ICamera _visitingCamera; 20 | 21 | } 22 | -------------------------------------------------------------------------------- /src/com/cocos2dj/base/Console.java: -------------------------------------------------------------------------------- 1 | package com.cocos2dj.base; 2 | 3 | public class Console { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /src/com/cocos2dj/base/Event.java: -------------------------------------------------------------------------------- 1 | package com.cocos2dj.base; 2 | 3 | import com.cocos2dj.protocol.INode; 4 | 5 | /** 6 | * Event.java 7 | *
Type 8 | *

9 | * 10 | * @author Copyright (c) 2017 xu jun 11 | */ 12 | public class Event { 13 | 14 | public static enum Type { 15 | TOUCH, 16 | KEYBOARD, 17 | ACCELERATION, 18 | MOUSE, 19 | FOCUS, 20 | GAME_CONTROLLER, 21 | CUSTOM 22 | }; 23 | 24 | public T getObject(T t) { 25 | return t; 26 | } 27 | 28 | Event(Type type) { 29 | this._type = type; 30 | } 31 | 32 | 33 | /** Gets the event type. 34 | * 35 | * @return The event type. 36 | */ 37 | public Type getType() { return _type; }; 38 | 39 | /** Stops propagation for current event. 40 | */ 41 | public void stopPropagation() { _isStopped = true; }; 42 | 43 | /** Checks whether the event has been stopped. 44 | * 45 | * @return True if the event has been stopped. 46 | */ 47 | public boolean isStopped() { return _isStopped; }; 48 | 49 | /** Gets current target of the event. 50 | * @return The target with which the event associates. 51 | * @note It's only available when the event listener is associated with node. 52 | * It returns 0 when the listener is associated with fixed priority. 53 | */ 54 | public INode getCurrentTarget() { return _currentTarget; }; 55 | 56 | /** Sets current target */ 57 | protected void setCurrentTarget(INode target) { _currentTarget = target; }; 58 | 59 | protected Type _type; ///< Event type 60 | 61 | protected boolean _isStopped; ///< whether the event has been stopped. 62 | protected INode _currentTarget; ///< Current target 63 | 64 | } 65 | -------------------------------------------------------------------------------- /src/com/cocos2dj/base/EventCustom.java: -------------------------------------------------------------------------------- 1 | package com.cocos2dj.base; 2 | 3 | /** 4 | * EventCustom.java 5 | *

6 | * 7 | * @author Copyright (c) 2017 xu jun 8 | */ 9 | public class EventCustom extends Event { 10 | /** Constructor. 11 | * 12 | * @param eventName A given name of the custom event. 13 | * @js ctor 14 | */ 15 | public EventCustom(String eventName) { 16 | super(Type.CUSTOM); 17 | this._eventName = eventName; 18 | } 19 | 20 | /** Sets user data. 21 | * 22 | * @param data The user data pointer, it's a void*. 23 | */ 24 | public final void setUserData(Object data) { _userData = data; } 25 | 26 | /** Gets user data. 27 | * 28 | * @return The user data pointer, it's a void*. 29 | */ 30 | public final Object getUserData() { return _userData; } 31 | 32 | /** Gets event name. 33 | * 34 | * @return The name of the event. 35 | */ 36 | public final String getEventName() { return _eventName; } 37 | 38 | protected Object _userData; ///< User data 39 | protected String _eventName; 40 | } 41 | -------------------------------------------------------------------------------- /src/com/cocos2dj/base/EventKeyboard.java: -------------------------------------------------------------------------------- 1 | package com.cocos2dj.base; 2 | 3 | /** 4 | * EventKeyboard.java 5 | *

6 | * 7 | * @author Copyright(c) 2017 xujun 8 | */ 9 | public class EventKeyboard extends Event { 10 | 11 | public EventKeyboard() { 12 | super(Type.KEYBOARD); 13 | } 14 | 15 | /** 16 | * @param keyCode A given keycode. 17 | * @param isPressed True if the key is pressed. 18 | */ 19 | public void init(int keyCode, boolean isPressed) { 20 | _keyCode = keyCode; 21 | _isPressed = isPressed; 22 | } 23 | 24 | public int getKeyCode() {return _keyCode;} 25 | public boolean isPressed() {return _isPressed;} 26 | 27 | private int _keyCode; 28 | private boolean _isPressed; 29 | } 30 | -------------------------------------------------------------------------------- /src/com/cocos2dj/base/EventListenerCustom.java: -------------------------------------------------------------------------------- 1 | package com.cocos2dj.base; 2 | 3 | import com.cocos2dj.protocol.IFunctionOneArg; 4 | 5 | public class EventListenerCustom extends EventListener { 6 | 7 | /** Creates an event listener with type and callback. 8 | * @param eventName The type of the event. 9 | * @param callback The callback function when the specified event was emitted. 10 | * @return An autoreleased EventListenerCustom object. 11 | */ 12 | public static EventListenerCustom create(String eventName, IFunctionOneArg callback) { 13 | EventListenerCustom ret = new EventListenerCustom(); 14 | ret.init(eventName, callback); 15 | return ret; 16 | } 17 | 18 | /// Overrides 19 | public boolean checkAvailable() { 20 | return _onCustomEvent != null && super.checkAvailable(); 21 | } 22 | 23 | // virtual EventListenerCustom* clone() override; 24 | 25 | /** Constructor */ 26 | protected EventListenerCustom() { 27 | 28 | } 29 | 30 | private IFunctionOneArg warpCallback = new IFunctionOneArg() { 31 | @Override 32 | public void callback(Event t) { 33 | if(_onCustomEvent != null) { 34 | _onCustomEvent.callback((EventCustom) t); 35 | } 36 | } 37 | }; 38 | 39 | /** Initializes event with type and callback function */ 40 | protected boolean init(String listenerId, IFunctionOneArg callback) { 41 | _onCustomEvent = callback; 42 | return super.init(Type.CUSTOM, listenerId, warpCallback); 43 | } 44 | 45 | protected IFunctionOneArg _onCustomEvent; 46 | 47 | } 48 | -------------------------------------------------------------------------------- /src/com/cocos2dj/base/EventListenerFocus.java: -------------------------------------------------------------------------------- 1 | package com.cocos2dj.base; 2 | 3 | public class EventListenerFocus { 4 | 5 | public static final String LISTENER_ID = "__cc_focus_event"; 6 | 7 | } 8 | -------------------------------------------------------------------------------- /src/com/cocos2dj/base/EventListenerKeyboard.java: -------------------------------------------------------------------------------- 1 | package com.cocos2dj.base; 2 | 3 | import com.cocos2dj.protocol.IFunctionOneArg; 4 | 5 | /** 6 | * EventListenerKeyboard.java 7 | *

8 | * 9 | * @author Copyright(c) 2017 xujun 10 | */ 11 | public class EventListenerKeyboard extends EventListener implements IFunctionOneArg { 12 | 13 | public static final String LISTENER_ID = "__cc_keyboard"; 14 | 15 | public static interface OnKeyPressedCallback {public void onKeyPressed(int keycode, Event e);} 16 | public static interface OnKeyReleassedCallback {public void onKeyReleassed(int keycode, Event e);} 17 | 18 | public static interface KeyCallback extends OnKeyPressedCallback, OnKeyReleassedCallback { 19 | public static final KeyCallback NULL = new KeyCallback() { 20 | public void onKeyPressed(int keycode, Event e) {} 21 | public void onKeyReleassed(int keycode, Event e) {} 22 | }; 23 | } 24 | 25 | OnKeyPressedCallback _onKeyPressedCallback = KeyCallback.NULL; 26 | OnKeyReleassedCallback _onKeyReleassedCallback = KeyCallback.NULL; 27 | 28 | public void setOnKeyPressedCallback(OnKeyPressedCallback callback) { 29 | _onKeyPressedCallback = callback == null ? KeyCallback.NULL : callback; 30 | } 31 | public void setOnKeyReleassedCallback(OnKeyReleassedCallback callback) { 32 | _onKeyReleassedCallback = callback == null ? KeyCallback.NULL : callback; 33 | } 34 | 35 | public void setKeyCallback(KeyCallback callback) { 36 | setOnKeyPressedCallback(callback); 37 | setOnKeyReleassedCallback(callback); 38 | } 39 | 40 | 41 | public static EventListenerKeyboard create() { 42 | EventListenerKeyboard ret = new EventListenerKeyboard(); 43 | ret.init(); 44 | return ret; 45 | } 46 | 47 | /**use {@link #create()} */ 48 | public EventListenerKeyboard() {} 49 | 50 | public boolean init() { 51 | return init(Type.KEYBOARD, LISTENER_ID, this); 52 | } 53 | 54 | 55 | @Override 56 | public final void callback(Event t) { 57 | EventKeyboard e = (EventKeyboard) t; 58 | if(e.isPressed()) { 59 | _onKeyPressedCallback.onKeyPressed(e.getKeyCode(), e); 60 | } else { 61 | _onKeyReleassedCallback.onKeyReleassed(e.getKeyCode(), e); 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/com/cocos2dj/base/EventTouch.java: -------------------------------------------------------------------------------- 1 | package com.cocos2dj.base; 2 | 3 | import com.badlogic.gdx.utils.Array; 4 | 5 | public class EventTouch extends Event { 6 | 7 | public static final int MAX_TOUCHES = 15; 8 | 9 | public static enum EventCode { 10 | BEGAN, 11 | MOVED, 12 | ENDED, 13 | CANCELLED, 14 | } 15 | 16 | public EventTouch() { 17 | super(Type.TOUCH); 18 | } 19 | 20 | 21 | /** Get event code. 22 | * 23 | * @return The code of the event. 24 | */ 25 | public EventCode getEventCode() { return _eventCode; }; 26 | 27 | public void setEventCode(EventCode eventCode) { 28 | _eventCode = eventCode; 29 | } 30 | 31 | /** Get the touches. 32 | * 33 | * @return The touches of the event. 34 | */ 35 | public final Array getTouches() { return _touches; }; 36 | 37 | private EventCode _eventCode; 38 | private Array _touches = new Array<>(); 39 | 40 | 41 | 42 | /**不要调用 */ 43 | public final void _clearTouch() { 44 | _touches.clear(); 45 | } 46 | 47 | /**不要调用 */ 48 | public void _addTouch(Touch touch) { 49 | //超出15个就删除一个 50 | if(_touches.size > MAX_TOUCHES) { 51 | _touches.removeIndex(0); 52 | } 53 | _touches.add(touch); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/com/cocos2dj/base/Rect.java: -------------------------------------------------------------------------------- 1 | package com.cocos2dj.base; 2 | 3 | import com.badlogic.gdx.math.Rectangle; 4 | import com.badlogic.gdx.math.Vector2; 5 | 6 | 7 | public class Rect extends Rectangle { 8 | 9 | private static final long serialVersionUID = -3855101754113979241L; 10 | private static final Rect _rect = new Rect(); 11 | 12 | public static Rect getStackInstance() { 13 | return _rect; 14 | } 15 | 16 | /** 17 | * 值传递使用的Rect 返回一个静态Rect 18 | */ 19 | public static Rect Get(float x, float y, float w, float h) { 20 | return (Rect) _rect.set(x, y, w, h); 21 | } 22 | 23 | public Rect() { 24 | super(); 25 | } 26 | 27 | public boolean isZero() { 28 | return x == 0 && y == 0 && width == 0 && height == 0; 29 | } 30 | 31 | /** 32 | * @js NA 33 | */ 34 | public Rect(float x, float y, float width, float height) { 35 | super(x, y, width, height); 36 | } 37 | 38 | /** 39 | * @js NA 40 | * @lua NA 41 | */ 42 | public Rect(Rect other) { 43 | super(other); 44 | } 45 | 46 | public Rect(Rectangle other) { 47 | super(other); 48 | } 49 | 50 | 51 | /** 52 | * @js NA 53 | * @lua NA 54 | */ 55 | public void setRect(float x, float y, float width, float height) { 56 | this.set(x, y, width, height); 57 | } 58 | 59 | public boolean containsPoint(float x, float y) { 60 | return contains(x, y); 61 | } 62 | 63 | /** 64 | * @js NA 65 | */ 66 | public boolean containsPoint(Vector2 point) { 67 | return contains(point); 68 | } 69 | /** 70 | * @js NA 71 | */ 72 | public boolean intersectsRect(final Rect rect) { 73 | return contains(rect); 74 | } 75 | /** 76 | * @js NA 77 | * @lua NA 78 | */ 79 | public Rect unionWithRect(final Rect rect) { 80 | Rectangle ret = merge(rect); 81 | if(ret instanceof Rect) { 82 | return (Rect) ret; 83 | } else { 84 | return new Rect(rect); 85 | } 86 | } 87 | 88 | public float getMinX() {return x;} 89 | public float getMinY() {return y;} 90 | public float getMaxX() {return x + width;} 91 | public float getMaxY() {return y + height;} 92 | static final Rect ZERO = new Rect(); 93 | } 94 | -------------------------------------------------------------------------------- /src/com/cocos2dj/base/Size.java: -------------------------------------------------------------------------------- 1 | package com.cocos2dj.base; 2 | 3 | import com.badlogic.gdx.math.Vector2; 4 | import com.badlogic.gdx.utils.NumberUtils; 5 | 6 | public final class Size { 7 | 8 | public float width; 9 | public float height; 10 | 11 | public Size() {} 12 | public Size(float width, float height) { 13 | this.width = width; 14 | this.height = height; 15 | } 16 | public Size(Size other) { 17 | this.width = other.width; 18 | this.height = other.height; 19 | } 20 | 21 | public Vector2 vector2() { 22 | return new Vector2(width, height); 23 | } 24 | 25 | public Size set(Size other) { 26 | this.width = other.width; 27 | this.height = other.height; 28 | return this; 29 | } 30 | 31 | public Size setSize(float width, float height) { 32 | this.width = width; 33 | this.height = height; 34 | return this; 35 | } 36 | 37 | public String toString() { 38 | return "{w=" + width + ", h=" + height + "}"; 39 | } 40 | 41 | public boolean equals(Size obj) { 42 | if (this == obj) return true; 43 | if (obj == null) return false; 44 | if (getClass() != obj.getClass()) return false; 45 | Size other = (Size)obj; 46 | if (NumberUtils.floatToIntBits(width) != NumberUtils.floatToIntBits(other.width)) return false; 47 | if (NumberUtils.floatToIntBits(height) != NumberUtils.floatToIntBits(other.height)) return false; 48 | return true; 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /src/com/cocos2dj/basic/BaseCoreTimer.java: -------------------------------------------------------------------------------- 1 | package com.cocos2dj.basic; 2 | 3 | /** 4 | * SCoreTimer.java

5 | * 6 | * 引擎内部时间 会进行平滑处理 7 | * 8 | * @author Copyright (c) 2012-2017 xu jun 9 | */ 10 | public final class BaseCoreTimer { 11 | 12 | //--------------smooth delta----------------------// 13 | static final int SMOOTH_COUNT = 32; 14 | static final float[] deltaList = new float[SMOOTH_COUNT]; 15 | static int currDeltaPoint = 0; 16 | static float currDeltaTotal = 0; 17 | static int deltaListSize = 0; 18 | 19 | ////////////////////////////// 20 | 21 | private static final void addDelta(float newDelta) { 22 | if(deltaListSize >= deltaList.length) { 23 | currDeltaTotal -= deltaList[currDeltaPoint]; 24 | deltaList[currDeltaPoint++] = newDelta; 25 | currDeltaTotal += newDelta; 26 | if(currDeltaPoint >= deltaListSize) { 27 | currDeltaPoint = 0; 28 | } 29 | } 30 | else { 31 | deltaList[deltaListSize++] = newDelta; 32 | currDeltaTotal += newDelta; 33 | } 34 | } 35 | 36 | static final float getSmoothDelta(float newDelta) { 37 | addDelta(newDelta); 38 | float ret = currDeltaTotal / deltaListSize; 39 | return ret; 40 | } 41 | 42 | /**更新内部时间 43 | * @return 平滑时间 */ 44 | public static final float update() { 45 | currentTime = System.currentTimeMillis(); 46 | final int tempdelta = ((int) (currentTime - lastTime)); 47 | lastTime = currentTime; 48 | // if(delta > 28) updateCount(1); 49 | // else updateCount(0); 50 | // 51 | //// deltaSecond = Gdx.graphics.getDeltaTime(); 52 | //// delta = (int) (deltaSecond * 1000f); 53 | // if(rate > 0.5f) { 54 | // delta = 32; 55 | // deltaSecond = 32 / 1000f; 56 | // } 57 | // else { 58 | // delta = 16; 59 | // deltaSecond = 16 / 1000f; 60 | // } 61 | // if(delta > 64) {delta = 64;} 62 | // deltaSecond = delta / 1000f; 63 | 64 | delta = getSmoothDelta(tempdelta > 100 ? 100 : tempdelta); 65 | delta = delta < 1f ? 1f : delta; 66 | deltaSecond = delta / 1000f; 67 | return delta; 68 | } 69 | 70 | /**重置时间 */ 71 | public static final void updateLastTime() { 72 | lastTime = System.currentTimeMillis(); 73 | } 74 | 75 | ////////////////////////// 76 | private static long currentTime, lastTime; 77 | public static float delta; 78 | public static float deltaSecond; 79 | } 80 | -------------------------------------------------------------------------------- /src/com/cocos2dj/basic/BaseGame.java: -------------------------------------------------------------------------------- 1 | package com.cocos2dj.basic; 2 | 3 | import com.badlogic.gdx.ApplicationListener; 4 | import com.cocos2dj.platform.AppDelegate; 5 | 6 | /** 7 | * BaseGame.java 8 | *

9 | * 10 | * @author Copyright (c) 2015-2017 xu jun 11 | */ 12 | public class BaseGame implements ApplicationListener { 13 | 14 | final AppDelegate appDelegate; 15 | 16 | public BaseGame(AppDelegate appDelegate) { 17 | this.appDelegate = appDelegate; 18 | } 19 | 20 | 21 | public void create() { 22 | appDelegate.initConfiguration(); 23 | 24 | Engine.newEngine(this); 25 | // EngineSetting(); 26 | Engine.instance().initializeEngine(); 27 | // gameInitialize(); 28 | Engine.instance().startEngine(); 29 | // gameStart(); 30 | appDelegate.applicationDidFinishLaunching(); 31 | } 32 | 33 | public void dispose () { 34 | // gameEnd(); 35 | Engine.instance().endEngine(); 36 | } 37 | 38 | public void pause () { 39 | appDelegate.applicationDidEnterBackground(); 40 | Engine.instance().pauseEngine(); 41 | } 42 | 43 | public void resume () { 44 | appDelegate.applicationWillEnterForeground(); 45 | Engine.instance().activeEngine(); 46 | } 47 | 48 | public void render () { 49 | Engine.instance().render(); 50 | } 51 | 52 | public void resize (int width, int height) { 53 | 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/com/cocos2dj/basic/BaseInput.java: -------------------------------------------------------------------------------- 1 | package com.cocos2dj.basic; 2 | 3 | import com.badlogic.gdx.Gdx; 4 | import com.badlogic.gdx.InputEventQueue; 5 | import com.badlogic.gdx.InputMultiplexer; 6 | import com.badlogic.gdx.InputProcessor; 7 | 8 | /** 9 | * BaseInput.java 10 | *

11 | * 封装了gdx中的输入事件系统 由engine负责调用驱动 12 | * 13 | * @author Copyright (c) 2017 xu jun 14 | */ 15 | public class BaseInput implements IDisposable { 16 | 17 | private static BaseInput _instance; 18 | public static BaseInput instance() { 19 | if(_instance == null) { 20 | _instance = new BaseInput(); 21 | _instance.init(); 22 | Engine.registerDisposable(_instance); 23 | } 24 | return _instance; 25 | } 26 | private BaseInput() {} 27 | 28 | @Override 29 | public void dispose() { 30 | _instance = null; 31 | } 32 | 33 | 34 | InputEventQueue _inputQueue; 35 | InputMultiplexer _multiplexer; 36 | InputMultiplexer _rootMultiPlexer; 37 | 38 | 39 | final void init() { 40 | _rootMultiPlexer = new InputMultiplexer(); 41 | _multiplexer = new InputMultiplexer(); 42 | _inputQueue = new InputEventQueue(_multiplexer); 43 | 44 | _rootMultiPlexer.addProcessor(_inputQueue); 45 | Gdx.input.setInputProcessor(_rootMultiPlexer); 46 | } 47 | 48 | final void update() { 49 | _inputQueue.drain(); 50 | } 51 | 52 | 53 | public final void clearInputProcessor() { 54 | _multiplexer.clear(); 55 | } 56 | 57 | public final int addInputProcessor(int index, InputProcessor processor) { 58 | _multiplexer.addProcessor(index, processor); 59 | return index; 60 | } 61 | 62 | public final int pushInputProcessor(InputProcessor processor) { 63 | _multiplexer.addProcessor(0, processor); 64 | return 0; 65 | } 66 | 67 | public final int addInputProcessor(InputProcessor processor) { 68 | int ret = _multiplexer.size(); 69 | _multiplexer.addProcessor(processor); 70 | return ret; 71 | } 72 | 73 | public final void removeInputProcessor(InputProcessor processor) { 74 | _multiplexer.removeProcessor(processor); 75 | } 76 | 77 | public final void removeInputProcessor(int index) { 78 | _multiplexer.removeProcessor(index); 79 | } 80 | 81 | } 82 | -------------------------------------------------------------------------------- /src/com/cocos2dj/basic/BaseRandTimer.java: -------------------------------------------------------------------------------- 1 | package com.cocos2dj.basic; 2 | 3 | import com.badlogic.gdx.math.MathUtils; 4 | 5 | /** 6 | * Storm Engine��ʱ�� �ö�ʱ�����ܵ�����״̬��Ӱ�죬��ͣ�����߳�ʱ��������ֹͣ

7 | * 8 | * �ö�ʱ�����ò�ѯ�ķ�ʽ���С���C2Timer�������������У�ֻ�е����ض��IJ�ѯ״̬�� 9 | * ���·�����Ż��������ʱ�����ж��Ƿ񵽶�ʱʱ�䡣�������Ϊ��Ҫ������������߳�

10 | * 11 | * ͨ������{@link #overTime()}��������ȡ��ʱ��Ϣ�� 12 | * ���ע����TimeListener�����ͨ������ {@link #updateTime()}���������¶�ʱ��״̬��

13 | * 14 | * �趨һ��ʱ�䷶Χ��������շ��ط�Χ�ڵ�ʱ����¼�ʱ 15 | * 16 | * ��ʱ���Ĺ�����ʽ�У� 17 | *

  • UNIFORM_DELAY_LOOP: ��ָ���ļ����ʱ 18 | *
  • ORDER_DELAY_LOOP����ָ����һ������ʱ 19 | *
  • ONCE��ֻ��ʱһ�Σ�Ȼ����ִͣ�� 20 | * 21 | * @author xu jun 22 | * Copyright (c) 2015. All rights reserved. 23 | */ 24 | public class BaseRandTimer extends BaseTimer { 25 | 26 | private long start, end; 27 | 28 | public BaseRandTimer(){} 29 | 30 | public BaseRandTimer(long start, long end) { 31 | this.setIntervalRange(start, end); 32 | this.restart(); 33 | } 34 | 35 | 36 | public void setIntervalRange(long start, long end) { 37 | this.start = start; 38 | this.end = end; 39 | } 40 | 41 | // public SRandTimer(int delay){ 42 | // super(new int[]{delay}); 43 | // } 44 | // 45 | // public SRandTimer(int delay, boolean running) { 46 | // super(ORDER_DELAY_LOOP, running, new int[]{delay}); 47 | // } 48 | // 49 | // public SRandTimer(int...delays){ 50 | // super(ORDER_DELAY_LOOP, delays); 51 | // } 52 | // 53 | // public SRandTimer(int type, int...delays){ 54 | // super(type, true, delays); 55 | // } 56 | // 57 | // public SRandTimer(int type, boolean running, int...delays){ 58 | // super(type, running, delays); 59 | // } 60 | 61 | @Override 62 | public boolean updateTimer(){ 63 | if(!running){ 64 | return false; 65 | } 66 | final long currentTime = BaseTimer.getEngineTime(); 67 | if(currentTime > nextTime){ 68 | // nextInterval(); 69 | //������� 70 | long interval = MathUtils.random(start, end); 71 | // currentiInterval = MathUtils.random(intervals.length - 1); 72 | nextTime = currentTime + interval; // + intervals[currentiInterval]; 73 | return true; 74 | } 75 | return false; 76 | } 77 | 78 | @Override 79 | /**ʹnextTimeָ����ȷ��ʱ�� */ 80 | public final void updateNextTime() { 81 | long interval = MathUtils.random(start, end); 82 | nextTime = BaseTimer.getEngineTime() + interval; // + intervals[currentiInterval]; 83 | // nextTime = System.currentTimeMillis() + intervals[currentiInterval]; 84 | } 85 | } 86 | 87 | -------------------------------------------------------------------------------- /src/com/cocos2dj/basic/BaseSystemTimer.java: -------------------------------------------------------------------------------- 1 | package com.cocos2dj.basic; 2 | 3 | /** 4 | * Card2D Engine��ʱ�� �ö�ʱ�����ܵ�����״̬��Ӱ�죬��ͣ�����߳�ʱ��������ֹͣ

    5 | * 6 | * �ö�ʱ�����ò�ѯ�ķ�ʽ���С���C2Timer�������������У�ֻ�е����ض��IJ�ѯ״̬�� 7 | * ���·�����Ż��������ʱ�����ж��Ƿ񵽶�ʱʱ�䡣�������Ϊ��Ҫ������������߳�

    8 | * 9 | * ͨ������{@link #overTime()}��������ȡ��ʱ��Ϣ�� 10 | * ���ע����TimeListener�����ͨ������ {@link #updateTime()}���������¶�ʱ��״̬��

    11 | * 12 | * ��ʱ���Ĺ�����ʽ�У� 13 | *

  • UNIFORM_DELAY_LOOP: ��ָ���ļ����ʱ 14 | *
  • ORDER_DELAY_LOOP����ָ����һ������ʱ 15 | *
  • ONCE��ֻ��ʱһ�Σ�Ȼ����ִͣ�� 16 | * 17 | * @author xu jun 18 | * Copyright (c) 2015. All rights reserved. 19 | */ 20 | public class BaseSystemTimer extends BaseTimer { 21 | 22 | public BaseSystemTimer(){} 23 | 24 | public BaseSystemTimer(int delay){ 25 | super(new int[]{delay}); 26 | } 27 | 28 | public BaseSystemTimer(int delay, boolean running) { 29 | super(ORDER_DELAY_LOOP, running, new int[]{delay}); 30 | } 31 | 32 | public BaseSystemTimer(int...delays){ 33 | super(ORDER_DELAY_LOOP, delays); 34 | } 35 | 36 | public BaseSystemTimer(int type, int...delays){ 37 | super(type, true, delays); 38 | } 39 | 40 | public BaseSystemTimer(int type, boolean running, int...delays){ 41 | super(type, running, delays); 42 | } 43 | 44 | 45 | @Override 46 | public boolean updateTimer(){ 47 | if(!running){ 48 | return false; 49 | } 50 | final long currentTime = System.currentTimeMillis(); 51 | if(currentTime > nextTime){ 52 | nextInterval(); 53 | nextTime = currentTime + intervals[currentiInterval]; 54 | return true; 55 | } 56 | return false; 57 | } 58 | 59 | @Override 60 | /**ʹnextTimeָ����ȷ��ʱ�� */ 61 | public final void updateNextTime() { 62 | nextTime = System.currentTimeMillis() + intervals[currentiInterval]; 63 | } 64 | } 65 | 66 | -------------------------------------------------------------------------------- /src/com/cocos2dj/basic/BaseTask.java: -------------------------------------------------------------------------------- 1 | package com.cocos2dj.basic; 2 | 3 | /** 4 | * BaseTask.java 5 | *

    6 | * 7 | * 推荐的使用方法: 8 | *

     9 |  * new BaseTask(()->{
    10 |  * //do something
    11 |  * }.attachSchedule(); //添加到main(cocos)线程执行
    12 |  * 
    13 |  * new BaseTask(()->{
    14 |  * //do something
    15 |  * }.attachScheduleToRender(); //添加到render(gl)线程执行 
    16 |  * 
    17 | * 18 | * @author Copyright (c) 2016 xu jun 19 | */ 20 | public class BaseTask extends BaseUpdater { 21 | 22 | private Runnable runnable; 23 | private int frameDelay = -1; 24 | 25 | public static BaseTask create(Runnable runnable) { 26 | return new BaseTask(runnable); 27 | } 28 | 29 | public BaseTask(Runnable runnable) { 30 | this(runnable, -1); 31 | } 32 | 33 | public BaseTask(Runnable runnable, int frameDelay) { 34 | this.runnable = runnable; 35 | this.frameDelay = frameDelay; 36 | } 37 | 38 | @Override 39 | protected final boolean onUpdate(float dt) { 40 | if(frameDelay-- <= 0) { 41 | runnable.run(); 42 | return true; 43 | } else { 44 | return false; 45 | } 46 | } 47 | 48 | @Override 49 | protected final void onEnd() { 50 | 51 | } 52 | 53 | } 54 | 55 | -------------------------------------------------------------------------------- /src/com/cocos2dj/basic/EngineLock.java: -------------------------------------------------------------------------------- 1 | package com.cocos2dj.basic; 2 | 3 | import java.util.concurrent.atomic.AtomicBoolean; 4 | import java.util.concurrent.locks.Condition; 5 | import java.util.concurrent.locks.ReentrantLock; 6 | 7 | /**协调双线程的锁*/ 8 | public class EngineLock extends ReentrantLock { 9 | 10 | private static final long serialVersionUID = 671220941302523934L; 11 | 12 | final Condition mDrawingCondition = this.newCondition(); 13 | final AtomicBoolean mDrawing = new AtomicBoolean(false); 14 | 15 | 16 | public EngineLock(final boolean pFair) { 17 | super(pFair); 18 | } 19 | 20 | /**唤醒绘制线程 21 | * @see java.util.concurrent.locks.Condition.signalAll()*/ 22 | public final void notifyCanDraw() { 23 | this.mDrawing.set(true); 24 | this.mDrawingCondition.signalAll(); 25 | } 26 | 27 | /**唤醒逻辑线程*/ 28 | public final void notifyCanUpdate() { 29 | this.mDrawing.set(false); 30 | this.mDrawingCondition.signalAll(); 31 | } 32 | 33 | /**通知绘制线程等待*/ 34 | public final void waitUntilCanDraw() throws InterruptedException { 35 | while(!this.mDrawing.get()) { 36 | this.mDrawingCondition.await(); 37 | } 38 | } 39 | 40 | /**通知逻辑线程等待*/ 41 | public final void waitUntilCanUpdate() throws InterruptedException { 42 | while(this.mDrawing.get()) { 43 | this.mDrawingCondition.await(); 44 | } 45 | } 46 | } -------------------------------------------------------------------------------- /src/com/cocos2dj/basic/IDisposable.java: -------------------------------------------------------------------------------- 1 | package com.cocos2dj.basic; 2 | 3 | public interface IDisposable { 4 | public void dispose(); 5 | } 6 | -------------------------------------------------------------------------------- /src/com/cocos2dj/basic/SConfig.java: -------------------------------------------------------------------------------- 1 | package com.cocos2dj.basic; 2 | 3 | import java.util.HashMap; 4 | 5 | import com.badlogic.gdx.utils.GdxRuntimeException; 6 | 7 | /** 8 | * ����

    9 | * 10 | * ����ϵͳ��������һ����Engine������ϵͳ���ã� 11 | * ��һ����ͨ����̬������ȡ����Ϸ����

    12 | * 13 | * @author xu jun 14 | * Copyright (c) 2015-2016. All rights reserved. */ 15 | public class SConfig implements IDisposable { 16 | 17 | //object�������ã��������õ��� 18 | private final HashMap, Object> configMap = new HashMap, Object>(); 19 | 20 | //���ò�����㴴�� 21 | SConfig() {} 22 | 23 | public final void putConfig(Object conf) { 24 | this.putConfig(conf.getClass(), conf); 25 | } 26 | 27 | public final void putConfig(Class clazz, Object conf) { 28 | Object o = configMap.put(clazz, conf); 29 | if(o != null) { 30 | throw new GdxRuntimeException("�������Ѿ����� :" + clazz); 31 | } 32 | } 33 | 34 | public final void removeConfig(Class clazz) { 35 | Object o = configMap.remove(clazz); 36 | if(o == null) { 37 | BaseLog.error("SConfig", "���ò����� clazz = " + clazz); 38 | // throw new GdxRuntimeException("���ò����� :" + clazz); 39 | } 40 | } 41 | 42 | public final Object getConfig(Class clazz) { 43 | return configMap.get(clazz); 44 | } 45 | 46 | /**��Ϣϵͳ����Ų������� */ 47 | public static final int MSG_MAX_ARG_COUNT = 8; 48 | 49 | @Override 50 | public void dispose() { 51 | gameConfig = null; 52 | } 53 | 54 | //�����Ƕ��ⲿ�Ľӿ� 55 | //static>> 56 | private static SConfig gameConfig; 57 | public static SConfig instance() { 58 | if(gameConfig == null) { 59 | gameConfig = new SConfig(); 60 | Engine.registerDisposable(gameConfig); 61 | } 62 | return gameConfig; 63 | } 64 | //static<< 65 | 66 | 67 | } 68 | -------------------------------------------------------------------------------- /src/com/cocos2dj/macros/CC.java: -------------------------------------------------------------------------------- 1 | package com.cocos2dj.macros; 2 | 3 | import com.badlogic.gdx.files.FileHandle; 4 | import com.badlogic.gdx.graphics.g2d.TextureAtlas; 5 | import com.cocos2dj.base.Director; 6 | import com.cocos2dj.module.Module; 7 | import com.cocos2dj.platform.FileUtils; 8 | import com.cocos2dj.renderer.Texture; 9 | import com.cocos2dj.s2d.Scene; 10 | import com.cocos2dj.s2d.SpriteFrameCache; 11 | 12 | public final class CC { 13 | 14 | @SuppressWarnings("unchecked") 15 | public static T GetRunningSceneModule(Class clazz) { 16 | return (T) GetRunningScene().getModule(clazz); 17 | } 18 | 19 | public static Scene GetRunningScene() { 20 | return (Scene) Director.getInstance().getRunningScene(); 21 | } 22 | 23 | public static com.cocos2dj.base.Scheduler Scheduler() { 24 | return Director.getInstance().getScheduler(); 25 | } 26 | 27 | public static Director Director() { 28 | return Director.getInstance(); 29 | } 30 | 31 | //image 32 | public static Texture LoadImage(String fileName) { 33 | Texture t = Director.getInstance().getTextureCache().addImage(fileName); 34 | return t; 35 | } 36 | 37 | /**创建并返回TextureAtlas对象 不会添加到 38 | * SpriteFrameCache */ 39 | public static TextureAtlas TextureAtlas(String packName) { 40 | return new TextureAtlas(CC.File(packName)); 41 | } 42 | 43 | /**创建并返回TextureAtlas对象 不会添加到 44 | * SpriteFrameCache */ 45 | public static TextureAtlas TextureAtlas(String packName, String imgPath) { 46 | return new TextureAtlas(CC.File(packName), CC.File(imgPath)); 47 | } 48 | 49 | /** 50 | * 装载atlas对象 会添加到SpriteFrameCache中 51 | * @param packName 52 | */ 53 | public static void LoadAtlas(String packName) { 54 | if(SpriteFrameCache.instance().findTextureAtlas(packName) != null) { 55 | return; 56 | } 57 | TextureAtlas ta = new TextureAtlas(CC.File(packName)); 58 | SpriteFrameCache.instance().addSpriteFrameWithTextureAtlas(packName, ta); 59 | } 60 | 61 | public static void LoadAtlas(String packName, String imgPath) { 62 | if(SpriteFrameCache.instance().findTextureAtlas(packName) != null) { 63 | return; 64 | } 65 | TextureAtlas ta = new TextureAtlas(CC.File(packName), CC.File(imgPath)); 66 | SpriteFrameCache.instance().addSpriteFrameWithTextureAtlas(packName, ta); 67 | } 68 | 69 | public static void UnloadAtlas(String packName) { 70 | SpriteFrameCache.instance().removeSpriteFramesFromTextureAtlas(packName); 71 | } 72 | 73 | 74 | //file 75 | public static FileHandle File(String fileName) { 76 | return FileUtils.getInstance().getFileHandle(fileName); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/com/cocos2dj/macros/CCLog.java: -------------------------------------------------------------------------------- 1 | package com.cocos2dj.macros; 2 | 3 | public class CCLog { 4 | // 5 | public static boolean CC_ENGINE_LOG_ENABLE = true; 6 | public static final void engine(String tag, String msg) { 7 | if (CC_ENGINE_LOG_ENABLE) { 8 | System.out.println("["+tag+"] " + msg); 9 | } 10 | } 11 | 12 | public static final void debug(Class clazz, String msg) { 13 | // simpleName.substring(simpleName.lastIndexOf(".")+1); 14 | debug(clazz.getSimpleName(), msg); 15 | } 16 | 17 | public static final void debug(String tag, String msg) { 18 | System.out.println("["+tag+"] " + msg); 19 | } 20 | 21 | public static final void error(String tag, String msg) { 22 | System.err.println("["+tag+"] " + msg); 23 | } 24 | } 25 | 26 | //CC.LOG(ddd) 27 | //CC.Sprite.create() 28 | //CC.ReadJson 29 | -------------------------------------------------------------------------------- /src/com/cocos2dj/macros/CCMacros.java: -------------------------------------------------------------------------------- 1 | package com.cocos2dj.macros; 2 | 3 | public class CCMacros { 4 | 5 | public static final float FLT_EPSILON = 1.192092896e-07F; 6 | 7 | 8 | public static final boolean CC_SPRITE_DEBUG_DRAW = false; 9 | 10 | public static final boolean USE_CC_TOUCH_LISTENER = true; //使用cocos风格的触摸事件监听 11 | } 12 | -------------------------------------------------------------------------------- /src/com/cocos2dj/module/Module.java: -------------------------------------------------------------------------------- 1 | package com.cocos2dj.module; 2 | 3 | import com.cocos2dj.protocol.IScene; 4 | 5 | /** 6 | * Module.java 7 | *

    8 | * 9 | * 模块修改:
    10 | * 模块准备结合 Scheduler 来使用
    11 | * 以scene为单位,直接关联scheduler驱动逻辑。例如:
    12 | * 13 | * 为场景添加box2d物理引擎 14 | *

    15 |  * //init
    16 |  * World world = new World();
    17 |  * Scheduler s = Director.getInstance().getScheduler();
    18 |  * s.mainSchedulePerFrame((t)->{
    19 |  * 	world.step(t, )...
    20 |  * }, scene, -2, false);
    21 |  * 
    22 |  * //destroy
    23 |  * world.destroy();
    24 |  * 
    25 | * 26 | * schedule的释放会通过 scheduler.unscheduleForTarget(currScene) 27 | * 实现。 28 | * 29 | * @author Copyright (c) 2017 xu jun 30 | */ 31 | public abstract class Module { 32 | /**模块名称 */ 33 | public final String moduleName; 34 | /**模块类型 */ 35 | public final String moduleType; 36 | 37 | protected boolean initFlag = false; 38 | 39 | protected IScene _currentScene; 40 | 41 | /**获取当前模块关联的scene */ 42 | public IScene getCurrentScene() {return _currentScene;} 43 | 44 | public Module(String moduleName, String moduleType) { 45 | this.moduleName = moduleName; 46 | this.moduleType = moduleType; 47 | } 48 | 49 | public void init() { 50 | 51 | } 52 | 53 | public void _onEnter(IScene scene, Object config) { 54 | this._currentScene = scene; 55 | if(!initFlag) { 56 | initFlag = true; 57 | onEnter(scene, config); 58 | } 59 | } 60 | 61 | public void _onExit(IScene scene) { 62 | if(initFlag) { 63 | initFlag = false; 64 | onExit(scene); 65 | } 66 | this._currentScene = null; 67 | } 68 | 69 | /**场景enter调用完毕后执行 */ 70 | public void onAfterEnter(IScene scene) {} 71 | 72 | public abstract void onEnter(IScene scene, Object config); 73 | 74 | public abstract void onExit(IScene scene); 75 | 76 | } 77 | 78 | -------------------------------------------------------------------------------- /src/com/cocos2dj/module/ModuleManager.java: -------------------------------------------------------------------------------- 1 | package com.cocos2dj.module; 2 | 3 | import com.badlogic.gdx.utils.Array; 4 | import com.cocos2dj.macros.CCLog; 5 | import com.cocos2dj.protocol.IScene; 6 | 7 | /** 8 | * ModuleManager.java 9 | *

    10 | * 11 | * 模块管理以scene为单位,sceneManager负责模块的初始化和销毁其余需要模块自己实现 12 | * 不提供remove方法,scene周期内,模块固定 13 | * 14 | * @author Copyright (c) 2015-2017 xu jun 15 | * */ 16 | public class ModuleManager { 17 | 18 | final IScene _scene; 19 | final Array modules = new Array(); 20 | boolean running = false; 21 | Object config; 22 | 23 | public ModuleManager(IScene scene) { 24 | _scene = scene; 25 | } 26 | 27 | public final void setRunning(boolean running) { 28 | this.running = running; 29 | } 30 | 31 | 32 | public Module findModule(String moduleName) { 33 | for(int i = 0; i < modules.size; ++i) { 34 | Module module = modules.get(i); 35 | if(module.moduleName.equals(moduleName)) { 36 | return module; 37 | } 38 | } 39 | return null; 40 | } 41 | 42 | @SuppressWarnings("unchecked") 43 | public T getModule(String moduleName) { 44 | for(int i = 0; i < modules.size; ++i) { 45 | Module module = modules.get(i); 46 | if(module.moduleName.equals(moduleName)) { 47 | return (T) module; 48 | } 49 | } 50 | return null; 51 | } 52 | 53 | /** 54 | *

     55 | 	 * Gdxui = scene.getModule<'Gdxui'>(Gdxui.class);
     56 | 	 * 
    57 | * @param clazz 58 | * @return 59 | */ 60 | @SuppressWarnings("unchecked") 61 | public T getModule(Class clazz) { 62 | for(int i = 0; i < modules.size; ++i) { 63 | Module module = modules.get(i); 64 | if(module.getClass() == clazz) { 65 | return (T) module; 66 | } 67 | } 68 | return null; 69 | } 70 | 71 | /**检测模块是否可以安装 不能重复添加*/ 72 | private boolean checkModule(Module module) { 73 | for(int i = 0; i < modules.size; ++i) { 74 | Module temp = modules.get(i); 75 | if(module.moduleType.equals(temp.moduleType)) { 76 | //同样类型模块只能添加一个 77 | CCLog.engine("ModuleManager", "module has same type : " + temp.moduleType); 78 | return false; 79 | } 80 | } 81 | 82 | 83 | if(modules.contains(module, true)) { 84 | CCLog.engine("ModuleManager", "module already exists"); 85 | return false; 86 | } 87 | return true; 88 | } 89 | 90 | public final void addModule(Module module, Object config) { 91 | if(!checkModule(module)) {return;} 92 | this.config = config; 93 | modules.add(module); 94 | if(running) { 95 | module._onEnter(_scene, this.config); 96 | } 97 | } 98 | 99 | public final void onSceneEnter() { 100 | running = true; 101 | for(int i = 0; i < modules.size; ++i) { 102 | modules.get(i)._onEnter(_scene, config); 103 | } 104 | } 105 | 106 | public final void onSceneEnterAfter() { 107 | for(int i = 0; i < modules.size; ++i) { 108 | modules.get(i).onAfterEnter(_scene); 109 | } 110 | } 111 | 112 | public final void onSceneExit() { 113 | running = false; 114 | for(int i = 0; i < modules.size; ++i) { 115 | modules.get(i)._onExit(_scene); 116 | } 117 | modules.clear(); 118 | } 119 | } 120 | -------------------------------------------------------------------------------- /src/com/cocos2dj/module/base2d/framework/IPhysicsObject.java: -------------------------------------------------------------------------------- 1 | package com.cocos2dj.module.base2d.framework; 2 | 3 | import com.badlogic.gdx.math.Vector2; 4 | import com.cocos2dj.module.base2d.framework.collision.ContactCollisionData; 5 | import com.cocos2dj.module.base2d.framework.common.TimeInfo; 6 | 7 | /** 8 | * 物理对象接口

    9 | * 10 | * 不要使用任何get方法进行修改 11 | * 12 | * @author xujun 13 | * Copyright (c) 2015. All rights reserved. 14 | */ 15 | public interface IPhysicsObject { 16 | 17 | static final Vector2 ZERO = new Vector2(); 18 | 19 | /**设置physicsObject的位置
    20 | * 同时会更新prevPositon数据 21 | * 在实现此方法时需注意 22 | * @param x 23 | * @param y */ 24 | public void setPosition(final float x, final float y); 25 | 26 | /** 获取对象位置(只读不要修改 修改要用set方法) 27 | * @return*/ 28 | public Vector2 getPosition(); 29 | 30 | /**获取对象前一个位置(只读不要修改 修改要用set方法) 31 | * @return*/ 32 | public Vector2 getPrevPosition(); 33 | 34 | /**获取速度衰减率*/ 35 | public float getDamping(); 36 | 37 | public void setCollisionLevel(int level); 38 | 39 | /**获取碰撞等级*/ 40 | public int getCollisionLevel(); 41 | 42 | /** 43 | * 移动物理对象并且将移动向量记录在argVector2中(经过time处理后的向量)

    44 | * 返回的值是Z轴上的分量 45 | * 46 | * @param time 47 | * @param argVector2 48 | * @return zClip 49 | */ 50 | public float move(final TimeInfo time,final Vector2 argVector2, PhysicsObject obj); 51 | 52 | /**修正物理对象的位置 */ 53 | public void modifierPosition(); 54 | 55 | // public void 56 | /**按照MTD修正物理对象位置(xy平面) 57 | * {@link #modifierPositionXZ(Vector2)} 58 | * @param MTD 59 | * @param data 碰撞信息 */ 60 | public void modifierPosition(Vector2 MTD, ContactCollisionData data); 61 | 62 | /**更新速度 63 | * @param time */ 64 | public void updateVelocity(final TimeInfo time); 65 | 66 | /**设置碰撞数据 */ 67 | // public void setContactData(); 68 | 69 | /**根据给定的向量设置速度(复制数据) 70 | * @param velocity */ 71 | public void setVelocity(final Vector2 velocity); 72 | 73 | public void setVelocityX(final float x); 74 | 75 | public void setVelocityY(final float y); 76 | 77 | public void setVelocity(float x,float y); 78 | 79 | /**根据给定的向量设置速度(复制数据) 80 | * @param velocity */ 81 | public void setAccelerate(final Vector2 velocity); 82 | 83 | public void setAccelerateX(final float x); 84 | 85 | public void setAccelerateY(final float y); 86 | 87 | public void setAccelerate(float x,float y); 88 | 89 | /**@return velocity 速度向量引用*/ 90 | public Vector2 getVelocity(); 91 | 92 | /**@return accelerate 加速度向量引用*/ 93 | public Vector2 getAccelerate(); 94 | 95 | /**设置速度衰减 96 | * @param damping */ 97 | public void setVelocityDamping(float damping); 98 | 99 | /**获取速度衰减 100 | * @return */ 101 | public float getVelocityDamping(); 102 | 103 | /**初始化advance的数据
    用于contact的handle方法中 104 | * 将position重新设置为prevPosition*/ 105 | public void initAdvance(); 106 | } -------------------------------------------------------------------------------- /src/com/cocos2dj/module/base2d/framework/PhysicsConfig.java: -------------------------------------------------------------------------------- 1 | package com.cocos2dj.module.base2d.framework; 2 | 3 | /**物理相关配置 */ 4 | public final class PhysicsConfig { 5 | 6 | /**模拟时间间隔单位为ms 建议选择32ms(对应1/30)或16ms(对应1/60)*/ 7 | public float dt = 32f; 8 | 9 | /**碰撞迭代求解次数*/ 10 | public int iteration = 2; 11 | 12 | public float LimitX = 1000; 13 | 14 | public float LimitY = 1000; 15 | 16 | } 17 | -------------------------------------------------------------------------------- /src/com/cocos2dj/module/base2d/framework/PhysicsGenerator.java: -------------------------------------------------------------------------------- 1 | package com.cocos2dj.module.base2d.framework; 2 | 3 | import com.badlogic.gdx.math.Vector2; 4 | import com.cocos2dj.module.base2d.framework.common.TimeInfo; 5 | 6 | /** 7 | * PhysicsGenerator.java 8 | *

    9 | * 10 | * @author copyright(c) 2017 xujun 11 | */ 12 | public abstract class PhysicsGenerator { 13 | 14 | /** 15 | * generator 帧更新 16 | * @param time 17 | * @param target 18 | * @return 19 | */ 20 | public abstract boolean onUpdate(PhysicsObject target, TimeInfo time); 21 | 22 | /** 23 | * 用于修正速度 24 | * @param targetVelocity 25 | */ 26 | public abstract void onUpdateVelocity(PhysicsObject target, TimeInfo time, Vector2 targetVelocity); 27 | 28 | /** 29 | * 修正位移偏移向量 30 | * @param positionDelta 31 | */ 32 | public abstract void onUpdatePosition(PhysicsObject target, TimeInfo time, Vector2 positionDelta); 33 | 34 | 35 | protected boolean endFlag; 36 | public void stop() { 37 | endFlag = true; 38 | } 39 | public boolean isStop() { return endFlag;} 40 | 41 | 42 | 43 | public static final PhysicsGenerator TEST = new PhysicsGenerator() { 44 | 45 | @Override 46 | public boolean onUpdate(PhysicsObject target, TimeInfo time) { 47 | System.out.println("TestGenerator: onUpdate "); 48 | return false; 49 | } 50 | 51 | @Override 52 | public void onUpdateVelocity(PhysicsObject target, TimeInfo time, Vector2 targetVelocity) { 53 | System.out.println("TestGenerator: onUpdate Velocity"); 54 | } 55 | 56 | @Override 57 | public void onUpdatePosition(PhysicsObject target, TimeInfo time, Vector2 positionDelta) { 58 | System.out.println("TestGenerator: onUpdate Position"); 59 | } 60 | 61 | }; 62 | } 63 | -------------------------------------------------------------------------------- /src/com/cocos2dj/module/base2d/framework/PhysicsObjectType.java: -------------------------------------------------------------------------------- 1 | package com.cocos2dj.module.base2d.framework; 2 | 3 | /** 4 | * @author xu jun 5 | * Copyright (c) 2015. All rights reserved. 6 | */ 7 | public enum PhysicsObjectType { 8 | Static, 9 | Dynamic, 10 | Move, 11 | Detect, 12 | 13 | // Static3D, 14 | // Dynamic3D, 15 | // Move3D, 16 | // Detect3D 17 | } 18 | -------------------------------------------------------------------------------- /src/com/cocos2dj/module/base2d/framework/callback/ContactListener.java: -------------------------------------------------------------------------------- 1 | package com.cocos2dj.module.base2d.framework.callback; 2 | 3 | import com.badlogic.gdx.math.Vector2; 4 | import com.cocos2dj.module.base2d.framework.PhysicsObject; 5 | import com.cocos2dj.module.base2d.framework.collision.ContactCollisionData; 6 | 7 | /** 8 | * ContactListener.java 9 | *

    10 | * @author Copyright(c) 2015 xu jun 11 | */ 12 | public interface ContactListener { 13 | 14 | /** 15 | * 碰撞处理开始时调用 返回true取消本次碰撞 16 | * @param o1 17 | * @param o2 18 | * @return false 继续碰撞 true 取消碰撞 */ 19 | public boolean cancelContact(PhysicsObject o1, PhysicsObject o2); 20 | 21 | /**碰撞开始时调用 22 | * @param o1 23 | * @param o2 24 | * @param MTD 修正向量 */ 25 | public void contactCreated(PhysicsObject o1, PhysicsObject o2, Vector2 MTD, ContactCollisionData data); 26 | 27 | /**碰撞持续时调用 28 | * @param o1 29 | * @param o2 30 | * @param MTD 修正向量 */ 31 | public void contactPersisted(PhysicsObject o1, PhysicsObject o2, Vector2 MTD, ContactCollisionData data); 32 | 33 | /**碰撞结束调用 34 | * @param o1 35 | * @param o2 36 | * @param MTD 修正向量 */ 37 | public void contactDestroyed(PhysicsObject o1, PhysicsObject o2, Vector2 MTD, ContactCollisionData data); 38 | } 39 | -------------------------------------------------------------------------------- /src/com/cocos2dj/module/base2d/framework/callback/DefaultContactListener.java: -------------------------------------------------------------------------------- 1 | package com.cocos2dj.module.base2d.framework.callback; 2 | 3 | import com.badlogic.gdx.math.Vector2; 4 | import com.cocos2dj.module.base2d.framework.PhysicsObject; 5 | import com.cocos2dj.module.base2d.framework.collision.ContactCollisionData; 6 | 7 | public class DefaultContactListener implements ContactListener { 8 | 9 | @Override 10 | public boolean cancelContact(PhysicsObject o1, PhysicsObject o2) { 11 | return o1.cancelContact(o2) || o2.cancelContact(o1); 12 | } 13 | 14 | @Override 15 | public void contactCreated(PhysicsObject o1, PhysicsObject o2, Vector2 MTD, ContactCollisionData data) { 16 | o1.contactCreated(o2, MTD, data); 17 | o2.contactCreated(o1, MTD, data); 18 | } 19 | 20 | @Override 21 | public void contactPersisted(PhysicsObject o1, PhysicsObject o2, Vector2 MTD, ContactCollisionData data) { 22 | o1.contactPersisted(o2, MTD, data); 23 | o2.contactPersisted(o1, MTD, data); 24 | } 25 | 26 | @Override 27 | public void contactDestroyed(PhysicsObject o1, PhysicsObject o2, Vector2 MTD, ContactCollisionData data) { 28 | o1.contactDestroyed(o2, MTD, data); 29 | o2.contactDestroyed(o1, MTD, data); 30 | } 31 | 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/com/cocos2dj/module/base2d/framework/callback/MyTreeCallback.java: -------------------------------------------------------------------------------- 1 | package com.cocos2dj.module.base2d.framework.callback; 2 | 3 | import com.cocos2dj.module.base2d.framework.PhysicsObject; 4 | import com.cocos2dj.module.base2d.jbox2d.BroadPhase; 5 | import com.cocos2dj.module.base2d.jbox2d.TreeCallback; 6 | 7 | /** 8 | * 查询回调函数(返回查询的物理对象个数以及引用) 9 | * @author xu jun 10 | * Copyright (c) 2015. All rights reserved. 11 | */ 12 | public class MyTreeCallback implements TreeCallback { 13 | private BroadPhase broadPhase; 14 | private PhysicsObject[] results; 15 | private int queryCount; 16 | 17 | /**@return 最终查询到的物理对象个数*/ 18 | public final int getQueryCount(){ 19 | return queryCount; 20 | } 21 | 22 | public final void init(PhysicsObject[] results, BroadPhase broadPhase){ 23 | queryCount = 0; 24 | this.results = results; 25 | this.broadPhase = broadPhase; 26 | } 27 | 28 | @Override 29 | public boolean treeCallback(int proxyId) { 30 | PhysicsObject temp = (PhysicsObject) broadPhase.getUserData(proxyId); 31 | if(!temp.sleep && !temp.checkRemoveFlag()){ 32 | results[queryCount++] = temp; 33 | } 34 | init(null, null); 35 | return queryCount < results.length; 36 | } 37 | 38 | } -------------------------------------------------------------------------------- /src/com/cocos2dj/module/base2d/framework/callback/MyTreeRayCastCallback.java: -------------------------------------------------------------------------------- 1 | package com.cocos2dj.module.base2d.framework.callback; 2 | 3 | import com.cocos2dj.module.base2d.framework.PhysicsObject; 4 | import com.cocos2dj.module.base2d.jbox2d.BroadPhase; 5 | import com.cocos2dj.module.base2d.jbox2d.RayCastInput; 6 | import com.cocos2dj.module.base2d.jbox2d.TreeRayCastCallback; 7 | public class MyTreeRayCastCallback implements TreeRayCastCallback { 8 | private BroadPhase broadPhase; 9 | private PhysicsObject[] results; 10 | private int queryCount; 11 | 12 | /**@return 最终查询到的物理对象个数*/ 13 | public int getQueryCount(){ 14 | return queryCount; 15 | } 16 | 17 | public final void initRayCast(PhysicsObject[] results, BroadPhase broadPhase){ 18 | // public void setResults(PhysicsObject[] results){ 19 | queryCount = 0; 20 | this.results = results; 21 | this.broadPhase = broadPhase; 22 | } 23 | 24 | @Override 25 | public float raycastCallback(RayCastInput input, int nodeId) { 26 | //返回0则停止测试 27 | //返回小于0的数继续测试 28 | //返回大于0的数更改范围继续测试 29 | PhysicsObject temp = (PhysicsObject) broadPhase.getUserData(nodeId); 30 | if(!temp.sleep && !temp.checkRemoveFlag()){ 31 | results[queryCount++] = temp; 32 | } 33 | 34 | if(queryCount < results.length) { 35 | return -1; 36 | } 37 | else { 38 | initRayCast(null, null); 39 | return 0; 40 | } 41 | } 42 | 43 | // @Override 44 | // public float raycastCallback(RayCastInput input, int nodeId) { 45 | // // TODO Auto-generated method stub 46 | // return 0; 47 | // } 48 | 49 | } -------------------------------------------------------------------------------- /src/com/cocos2dj/module/base2d/framework/callback/OnContactCallback.java: -------------------------------------------------------------------------------- 1 | package com.cocos2dj.module.base2d.framework.callback; 2 | 3 | import com.cocos2dj.module.base2d.framework.PhysicsObject; 4 | import com.cocos2dj.module.base2d.framework.collision.Contact; 5 | 6 | public interface OnContactCallback { 7 | 8 | public boolean onContact(Contact c, PhysicsObject other); 9 | 10 | } 11 | -------------------------------------------------------------------------------- /src/com/cocos2dj/module/base2d/framework/callback/UpdateListener.java: -------------------------------------------------------------------------------- 1 | package com.cocos2dj.module.base2d.framework.callback; 2 | 3 | import com.cocos2dj.module.base2d.framework.PhysicsObject; 4 | 5 | /**UpdateListener
    6 | * 当更新位置时调用以发送位置信息 7 | * 8 | * @author xu jun 9 | * Copyright (c) 2012-2014. All rights reserved. */ 10 | public interface UpdateListener { 11 | 12 | /**当C2PhysObject更新完位置后调用
    13 | * 14 | * 这个方法在C2PhysicsObject的sweep方法以及contact的handle方法中调用 15 | * 由于可能重复调用, 所以不要再这个接口执行过多的操作 16 | * 17 | * @param o 更新的对象 */ 18 | public void onUpdatePosition(final PhysicsObject o); 19 | } 20 | -------------------------------------------------------------------------------- /src/com/cocos2dj/module/base2d/framework/callback/VelocityLimitListener.java: -------------------------------------------------------------------------------- 1 | package com.cocos2dj.module.base2d.framework.callback; 2 | 3 | import com.badlogic.gdx.math.Vector2; 4 | 5 | /** 6 | * VelocityLimitListener.java 7 | * <>p 8 | * 用于限制最大速度 9 | * 10 | * @author xu jun 11 | */ 12 | public interface VelocityLimitListener { 13 | 14 | public void onVelocity(Vector2 velocity); 15 | 16 | public static final VelocityLimitListener NULL = new VelocityLimitListener() { 17 | @Override 18 | public void onVelocity(Vector2 velocity) {} 19 | }; 20 | 21 | } 22 | -------------------------------------------------------------------------------- /src/com/cocos2dj/module/base2d/framework/collision/ContactAttach.java: -------------------------------------------------------------------------------- 1 | package com.cocos2dj.module.base2d.framework.collision; 2 | 3 | import com.cocos2dj.module.base2d.framework.PhysicsObject; 4 | 5 | /**ContactAttach

    6 | * 接触连接 */ 7 | public class ContactAttach { 8 | 9 | /**关联的接触*/ 10 | public Contact contact; 11 | 12 | /**获取contact的另一个接触物体

    13 | * 从C2PhysicsObject访问该对象时 other表示与其接触的另一个C2PhysicsObject对象 */ 14 | public PhysicsObject other; 15 | 16 | /**链表访问 previous*/ 17 | public ContactAttach prev; 18 | 19 | /**链表访问 next*/ 20 | public ContactAttach next; 21 | 22 | /**@return true 对应contact有效 */ 23 | public final boolean isContact() { 24 | return contact.isContacting() || contact.isContacted(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/com/cocos2dj/module/base2d/framework/collision/ContactCollisionData.java: -------------------------------------------------------------------------------- 1 | package com.cocos2dj.module.base2d.framework.collision; 2 | 3 | /** 4 | * 碰撞数据

    5 | * 6 | * @author Copyright (c) 2015-2017. xujun 7 | */ 8 | public class ContactCollisionData { 9 | // public V2 point; 10 | // public float depth; 11 | // public boolean isXZ = false; 12 | 13 | public Shape shape1; 14 | 15 | public Shape shape2; 16 | /**动摩擦系数(衰减计算) */ 17 | public float retFriction = 0f; 18 | /**静摩擦系数(修正计算) */ 19 | public float retStaticFriction = 0f; 20 | 21 | public void clear() { 22 | shape1 = null; 23 | shape2 = null; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/com/cocos2dj/module/base2d/framework/collision/ContactList.java: -------------------------------------------------------------------------------- 1 | package com.cocos2dj.module.base2d.framework.collision; 2 | /**接触链表

    3 | * 4 | * 该链表的 {@link #addContact(Contact)} 以及 {@link #removeContact(Contact)} 5 | * 方法会判断是否重复添加contact 因为这个数据结构十分惧怕重复添加contact破坏遍历

    6 | * 7 | * 不过不会判断是否重复删除contact

    8 | * 9 | * @author xu jun 10 | * Copyright (c) 2015. All rights reserved. */ 11 | public class ContactList { 12 | Contact first = null; 13 | Contact last = null; 14 | int size; 15 | 16 | /**向链表末端添加contact对象 */ 17 | public final void addContact(final Contact c) { 18 | //判断contact是否重复添加 19 | if(c.list_prev != null || c.list_next != null) {return;} 20 | 21 | c.list_prev = last; 22 | 23 | if(last == null) { 24 | first = c; 25 | } 26 | else { 27 | last.list_next = c; 28 | } 29 | 30 | last = c; 31 | ++size; 32 | } 33 | 34 | /**从链表中移除该contact对象 */ 35 | public final void removeContact(final Contact c) { 36 | final Contact next = c.list_next; 37 | final Contact prev = c.list_prev; 38 | 39 | if (prev == null) { 40 | first = next; 41 | } else { 42 | prev.list_next = next; 43 | c.list_prev = null; 44 | } 45 | 46 | if (next == null) { 47 | last = prev; 48 | } else { 49 | next.list_prev = prev; 50 | c.list_next = null; 51 | } 52 | 53 | --size; 54 | } 55 | 56 | /**清空链表中的contact对象 */ 57 | public final void clear() { 58 | for(Contact curr = first; curr != null; ) { 59 | Contact next = curr.list_next; 60 | curr.list_next = null; 61 | curr.list_prev = null; 62 | curr = next; 63 | } 64 | first = last = null; 65 | size = 0; 66 | } 67 | 68 | public final int size() { 69 | return size; 70 | } 71 | 72 | public final Contact first() { 73 | return first; 74 | } 75 | 76 | 77 | public String toSimpleString() { 78 | return "size = " + size + "\n"; 79 | } 80 | 81 | public String toString() { 82 | StringBuilder sb = new StringBuilder(); 83 | sb.append("size = ").append(size).append('\n'); 84 | 85 | Contact temp = first; 86 | for(int i = 0; i < size; ++i) { 87 | sb.append("["+i+"] ").append(temp).append('\n'); 88 | temp = temp.list_next; 89 | } 90 | return sb.toString(); 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /src/com/cocos2dj/module/base2d/framework/collision/ContactPool.java: -------------------------------------------------------------------------------- 1 | package com.cocos2dj.module.base2d.framework.collision; 2 | 3 | import com.cocos2dj.module.base2d.jbox2d.pooling.MutableStack; 4 | 5 | /**ContactPool

    6 | * 接触缓存池 7 | * 初始值为16个之后每当获取contact数量超过缓存数之后 池容量增长1倍
    8 | * get()方法用于获取缓存contact
    9 | * cycle(Contact contact)方法用于将contact送回缓存中 */ 10 | public class ContactPool { 11 | 12 | private static final int INIT_CAPACITY = 16; 13 | private static ContactPool cp; 14 | 15 | public static final ContactPool getContactPool(){ 16 | if(cp == null){ 17 | cp = new ContactPool(); 18 | } 19 | return cp; 20 | } 21 | 22 | private MutableStack pool; 23 | 24 | /**重新分配内存 */ 25 | public final void reset() { 26 | pool.reset(INIT_CAPACITY); 27 | } 28 | 29 | public ContactPool() { 30 | pool = new MutableStack(Contact.class, INIT_CAPACITY); 31 | } 32 | 33 | /**从池中获取一个contact对象 34 | * @return contact */ 35 | public final Contact get() { 36 | return pool.pop(); 37 | } 38 | 39 | public final void cycle(final Contact contact){ 40 | contact.clearAdvanceFlag(); 41 | contact.setContacted(false); 42 | pool.push(contact); 43 | } 44 | 45 | 46 | public String toString() { 47 | return pool.toString(); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/com/cocos2dj/module/base2d/framework/collision/FloatPair.java: -------------------------------------------------------------------------------- 1 | package com.cocos2dj.module.base2d.framework.collision; 2 | /** 3 | * 2015 4 | * 改为了单例模式以充分利用该资源 5 | */ 6 | public final class FloatPair { 7 | 8 | private static FloatPair pair = new FloatPair(); 9 | public float min; 10 | public float max; 11 | 12 | // private FloatPair(final float min, final float max){ 13 | // this.min = min; 14 | // this.max = max; 15 | // } 16 | 17 | public final void setValue(final float min,final float max){ 18 | this.min = min; 19 | this.max =max; 20 | } 21 | 22 | /** 23 | * 销毁floatPair 24 | */ 25 | public static final void release() { 26 | pair = null; 27 | } 28 | 29 | /** 30 | * 获取内含有min与max两个float的floatPair 31 | * @param min 32 | * @param max 33 | */ 34 | static final FloatPair getFloatPair(final float min,final float max){ 35 | // if(pair == null){ 36 | // pair = new FloatPair(min, max); 37 | // }else { 38 | pair.setValue(min, max); 39 | // } 40 | return pair; 41 | } 42 | } -------------------------------------------------------------------------------- /src/com/cocos2dj/module/base2d/framework/common/TimeInfo.java: -------------------------------------------------------------------------------- 1 | package com.cocos2dj.module.base2d.framework.common; 2 | 3 | /** 4 | * 仿真所需的时间信息 5 | */ 6 | public class TimeInfo { 7 | 8 | /**模拟时间间隔单位为ms 建议选择32ms(对应1/30)或16ms(对应1/60)*/ 9 | public float dt = 32f; 10 | 11 | /**引擎输入的模拟时长 */ 12 | public float realDt; 13 | 14 | /**时间执行比率(实际时间/模拟时间间隔)*/ 15 | public float ratio = 1; 16 | 17 | /**迭代次数*/ 18 | public int iteration = 2; 19 | 20 | /**迭代次数的倒数*/ 21 | public float inv_iteration = 1f / iteration; 22 | 23 | 24 | /**设置迭代次数 25 | * 用这个方法会更新inv_iteration*/ 26 | public void setIteration(final int iteration){ 27 | this.iteration = iteration; 28 | this.inv_iteration = 1f / this.iteration; 29 | } 30 | 31 | /**更新时间信息的ratio信息 32 | * @param timeDelay 距离上一次执行的时间间隔(ms)*/ 33 | public final void update(final float timeDelay){ 34 | realDt = timeDelay; 35 | ratio = timeDelay/dt; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/com/cocos2dj/module/base2d/framework/pipeline/BroadPhaseSolver.java: -------------------------------------------------------------------------------- 1 | package com.cocos2dj.module.base2d.framework.pipeline; 2 | 3 | import com.cocos2dj.module.base2d.framework.PhysicsObject; 4 | import com.cocos2dj.module.base2d.framework.PhysicsScene; 5 | import com.cocos2dj.module.base2d.framework.common.TempArray; 6 | import com.cocos2dj.module.base2d.jbox2d.BroadPhase; 7 | 8 | /**粗检测管线

    9 | * 10 | * @author xujun 11 | * Copyright (c) 2015. All rights reserved. */ 12 | public class BroadPhaseSolver { 13 | 14 | public final void solve(final PhysicsScene scene) { 15 | final BroadPhase broadPhase = scene._getBroadPhase(); 16 | //detect 物体不维护broadPhase,直接查询 17 | final TempArray detectObjects = scene._getDetectObjects(); 18 | for(int i = 0, n = detectObjects.size(); i < n; ++i) { 19 | final PhysicsObject temp = detectObjects.get(i); 20 | scene._setCurrectDetectObject(temp); 21 | // System.out.println(temp.sweepAABB); 22 | broadPhase.query(scene, temp.getSweepAABB()); 23 | } 24 | 25 | //dynamicTree 26 | broadPhase.updatePairs(scene); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/com/cocos2dj/module/base2d/framework/pipeline/ContactSolver.java: -------------------------------------------------------------------------------- 1 | package com.cocos2dj.module.base2d.framework.pipeline; 2 | 3 | import com.cocos2dj.module.base2d.framework.PhysicsScene; 4 | import com.cocos2dj.module.base2d.framework.callback.ContactListener; 5 | import com.cocos2dj.module.base2d.framework.collision.Contact; 6 | import com.cocos2dj.module.base2d.framework.common.AABB; 7 | import com.cocos2dj.module.base2d.framework.common.TimeInfo; 8 | import com.cocos2dj.module.base2d.jbox2d.BroadPhase; 9 | 10 | /**接触处理

    11 | * 12 | * @author xujun 13 | * Copyright (c) 2015. All rights reserved. */ 14 | public class ContactSolver { 15 | 16 | /** 17 | * 从缓存的角度来讲这样并不好,但是实际上该物理引擎处理对象的性能问题 18 | * 主要出现在broadPhase的算法上而不是contact的计算因此这里不做优化了 19 | * @param listener 20 | * @param time 21 | * @param scene 22 | */ 23 | public final void solve(final ContactListener listener, final TimeInfo time, final PhysicsScene scene) { 24 | /*处理碰撞 需进行迭代*/ 25 | final BroadPhase broadPhase = scene._getBroadPhase(); 26 | Contact contact = scene._getContacts(); 27 | // System.out.println("start contact"); 28 | //验证contact是否需要(移动后可能该contact已经不存在) 29 | //并且如果contact被设为需要删除则会执行删除方法 30 | while(contact != null) { 31 | 32 | boolean overlap; 33 | if(contact.isAABBTest()) { 34 | overlap = AABB.testOverlap(contact.getPhysicsObject1().sweepAABB, 35 | contact.getPhysicsObject2().sweepAABB); 36 | } 37 | else { 38 | overlap = broadPhase.testOverlap(contact.getPhysicsObject1().getProxy(), 39 | contact.getPhysicsObject2().getProxy()); 40 | } 41 | 42 | // if(contact.isAABBTest()) { 43 | // if(!AABB.testOverlap(contact.getPhysicsObject1().sweepAABB, 44 | // contact.getPhysicsObject2().sweepAABB) 45 | // ||contact.isWillRemove() 46 | // ||contact.getPhysicsObject1().isSleep() 47 | // ||contact.getPhysicsObject2().isSleep()) { 48 | // 49 | // //需要删除该contact 50 | // Contact next = contact.list_next; 51 | // scene._destroyContact(contact); 52 | // contact = next; 53 | // } 54 | // else { 55 | // contact.o1.initAdvance(); 56 | // contact.o2.initAdvance(); 57 | // 58 | // contact = contact.list_next; 59 | // } 60 | // } 61 | if(!overlap 62 | ||contact.isWillRemove() 63 | ||contact.getPhysicsObject1().isSleep() 64 | ||contact.getPhysicsObject2().isSleep()) { 65 | 66 | //需要删除该contact 67 | Contact next = contact.list_next; 68 | scene._destroyContact(contact); 69 | contact = next; 70 | } 71 | else { 72 | contact.o1.initAdvance(); 73 | contact.o2.initAdvance(); 74 | 75 | contact = contact.list_next; 76 | } 77 | } 78 | 79 | //迭代指定的次数检测碰撞可以在一定程度上防止隧道效应 80 | for(int i = 1; i <= time.iteration; ++i) { 81 | contact = scene._getContacts(); 82 | //处理contact 可能删除 83 | final boolean last = (i == time.iteration); 84 | 85 | while(contact != null) { 86 | contact.handle(last, time, listener); 87 | contact = contact.list_next; 88 | } 89 | 90 | contact = scene._getContacts(); 91 | while(contact != null) { 92 | contact.clearAdvanceFlag(); 93 | contact = contact.list_next; 94 | } 95 | } 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /src/com/cocos2dj/module/base2d/framework/pipeline/PosSolver.java: -------------------------------------------------------------------------------- 1 | package com.cocos2dj.module.base2d.framework.pipeline; 2 | 3 | import com.badlogic.gdx.math.Vector2; 4 | import com.cocos2dj.module.base2d.framework.PhysicsObject; 5 | import com.cocos2dj.module.base2d.framework.PhysicsScene; 6 | import com.cocos2dj.module.base2d.framework.common.TempArray; 7 | import com.cocos2dj.module.base2d.framework.common.TimeInfo; 8 | import com.cocos2dj.module.base2d.jbox2d.BroadPhase; 9 | 10 | /**位置处理管线

    11 | * 12 | * @author xujun 13 | * Copyright (c) 2015. All rights reserved. */ 14 | public class PosSolver { 15 | 16 | public final void solve(final TimeInfo time, final PhysicsScene scene) { 17 | final TempArray dynamicList = scene._getMoveObjects(); 18 | final int n = dynamicList.size(); 19 | final BroadPhase broadPhase = scene._getBroadPhase(); 20 | 21 | for(int i = 0; i < n; ++i) { 22 | final PhysicsObject temp = dynamicList.get(i); 23 | 24 | if(temp.isSleep()) { 25 | continue; 26 | } 27 | 28 | //更新速度 29 | temp.updateObject(); 30 | temp.updateVelocity(time); 31 | 32 | 33 | switch(temp.getPhysicsObjectType()) { 34 | case Detect: { 35 | temp.sweep(time); 36 | } 37 | break; 38 | case Dynamic: { 39 | final Vector2 distance = temp.sweep(time); 40 | broadPhase.moveProxy(temp.getProxy(), temp.getSweepAABB(), distance); 41 | } 42 | break; 43 | case Move: { 44 | temp.move(time); 45 | temp.listener.onUpdatePosition(temp); 46 | } 47 | break; 48 | case Static: 49 | break; 50 | } 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/com/cocos2dj/module/base2d/jbox2d/BroadPhase.java: -------------------------------------------------------------------------------- 1 | package com.cocos2dj.module.base2d.jbox2d; 2 | 3 | import com.badlogic.gdx.math.Vector2; 4 | import com.cocos2dj.module.base2d.framework.common.AABB; 5 | 6 | 7 | public interface BroadPhase { 8 | 9 | public static final int NULL_PROXY = -1; 10 | 11 | /** 12 | * reset BroadPhase state 13 | */ 14 | void reset(); 15 | 16 | /** 17 | * Create a proxy with an initial AABB. Pairs are not reported until updatePairs is called. 18 | * 19 | * @param aabb 20 | * @param userData 21 | * @return 22 | */ 23 | int createProxy(AABB aabb, Object userData); 24 | 25 | /** 26 | * Destroy a proxy. It is up to the client to remove any pairs. 27 | * 28 | * @param proxyId 29 | */ 30 | void destroyProxy(int proxyId); 31 | 32 | /** 33 | * Call MoveProxy as many times as you like, then when you are done call UpdatePairs to finalized 34 | * the proxy pairs (for your time step). 35 | */ 36 | void moveProxy(int proxyId, AABB aabb, Vector2 displacement); 37 | 38 | void touchProxy(int proxyId); 39 | 40 | Object getUserData(int proxyId); 41 | 42 | AABB getFatAABB(int proxyId); 43 | 44 | boolean testOverlap(int proxyIdA, int proxyIdB); 45 | 46 | /** 47 | * Get the number of proxies. 48 | * 49 | * @return 50 | */ 51 | int getProxyCount(); 52 | 53 | // void drawTree(DebugDraw argDraw); 54 | 55 | /** 56 | * Update the pairs. This results in pair callbacks. This can only add pairs. 57 | * 58 | * @param callback 59 | */ 60 | void updatePairs(PairCallback callback); 61 | 62 | /** 63 | * Query an AABB for overlapping proxies. The callback class is called for each proxy that 64 | * overlaps the supplied AABB. 65 | * 66 | * @param callback 67 | * @param aabb 68 | */ 69 | void query(TreeCallback callback, AABB aabb); 70 | 71 | /** 72 | * Ray-cast against the proxies in the tree. This relies on the callback to perform a exact 73 | * ray-cast in the case were the proxy contains a shape. The callback also performs the any 74 | * collision filtering. This has performance roughly equal to k * log(n), where k is the number of 75 | * collisions and n is the number of proxies in the tree. 76 | * 77 | * @param input the ray-cast input data. The ray extends from p1 to p1 + maxFraction * (p2 - p1). 78 | * @param callback a callback class that is called for each proxy that is hit by the ray. 79 | */ 80 | void raycast(TreeRayCastCallback callback, RayCastInput input); 81 | 82 | /** 83 | * Get the height of the embedded tree. 84 | * 85 | * @return 86 | */ 87 | int getTreeHeight(); 88 | 89 | int getTreeBalance(); 90 | 91 | float getTreeQuality(); 92 | } 93 | -------------------------------------------------------------------------------- /src/com/cocos2dj/module/base2d/jbox2d/BroadPhaseStrategy.java: -------------------------------------------------------------------------------- 1 | package com.cocos2dj.module.base2d.jbox2d; 2 | 3 | import com.badlogic.gdx.math.Vector2; 4 | import com.cocos2dj.module.base2d.framework.common.AABB; 5 | 6 | public interface BroadPhaseStrategy { 7 | 8 | void reset(); 9 | 10 | /** 11 | * Create a proxy. Provide a tight fitting AABB and a userData pointer. 12 | * 13 | * @param aabb 14 | * @param userData 15 | * @return 16 | */ 17 | int createProxy(AABB aabb, Object userData); 18 | 19 | /** 20 | * Destroy a proxy 21 | * 22 | * @param proxyId 23 | */ 24 | void destroyProxy(int proxyId); 25 | 26 | /** 27 | * Move a proxy with a swepted AABB. If the proxy has moved outside of its fattened AABB, then the 28 | * proxy is removed from the tree and re-inserted. Otherwise the function returns immediately. 29 | * 30 | * @return true if the proxy was re-inserted. 31 | */ 32 | boolean moveProxy(int proxyId, AABB aabb, Vector2 displacement); 33 | 34 | Object getUserData(int proxyId); 35 | 36 | AABB getFatAABB(int proxyId); 37 | 38 | /** 39 | * Query an AABB for overlapping proxies. The callback class is called for each proxy that 40 | * overlaps the supplied AABB. 41 | * 42 | * @param callback 43 | * @param araabbgAABB 44 | */ 45 | void query(TreeCallback callback, AABB aabb); 46 | 47 | /** 48 | * Ray-cast against the proxies in the tree. This relies on the callback to perform a exact 49 | * ray-cast in the case were the proxy contains a shape. The callback also performs the any 50 | * collision filtering. This has performance roughly equal to k * log(n), where k is the number of 51 | * collisions and n is the number of proxies in the tree. 52 | * 53 | * @param input the ray-cast input data. The ray extends from p1 to p1 + maxFraction * (p2 - p1). 54 | * @param callback a callback class that is called for each proxy that is hit by the ray. 55 | */ 56 | void raycast(TreeRayCastCallback callback, RayCastInput input); 57 | 58 | /** 59 | * Compute the height of the tree. 60 | */ 61 | int computeHeight(); 62 | 63 | /** 64 | * Compute the height of the binary tree in O(N) time. Should not be called often. 65 | * 66 | * @return 67 | */ 68 | int getHeight(); 69 | 70 | /** 71 | * Get the maximum balance of an node in the tree. The balance is the difference in height of the 72 | * two children of a node. 73 | * 74 | * @return 75 | */ 76 | int getMaxBalance(); 77 | 78 | /** 79 | * Get the ratio of the sum of the node areas to the root area. 80 | * 81 | * @return 82 | */ 83 | float getAreaRatio(); 84 | 85 | // void drawTree(DebugDraw draw); 86 | } -------------------------------------------------------------------------------- /src/com/cocos2dj/module/base2d/jbox2d/Pair.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013, Daniel Murphy 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * * Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright notice, 10 | * this list of conditions and the following disclaimer in the documentation 11 | * and/or other materials provided with the distribution. 12 | * 13 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 14 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 15 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 16 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 17 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 18 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 19 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 20 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 21 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 22 | * POSSIBILITY OF SUCH DAMAGE. 23 | ******************************************************************************/ 24 | package com.cocos2dj.module.base2d.jbox2d; 25 | 26 | // updated to rev 100 27 | /** 28 | * Java note: at the "creation" of each node, a random key is given to that node, and that's what we 29 | * sort from. 30 | */ 31 | public class Pair implements Comparable { 32 | public int proxyIdA; 33 | public int proxyIdB; 34 | 35 | public int compareTo(Pair pair2) { 36 | if (this.proxyIdA < pair2.proxyIdA) { 37 | return -1; 38 | } 39 | 40 | if (this.proxyIdA == pair2.proxyIdA) { 41 | return proxyIdB < pair2.proxyIdB ? -1 : proxyIdB == pair2.proxyIdB ? 0 : 1; 42 | } 43 | 44 | return 1; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/com/cocos2dj/module/base2d/jbox2d/PairCallback.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2011, Daniel Murphy 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * * Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright notice, 10 | * this list of conditions and the following disclaimer in the documentation 11 | * and/or other materials provided with the distribution. 12 | * 13 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 14 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 15 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 16 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 17 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 18 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 19 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 20 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 21 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 22 | * POSSIBILITY OF SUCH DAMAGE. 23 | ******************************************************************************/ 24 | package com.cocos2dj.module.base2d.jbox2d; 25 | 26 | // updated to rev 100 27 | public interface PairCallback { 28 | public void addPair(Object userDataA, Object userDataB); 29 | } 30 | -------------------------------------------------------------------------------- /src/com/cocos2dj/module/base2d/jbox2d/RayCastInput.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2011, Daniel Murphy 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * * Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright notice, 10 | * this list of conditions and the following disclaimer in the documentation 11 | * and/or other materials provided with the distribution. 12 | * 13 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 14 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 15 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 16 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 17 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 18 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 19 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 20 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 21 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 22 | * POSSIBILITY OF SUCH DAMAGE. 23 | ******************************************************************************/ 24 | package com.cocos2dj.module.base2d.jbox2d; 25 | 26 | import com.badlogic.gdx.math.Vector2; 27 | 28 | 29 | // updated to rev 100 30 | /** 31 | * Ray-cast input data. The ray extends from p1 to p1 + maxFraction * (p2 - p1). 32 | */ 33 | public class RayCastInput{ 34 | public final Vector2 p1, p2; 35 | public float maxFraction; 36 | 37 | public RayCastInput(){ 38 | p1 = new Vector2(); 39 | p2 = new Vector2(); 40 | maxFraction = 0; 41 | } 42 | 43 | public void set(final RayCastInput rci){ 44 | p1.set(rci.p1); 45 | p2.set(rci.p2); 46 | maxFraction = rci.maxFraction; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/com/cocos2dj/module/base2d/jbox2d/RayCastOutput.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2011, Daniel Murphy 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * * Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright notice, 10 | * this list of conditions and the following disclaimer in the documentation 11 | * and/or other materials provided with the distribution. 12 | * 13 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 14 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 15 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 16 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 17 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 18 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 19 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 20 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 21 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 22 | * POSSIBILITY OF SUCH DAMAGE. 23 | ******************************************************************************/ 24 | package com.cocos2dj.module.base2d.jbox2d; 25 | 26 | import com.badlogic.gdx.math.Vector2; 27 | 28 | // updated to rev 100 29 | /** 30 | * Ray-cast output data. The ray hits at p1 + fraction * (p2 - p1), where p1 and p2 31 | * come from b2RayCastInput. 32 | */ 33 | public class RayCastOutput{ 34 | public final Vector2 normal; 35 | public float fraction; 36 | 37 | public RayCastOutput(){ 38 | normal = new Vector2(); 39 | fraction = 0; 40 | } 41 | 42 | public void set(final RayCastOutput rco){ 43 | normal.set(rco.normal); 44 | fraction = rco.fraction; 45 | } 46 | }; 47 | -------------------------------------------------------------------------------- /src/com/cocos2dj/module/base2d/jbox2d/RaycastResult.java: -------------------------------------------------------------------------------- 1 | package com.cocos2dj.module.base2d.jbox2d; 2 | 3 | import com.badlogic.gdx.math.Vector2; 4 | 5 | public class RaycastResult { 6 | public float lambda = 0.0f; 7 | public final Vector2 normal = new Vector2(); 8 | 9 | public RaycastResult set(RaycastResult argOther){ 10 | lambda = argOther.lambda; 11 | normal.set( argOther.normal); 12 | return this; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/com/cocos2dj/module/base2d/jbox2d/SortKeyFunc.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.cocos2dj.module.base2d.jbox2d; 5 | 6 | 7 | /** 8 | * @author eric 9 | * 10 | */ 11 | public interface SortKeyFunc { 12 | public float apply(Object shape); 13 | } 14 | -------------------------------------------------------------------------------- /src/com/cocos2dj/module/base2d/jbox2d/TreeCallback.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013, Daniel Murphy 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * * Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright notice, 10 | * this list of conditions and the following disclaimer in the documentation 11 | * and/or other materials provided with the distribution. 12 | * 13 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 14 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 15 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 16 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 17 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 18 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 19 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 20 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 21 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 22 | * POSSIBILITY OF SUCH DAMAGE. 23 | ******************************************************************************/ 24 | package com.cocos2dj.module.base2d.jbox2d; 25 | 26 | // update to rev 100 27 | /** 28 | * callback for {@link DynamicTree} 29 | * @author Daniel Murphy 30 | * 31 | */ 32 | public interface TreeCallback { 33 | 34 | /** 35 | * Callback from a query request. 36 | * @param proxyId the id of the proxy 37 | * @return if the query should be continued 38 | */ 39 | public boolean treeCallback(int proxyId); 40 | } 41 | -------------------------------------------------------------------------------- /src/com/cocos2dj/module/base2d/jbox2d/TreeRayCastCallback.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013, Daniel Murphy 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * * Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright notice, 10 | * this list of conditions and the following disclaimer in the documentation 11 | * and/or other materials provided with the distribution. 12 | * 13 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 14 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 15 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 16 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 17 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 18 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 19 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 20 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 21 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 22 | * POSSIBILITY OF SUCH DAMAGE. 23 | ******************************************************************************/ 24 | package com.cocos2dj.module.base2d.jbox2d; 25 | 26 | // updated to rev 100 27 | 28 | /** 29 | * callback for {@link DynamicTree} 30 | * @author Daniel Murphy 31 | * 32 | */ 33 | public interface TreeRayCastCallback { 34 | /** 35 | * 36 | * @param input 37 | * @param nodeId 38 | * @return the fraction to the node 39 | */ 40 | public float raycastCallback( RayCastInput input, int nodeId); 41 | } 42 | -------------------------------------------------------------------------------- /src/com/cocos2dj/module/base2d/jbox2d/pooling/DynamicIntStack.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2011, Daniel Murphy 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * * Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright notice, 10 | * this list of conditions and the following disclaimer in the documentation 11 | * and/or other materials provided with the distribution. 12 | * 13 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 14 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 15 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 16 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 17 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 18 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 19 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 20 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 21 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 22 | * POSSIBILITY OF SUCH DAMAGE. 23 | ******************************************************************************/ 24 | package com.cocos2dj.module.base2d.jbox2d.pooling; 25 | 26 | public class DynamicIntStack { 27 | 28 | private int[] stack; 29 | private int size; 30 | private int position; 31 | 32 | public DynamicIntStack(int initialSize) { 33 | stack = new int[initialSize]; 34 | position = 0; 35 | size = initialSize; 36 | } 37 | 38 | public void reset() { 39 | position = 0; 40 | } 41 | 42 | public int pop() { 43 | assert (position > 0); 44 | return stack[--position]; 45 | } 46 | 47 | public void push(int i) { 48 | if (position == size) { 49 | int[] old = stack; 50 | stack = new int[size + (size >> 1)]; 51 | size = stack.length; 52 | System.arraycopy(old, 0, stack, 0, old.length); 53 | } 54 | stack[position++] = i; 55 | } 56 | 57 | public int getCount() { 58 | return position; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/com/cocos2dj/module/base2d/jbox2d/pooling/DynamicTLArray.java: -------------------------------------------------------------------------------- 1 | package com.cocos2dj.module.base2d.jbox2d.pooling; 2 | 3 | import java.util.HashMap; 4 | 5 | public abstract class DynamicTLArray { 6 | 7 | private static class TLHashMap extends ThreadLocal>{ 8 | protected HashMap initialValue(){ 9 | return new HashMap(); 10 | } 11 | } 12 | 13 | private final TLHashMap tlMap = new TLHashMap(); 14 | 15 | public I[] get( int argLength){ 16 | assert(argLength > 0); 17 | 18 | HashMap map = tlMap.get(); 19 | 20 | if(!map.containsKey(argLength)){ 21 | map.put(argLength, getInitializedArray(argLength)); 22 | } 23 | 24 | assert(map.get(argLength).length == argLength) : "Array not built of correct length"; 25 | return map.get(argLength); 26 | } 27 | 28 | public void recycle( I[] argArray){ 29 | 30 | } 31 | 32 | protected abstract I[] getInitializedArray(int argLength); 33 | } 34 | -------------------------------------------------------------------------------- /src/com/cocos2dj/module/base2d/jbox2d/pooling/IDynamicStack.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2011, Daniel Murphy 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * * Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright notice, 10 | * this list of conditions and the following disclaimer in the documentation 11 | * and/or other materials provided with the distribution. 12 | * 13 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 14 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 15 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 16 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 17 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 18 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 19 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 20 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 21 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 22 | * POSSIBILITY OF SUCH DAMAGE. 23 | ******************************************************************************/ 24 | package com.cocos2dj.module.base2d.jbox2d.pooling; 25 | 26 | /** 27 | * Same functionality of a regular java.util stack. Object 28 | * return order does not matter. 29 | * @author Daniel 30 | * 31 | * @param 32 | */ 33 | public interface IDynamicStack { 34 | 35 | /** 36 | * Pops an item off the stack 37 | * @return 38 | */ 39 | public E pop(); 40 | 41 | /** 42 | * Pushes an item back on the stack 43 | * @param argObject 44 | */ 45 | public void push(E argObject); 46 | 47 | } 48 | -------------------------------------------------------------------------------- /src/com/cocos2dj/module/base2d/jbox2d/pooling/IOrderedStack.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2011, Daniel Murphy 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * * Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright notice, 10 | * this list of conditions and the following disclaimer in the documentation 11 | * and/or other materials provided with the distribution. 12 | * 13 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 14 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 15 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 16 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 17 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 18 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 19 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 20 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 21 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 22 | * POSSIBILITY OF SUCH DAMAGE. 23 | ******************************************************************************/ 24 | package com.cocos2dj.module.base2d.jbox2d.pooling; 25 | 26 | /** 27 | * This stack assumes that when you push 'n' items back, 28 | * you're pushing back the last 'n' items popped. 29 | * @author Daniel 30 | * 31 | * @param 32 | */ 33 | public interface IOrderedStack { 34 | 35 | /** 36 | * Returns the next object in the pool 37 | * @return 38 | */ 39 | public E pop(); 40 | 41 | /** 42 | * Returns the next 'argNum' objects in the pool 43 | * in an array 44 | * @param argNum 45 | * @return an array containing the next pool objects in 46 | * items 0-argNum. Array length and uniqueness not 47 | * guaranteed. 48 | */ 49 | public E[] pop(int argNum); 50 | 51 | /** 52 | * Tells the stack to take back the last 'argNum' items 53 | * @param argNum 54 | */ 55 | public void push(int argNum); 56 | 57 | } 58 | -------------------------------------------------------------------------------- /src/com/cocos2dj/module/base2d/jbox2d/pooling/IWorldPool.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2011, Daniel Murphy 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * * Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright notice, 10 | * this list of conditions and the following disclaimer in the documentation 11 | * and/or other materials provided with the distribution. 12 | * 13 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 14 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 15 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 16 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 17 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 18 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 19 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 20 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 21 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 22 | * POSSIBILITY OF SUCH DAMAGE. 23 | ******************************************************************************/ 24 | package com.cocos2dj.module.base2d.jbox2d.pooling; 25 | 26 | import com.badlogic.gdx.math.Vector2; 27 | import com.cocos2dj.module.base2d.framework.common.AABB; 28 | 29 | 30 | /** 31 | * World pool interface 32 | * @author Daniel 33 | * 34 | */ 35 | public interface IWorldPool { 36 | 37 | //public IDynamicStack getPolyContactStack(); 38 | 39 | //public IDynamicStack getCircleContactStack(); 40 | 41 | //public IDynamicStack getPolyCircleContactStack(); 42 | 43 | public Vector2 popVec2(); 44 | 45 | public Vector2[] popVec2(int argNum); 46 | 47 | public void pushVec2(int argNum); 48 | 49 | //public Vec3 popVec3(); 50 | 51 | //public Vec3[] popVec3(int argNum); 52 | 53 | public void pushVec3(int argNum); 54 | 55 | //public Mat22 popMat22(); 56 | 57 | //public Mat22[] popMat22(int argNum); 58 | 59 | public void pushMat22(int argNum); 60 | 61 | public AABB popAABB(); 62 | 63 | public AABB[] popAABB(int argNum); 64 | 65 | public void pushAABB(int argNum); 66 | 67 | //public Collision getCollision(); 68 | 69 | //public TimeOfImpact getTimeOfImpact(); 70 | 71 | //public Distance getDistance(); 72 | 73 | public float[] getFloatArray(int argLength); 74 | 75 | public int[] getIntArray(int argLength); 76 | 77 | public Vector2[] getVec2Array(int argLength); 78 | 79 | } 80 | -------------------------------------------------------------------------------- /src/com/cocos2dj/module/base2d/jbox2d/pooling/IntegerArray.java: -------------------------------------------------------------------------------- 1 | package com.cocos2dj.module.base2d.jbox2d.pooling; 2 | 3 | 4 | public class IntegerArray extends DynamicTLArray { 5 | @Override 6 | protected final Integer[] getInitializedArray(int argLength) { 7 | return new Integer[argLength]; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/com/cocos2dj/module/base2d/jbox2d/pooling/TLAABB.java: -------------------------------------------------------------------------------- 1 | package com.cocos2dj.module.base2d.jbox2d.pooling; 2 | 3 | import com.cocos2dj.module.base2d.framework.common.AABB; 4 | 5 | public class TLAABB extends ThreadLocal { 6 | protected AABB initialValue(){ 7 | return new AABB(); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/com/cocos2dj/module/base2d/jbox2d/pooling/TLVec2.java: -------------------------------------------------------------------------------- 1 | package com.cocos2dj.module.base2d.jbox2d.pooling; 2 | 3 | import com.badlogic.gdx.math.Vector2; 4 | 5 | 6 | public class TLVec2 extends ThreadLocal { 7 | protected Vector2 initialValue(){ 8 | return new Vector2(); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/com/cocos2dj/module/base2d/jbox2d/pooling/Vec2Array.java: -------------------------------------------------------------------------------- 1 | package com.cocos2dj.module.base2d.jbox2d.pooling; 2 | 3 | import com.badlogic.gdx.math.Vector2; 4 | 5 | 6 | 7 | public class Vec2Array extends DynamicTLArray { 8 | 9 | @Override 10 | protected Vector2[] getInitializedArray(int argLength) { 11 | final Vector2[] ray = new Vector2[argLength]; 12 | for(int i=0; i 13 | * 14 | * @author xu jun 15 | * Copyright (c) 2016. All rights reserved. 16 | */ 17 | public class GdxUISkin implements IDisposable { 18 | 19 | private GdxUISkin() {} 20 | private static GdxUISkin _instance; 21 | public static GdxUISkin instance() { 22 | if(_instance == null) { 23 | _instance = new GdxUISkin(); 24 | Engine.registerDisposable(_instance); 25 | } 26 | return _instance; 27 | } 28 | static class StructSkin { 29 | String first; 30 | Skin second; 31 | } 32 | 33 | 34 | private Skin defaultSkin; 35 | private Array skins = new Array(3); 36 | 37 | public Skin getDeafult() { 38 | if(defaultSkin == null) { 39 | if(GdxUIConfig.instance().uiDefaultSkinPath == null) { 40 | //android 41 | if(FileUtils.getInstance().isFileExist("sfd/uiskin.json")) { 42 | defaultSkin = new Skin(Gdx.files.internal("sfd/uiskin.json")); 43 | } else { 44 | defaultSkin = new Skin(Gdx.files.classpath("com/cocos2dj/module/gdxui/sfd/uiskin.json")); 45 | } 46 | // Gdx.files.classpath("com/cocos2dj/module/gdxui/sfd/uiskin.json"); 47 | } else { 48 | defaultSkin = new Skin(Gdx.files.internal(GdxUIConfig.instance().uiDefaultSkinPath)); 49 | } 50 | } 51 | return defaultSkin; 52 | } 53 | 54 | public Skin getSkin(String path) { 55 | for(int i = 0; i < skins.size; ++i) { 56 | StructSkin ss = skins.get(i); 57 | if(path.equals(ss.first)) { 58 | return ss.second; 59 | } 60 | } 61 | return null; 62 | } 63 | 64 | public Skin loadSkin(String path) { 65 | Skin skin = getSkin(path); 66 | if(skin == null) { 67 | skin = new Skin(Gdx.files.internal(path)); 68 | StructSkin ss = new StructSkin(); 69 | ss.first = path; 70 | ss.second = skin; 71 | skins.add(ss); 72 | } 73 | return skin; 74 | } 75 | 76 | public void clearSkins() { 77 | for(int i = 0; i < skins.size; ++i) { 78 | skins.get(i).second.dispose(); 79 | } 80 | skins.clear(); 81 | } 82 | 83 | @Override 84 | public void dispose() { 85 | if(defaultSkin != null) { 86 | if(Engine.instance().isGLThread()) { 87 | defaultSkin.dispose(); 88 | defaultSkin = null; 89 | } else { 90 | new BaseTask(new Runnable() { 91 | @Override 92 | public void run() { 93 | defaultSkin.dispose(); 94 | defaultSkin = null; 95 | } 96 | }).attachScheduleToRenderBefore(); 97 | } 98 | } 99 | for(int i = 0; i < skins.size; ++i) { 100 | skins.get(i).second.dispose(); 101 | } 102 | skins.clear(); 103 | 104 | _instance = null; 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /src/com/cocos2dj/module/gdxui/sfd/default.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mingwuyun/cocos2d-java/f9534d0daa4ded45905ce670936f20ad5a314846/src/com/cocos2dj/module/gdxui/sfd/default.png -------------------------------------------------------------------------------- /src/com/cocos2dj/module/gdxui/sfd/uiskin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mingwuyun/cocos2d-java/f9534d0daa4ded45905ce670936f20ad5a314846/src/com/cocos2dj/module/gdxui/sfd/uiskin.png -------------------------------------------------------------------------------- /src/com/cocos2dj/module/typefactory/ModuleTypeFactory.java: -------------------------------------------------------------------------------- 1 | package com.cocos2dj.module.typefactory; 2 | 3 | import com.cocos2dj.basic.BaseTask; 4 | import com.cocos2dj.basic.Engine; 5 | import com.cocos2dj.macros.CCLog; 6 | import com.cocos2dj.module.Module; 7 | import com.cocos2dj.protocol.IScene; 8 | import com.cocos2dj.s2d.Scene; 9 | 10 | /** 11 | * ModuleTypeFactory.java 12 | *

    13 | * 14 | * @author Copyright(c) 2017 xu jun 15 | */ 16 | public class ModuleTypeFactory extends Module { 17 | 18 | public static final String ModuleId = "TypeFactory"; 19 | public static final String ModuleType = "NodeFactory"; 20 | 21 | public ModuleTypeFactory() { 22 | super(ModuleId, ModuleType); 23 | } 24 | 25 | @Override 26 | public void onEnter(IScene scene, Object config) { 27 | if(currentScene == null) { 28 | nodeFactory = new NodeFactory(); 29 | currentScene = (Scene) scene; 30 | 31 | } else { 32 | CCLog.engine("ModuleTypeFactory", "currentScene already exists!"); 33 | } 34 | } 35 | 36 | public void onAfterEnter(IScene scene) { 37 | if(nodeFactory != null) { 38 | nodeFactory.end_createInstance(currentScene); 39 | } 40 | } 41 | 42 | @Override 43 | public void onExit(IScene scene) { 44 | currentScene = null; 45 | nodeFactory.clear(); 46 | nodeFactory = null; 47 | } 48 | 49 | /** 50 | * autoFlush = true 51 | * @see #addNodeType(NodeType, boolean) 52 | */ 53 | public void addNodeType(NodeType type) { 54 | addNodeType(type, true); 55 | } 56 | 57 | /** 58 | * 添加 节点类型对象 59 | * @param type 60 | * @param autoFlush 是否自动刷新 61 | */ 62 | public void addNodeType(NodeType type, boolean autoFlush) { 63 | nodeFactory.putActorType(type); 64 | if(autoFlush) { 65 | if(Engine.instance().isGLThread()) { 66 | nodeFactory.flush_createInstances(currentScene); 67 | } else { 68 | BaseTask.create(new Runnable() { 69 | @Override 70 | public void run() { 71 | nodeFactory.flush_createInstances(currentScene); 72 | } 73 | }).attachScheduleToRenderBefore(); 74 | } 75 | } 76 | } 77 | 78 | public NodeType findNodeType(String key) { 79 | return nodeFactory.getActorType(key); 80 | } 81 | 82 | 83 | Scene currentScene; 84 | NodeFactory nodeFactory; 85 | } 86 | -------------------------------------------------------------------------------- /src/com/cocos2dj/module/typefactory/NodePools.java: -------------------------------------------------------------------------------- 1 | package com.cocos2dj.module.typefactory; 2 | 3 | import com.badlogic.gdx.utils.Array; 4 | import com.cocos2dj.basic.Engine; 5 | import com.cocos2dj.basic.IDisposable; 6 | import com.cocos2dj.macros.CCLog; 7 | 8 | /** 9 | * Pool管理器

    10 | * 11 | * 所有创建的 {@link NodePool} 都会保存在这个管理器中
    12 | * 管理器内部采用 Array 管理对象池, 所以可以使用“位置” 以及 “名称” 查询。

    13 | * 14 | * 每一个创建的实体对象池 内部也会保存其在EntityPool中的位置, 调用方法 15 | * C2EntityPool.getID() 可以获取这个位置。

    16 | * 17 | * 另外对于Pool对象的删除应该谨慎, 由于C2Pools中保存了所有EntityPool, 18 | * 必须在这个管理器中删除池对象,否则垃圾回收器无法将其回收. 19 | * 20 | * @author Copyright (c) 2014. xu jun 21 | * */ 22 | public class NodePools implements IDisposable { 23 | 24 | private static NodePools instance; 25 | private static Array> pools = new Array>(); 26 | 27 | public static final NodePools getPools() { 28 | if(instance == null) { 29 | instance = new NodePools(); 30 | } 31 | return instance; 32 | } 33 | 34 | 35 | /**获取指定编号的 对象池 */ 36 | // @SuppressWarnings("rawtypes") 37 | public static final NodePool getObjectPool(int index) { 38 | return pools.get(index); 39 | } 40 | 41 | public static final void addObjectPool(NodePool pool) { 42 | if(instance == null) { //实例化对象 为了注册dispose方法的调用 43 | instance = new NodePools(); 44 | } 45 | pools.add(pool); 46 | pool.setPoolID(pools.size - 1); 47 | 48 | CCLog.engine("NodePools", "add || poolCount: "+ pools.size); 49 | } 50 | 51 | /**删除对象池 52 | * @param pool 指定的对象池 53 | * @param dispose 是否释放对象 true 调用对象的dispose方法释放对象池 54 | * @return 删除成功返回true */ 55 | public static final boolean removeObjectPool(final NodePool pool, boolean dispose) { 56 | final int index = pool.getPoolID(); 57 | if(index < 0 || index >= pools.size) 58 | return false; 59 | pools.removeIndex(pool.getPoolID()); 60 | pool.setPoolID(-1); 61 | 62 | if(dispose) pool.dispose(); 63 | 64 | updatePoolsID(); 65 | return true; 66 | } 67 | 68 | /**更新所有 对象池 ID */ 69 | static final void updatePoolsID() { 70 | for(int i = 0; i < pools.size; ++i) { 71 | pools.get(i).setPoolID(i); 72 | } 73 | } 74 | 75 | /**清理所有对象池 该方法会强制回收所有池中的对象 */ 76 | public static final void clearObjectPools() { 77 | for(int i = 0; i < pools.size; ++i) { 78 | NodePool p = pools.get(i); 79 | p.dispose(); 80 | p.setPoolID(-1); 81 | } 82 | pools.clear(); 83 | } 84 | 85 | /**获取C2Pools中所有的Pool状态 */ 86 | public static String getPoolsState() { 87 | StringBuilder sb = new StringBuilder(128); 88 | for(int i = 0; i < pools.size; ++i) { 89 | sb.append(pools.get(i)); sb.append('\n'); 90 | } 91 | return sb.toString(); 92 | } 93 | 94 | public void dispose() { 95 | clearObjectPools(); 96 | instance = null; 97 | } 98 | 99 | private NodePools() { 100 | Engine.registerDisposable(this); 101 | } 102 | } 103 | 104 | -------------------------------------------------------------------------------- /src/com/cocos2dj/module/typefactory/PoolListener.java: -------------------------------------------------------------------------------- 1 | package com.cocos2dj.module.typefactory; 2 | 3 | import com.cocos2dj.s2d.Node; 4 | 5 | /** 6 | * PoolListener.java 7 | *
    PoolNodeEvent 8 | *

    9 | * 10 | * @author Copyright (c) 2016 xu jun 11 | */ 12 | public interface PoolListener { 13 | 14 | public static enum PoolEvent { 15 | /**awake*/Pop, 16 | /**sleep*/Push, 17 | } 18 | 19 | /** 20 | * SObject事件,该事件不能自定义触发,由SObject触发 21 | * 22 | * @param eventType 23 | * @param obj 24 | * @return 是否删除(返回true移除该监听) 25 | */ 26 | public boolean onObjectEvent(PoolEvent eventType, Node obj); 27 | } 28 | -------------------------------------------------------------------------------- /src/com/cocos2dj/module/typefactory/SmartType.java: -------------------------------------------------------------------------------- 1 | package com.cocos2dj.module.typefactory; 2 | 3 | import com.cocos2dj.base.Director; 4 | import com.cocos2dj.s2d.Node; 5 | import com.cocos2dj.s2d.Scene; 6 | 7 | /** 8 | * SmartType.java 9 | *

    10 | * 11 | * typeFactory辅助对象,根据放入 {@link NodeFactory} 中Type的键值获取对应的node对象 12 | * 第一次会从module中获取,之后缓存nodeType,可以快速取得目标node 13 | *
    14 | *

    15 |  * SmartType type = SmartType.create("TargetNode1");
    16 |  * Node target = type.getNode();
    17 |  * NodeProxy = target.getNodeProxy();
    18 |  * ...
    19 |  * target.pushBack();
    20 |  * 
    21 | * 22 | * @author Copyright(c) 2017 xujun 23 | */ 24 | public class SmartType { 25 | 26 | private String key; 27 | private NodeType type; 28 | 29 | public static SmartType create(String key) { 30 | return new SmartType(key); 31 | } 32 | 33 | public SmartType(String key) { 34 | this.key = key; 35 | } 36 | 37 | public final Node getObject() { 38 | if(type == null) { 39 | Scene scene = (Scene) Director.getInstance().getRunningScene(); 40 | ModuleTypeFactory factory = (ModuleTypeFactory) scene.getModule(ModuleTypeFactory.class); 41 | type = factory.findNodeType(key); 42 | } 43 | return type.getInstance(); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/com/cocos2dj/platform/AppDelegate.java: -------------------------------------------------------------------------------- 1 | package com.cocos2dj.platform; 2 | 3 | /** 4 | * AppDelegate.java 5 | *

    6 | * 7 | * @author Copyright (c) 2017 xu jun 8 | */ 9 | public interface AppDelegate { 10 | 11 | /** 12 | * Cocos引擎初始化之前调用 13 | * 可以对cocos2dj引擎进行参数设置,注意引擎此时不能使用,应该只设置参数 14 | * 此时gdx初始化完毕 15 | */ 16 | public void initConfiguration(); 17 | 18 | /** 19 | @brief Implement Director and Scene init code here. 20 | @return true Initialize success, app continue. 21 | @return false Initialize failed, app terminate. 22 | */ 23 | public boolean applicationDidFinishLaunching(); 24 | 25 | /** 26 | @brief Called when the application moves to the background 27 | @param the pointer of the application 28 | */ 29 | public void applicationDidEnterBackground(); 30 | 31 | /** 32 | @brief Called when the application reenters the foreground 33 | @param the pointer of the application 34 | */ 35 | public void applicationWillEnterForeground(); 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/com/cocos2dj/platform/ResolutionPolicy.java: -------------------------------------------------------------------------------- 1 | package com.cocos2dj.platform; 2 | 3 | public enum ResolutionPolicy 4 | { 5 | /** The entire application is visible in the specified area without trying to preserve the original aspect ratio. 6 | // Distortion can occur, and the application may appear stretched or compressed. */ 7 | EXACT_FIT, 8 | /** The entire application fills the specified area, without distortion but possibly with some cropping, 9 | // while maintaining the original aspect ratio of the application. */ 10 | NO_BORDER, 11 | /** The entire application is visible in the specified area without distortion while maintaining the original 12 | // aspect ratio of the application. Borders can appear on two sides of the application. */ 13 | SHOW_ALL, 14 | /** The application takes the height of the design resolution size and modifies the width of the internal 15 | // canvas so that it fits the aspect ratio of the device 16 | // no distortion will occur however you must make sure your application works on different */ 17 | // aspect ratios 18 | FIXED_HEIGHT, 19 | /** The application takes the width of the design resolution size and modifies the height of the internal 20 | // canvas so that it fits the aspect ratio of the device 21 | // no distortion will occur however you must make sure your application works on different 22 | // aspect ratios */ 23 | FIXED_WIDTH, 24 | 25 | UNKNOWN, 26 | }; 27 | -------------------------------------------------------------------------------- /src/com/cocos2dj/protocol/IAction.java: -------------------------------------------------------------------------------- 1 | package com.cocos2dj.protocol; 2 | 3 | public interface IAction { 4 | 5 | public static final int INVALID_TAG = -1; 6 | 7 | public void startWithTarget(INode node); 8 | 9 | public INode getOriginalTarget(); 10 | 11 | public int getTag(); 12 | 13 | public int getFlags(); 14 | 15 | 16 | public void step(float dt); 17 | 18 | public void stop(); 19 | 20 | public boolean isDone(); 21 | 22 | /**设置是否在ActionManager中执行 */ 23 | public void setAttached(boolean attached); 24 | 25 | /**@return 是否在ActionManager中执行 */ 26 | public boolean isAttached(); 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/com/cocos2dj/protocol/ICamera.java: -------------------------------------------------------------------------------- 1 | package com.cocos2dj.protocol; 2 | 3 | /** 4 | * ICamera.java 5 | *

    6 | * 7 | * @author Copyright (c) 2017 xu jun 8 | */ 9 | public interface ICamera { 10 | 11 | public boolean isVisible(); 12 | 13 | public int getCameraFlag(); 14 | } 15 | -------------------------------------------------------------------------------- /src/com/cocos2dj/protocol/IComponent.java: -------------------------------------------------------------------------------- 1 | package com.cocos2dj.protocol; 2 | 3 | import com.cocos2dj.s2d.Node; 4 | 5 | /** 6 | * Component.java 7 | *

    8 | * 9 | * @author Copyright (c) 2017 xu jun 10 | */ 11 | public interface IComponent { 12 | 13 | /* 14 | * 以下方法按照协议实现 15 | */ 16 | public void setOwner(Node owner); 17 | 18 | public Node getOwner(); 19 | 20 | public boolean isEnabled(); 21 | 22 | public void setEnabled(boolean enabled); 23 | 24 | public String getName(); 25 | public void setName(String name); 26 | 27 | // public final void setOwner(Node owner) {this._owner = owner;} 28 | // public final Node getOwner() {return _owner;} 29 | // public boolean isEnabled() {return _enabled;} 30 | // public void setEnabled(boolean enabled) {_enabled = enabled;} 31 | // public String getName() {return _name;} 32 | // public void setName(String name) {_name = name;} 33 | // protected Node _owner; 34 | // protected String _name; 35 | // protected boolean _enabled; 36 | 37 | 38 | public void update(float delta); 39 | public void onEnter(); 40 | public void onExit(); 41 | public void onAdd(); 42 | public void onRemove(); 43 | 44 | //pools 45 | public void onSleep(); 46 | public void onAwake(); 47 | } 48 | -------------------------------------------------------------------------------- /src/com/cocos2dj/protocol/IFunctionOneArg.java: -------------------------------------------------------------------------------- 1 | package com.cocos2dj.protocol; 2 | 3 | public interface IFunctionOneArg { 4 | 5 | public void callback(T t); 6 | 7 | } 8 | -------------------------------------------------------------------------------- /src/com/cocos2dj/protocol/IFunctionOneArgRet.java: -------------------------------------------------------------------------------- 1 | package com.cocos2dj.protocol; 2 | 3 | public interface IFunctionOneArgRet { 4 | 5 | public R callback(T t); 6 | 7 | } 8 | -------------------------------------------------------------------------------- /src/com/cocos2dj/protocol/IFunctionZeroArg.java: -------------------------------------------------------------------------------- 1 | package com.cocos2dj.protocol; 2 | 3 | public interface IFunctionZeroArg { 4 | 5 | public V callback(); 6 | 7 | } 8 | -------------------------------------------------------------------------------- /src/com/cocos2dj/protocol/INodePool.java: -------------------------------------------------------------------------------- 1 | package com.cocos2dj.protocol; 2 | 3 | public interface INodePool { 4 | 5 | public void pushPoolNode(INode node); 6 | 7 | } 8 | -------------------------------------------------------------------------------- /src/com/cocos2dj/protocol/INodeType.java: -------------------------------------------------------------------------------- 1 | package com.cocos2dj.protocol; 2 | 3 | public interface INodeType { 4 | 5 | public void pushSingletonNode(INode node); 6 | 7 | } 8 | -------------------------------------------------------------------------------- /src/com/cocos2dj/protocol/IScene.java: -------------------------------------------------------------------------------- 1 | package com.cocos2dj.protocol; 2 | 3 | import com.badlogic.gdx.math.Matrix4; 4 | import com.cocos2dj.renderer.Renderer; 5 | 6 | public interface IScene extends INode { 7 | 8 | public int getCamerasCount(); 9 | 10 | public ICamera getCamera(int index); 11 | 12 | public void render(Renderer renderer, Matrix4 eyeTransform, Matrix4 eyeProjection); 13 | } 14 | -------------------------------------------------------------------------------- /src/com/cocos2dj/protocol/ITransitionScene.java: -------------------------------------------------------------------------------- 1 | package com.cocos2dj.protocol; 2 | 3 | public interface ITransitionScene { 4 | // public void onExitTransitionDidStart(); 5 | // public void onEnterTransitionDidFinish(); 6 | } 7 | -------------------------------------------------------------------------------- /src/com/cocos2dj/protocol/IUpdater.java: -------------------------------------------------------------------------------- 1 | package com.cocos2dj.protocol; 2 | 3 | public interface IUpdater { 4 | 5 | public boolean update(float dt); 6 | 7 | } 8 | -------------------------------------------------------------------------------- /src/com/cocos2dj/renderer/FrameBuffer.java: -------------------------------------------------------------------------------- 1 | package com.cocos2dj.renderer; 2 | 3 | public class FrameBuffer { 4 | 5 | 6 | } 7 | -------------------------------------------------------------------------------- /src/com/cocos2dj/renderer/Viewport.java: -------------------------------------------------------------------------------- 1 | package com.cocos2dj.renderer; 2 | 3 | public final class Viewport { 4 | 5 | public static Viewport _defaultViewport = new Viewport(); 6 | 7 | public static final void setDefaultViewport(float left, float bottom, float width, float height) { 8 | _defaultViewport._left = left; 9 | _defaultViewport._bottom = bottom; 10 | _defaultViewport._width = width; 11 | _defaultViewport._height = height; 12 | } 13 | 14 | public Viewport(float left, float bottom, float width, float height) { 15 | this._left = left; 16 | this._bottom = bottom; 17 | this._width = width; 18 | this._height = height; 19 | } 20 | 21 | public Viewport() { 22 | 23 | } 24 | 25 | public void set(Viewport other) { 26 | this._left = other._left; 27 | this._bottom = other._bottom; 28 | this._width = other._width; 29 | this._height = other._height; 30 | } 31 | 32 | public float _left; 33 | public float _bottom; 34 | public float _width; 35 | public float _height; 36 | 37 | 38 | public String toString() { 39 | return "left = " + _left + " bottom = " + _bottom + " width = " + _width + " height = " + _height; 40 | } 41 | } -------------------------------------------------------------------------------- /src/com/cocos2dj/s2d/ActionInstant.java: -------------------------------------------------------------------------------- 1 | package com.cocos2dj.s2d; 2 | 3 | import com.cocos2dj.macros.CCLog; 4 | import com.cocos2dj.s2d.Action.FiniteTimeAction; 5 | 6 | /** 7 | * ActionInstant.java 8 | *

    9 | * 瞬时动作 10 | * @brief Instant actions are immediate actions. They don't have a duration like the IntervalAction actions. 11 | * 12 | * @author Copyright(c) 2017 xujun 13 | */ 14 | public class ActionInstant extends FiniteTimeAction { 15 | 16 | public ActionInstant copy() { 17 | CCLog.error("ActionInstant", "should override method copy()"); 18 | return null; 19 | } 20 | 21 | public ActionInstant reverse() { 22 | CCLog.error("ActionInstant", "should override method copy()"); 23 | return null; 24 | } 25 | 26 | public boolean isDone() { 27 | return true; 28 | } 29 | public void step(float dt) { 30 | update(1f); 31 | } 32 | public void update(float t) { 33 | 34 | } 35 | 36 | ////////////////////////////////////// 37 | //TODO CallFunc 38 | public static class CallFunc extends ActionInstant { 39 | 40 | /** Creates the action with the callback of type std::function. 41 | This is the preferred way to create the callback. 42 | * When this function bound in js or lua ,the input param will be changed. 43 | * In js: var create(var func, var this, var [data]) or var create(var func). 44 | * In lua:local create(local funcID). 45 | * 46 | * @param func A callback function need to be executed. 47 | * @return An autoreleased CallFunc object. 48 | */ 49 | public static CallFunc create(Runnable func) { 50 | CallFunc ret = new CallFunc(); 51 | if(ret.initWithFunction(func)) { 52 | return ret; 53 | } 54 | return null; 55 | } 56 | 57 | /** Executes the callback. 58 | */ 59 | public void execute() { 60 | if(_function != null) { 61 | _function.run(); 62 | } 63 | } 64 | 65 | // 66 | // Overrides 67 | // 68 | /** 69 | * @param time In seconds. 70 | */ 71 | public void update(float time) { 72 | execute(); 73 | } 74 | public CallFunc reverse() { 75 | return CallFunc.create(_function); 76 | } 77 | public CallFunc copy() { 78 | return CallFunc.create(_function); 79 | } 80 | 81 | // CC_CONSTRUCTOR_ACCESS: 82 | public CallFunc() { 83 | 84 | } 85 | 86 | /** initializes the action with the std::function 87 | * @lua NA 88 | */ 89 | public boolean initWithFunction(Runnable func) { 90 | this._function = func; 91 | return true; 92 | } 93 | 94 | 95 | /** function that will be called */ 96 | Runnable _function; 97 | // std::function _function; 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /src/com/cocos2dj/ui/Button.java: -------------------------------------------------------------------------------- 1 | package com.cocos2dj.ui; 2 | 3 | public class Button { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /src/com/cocos2dj/ui/GUIDefine.java: -------------------------------------------------------------------------------- 1 | package com.cocos2dj.ui; 2 | 3 | public class GUIDefine { 4 | 5 | public static final String __LAYOUT_COMPONENT_NAME = "__ui_layout"; 6 | } 7 | -------------------------------------------------------------------------------- /src/com/cocos2dj/ui/Layout.java: -------------------------------------------------------------------------------- 1 | package com.cocos2dj.ui; 2 | 3 | public class Layout extends Widget { 4 | 5 | public boolean isClippingEnabled() { 6 | // TODO Auto-generated method stub 7 | return false; 8 | } 9 | 10 | } 11 | -------------------------------------------------------------------------------- /src/com/cocos2dj/ui/LayoutComponent.java: -------------------------------------------------------------------------------- 1 | package com.cocos2dj.ui; 2 | 3 | import com.badlogic.gdx.math.Vector2; 4 | import com.cocos2dj.protocol.IComponent; 5 | import com.cocos2dj.s2d.Node; 6 | 7 | public class LayoutComponent implements IComponent { 8 | 9 | public static LayoutComponent create() { 10 | LayoutComponent ret = new LayoutComponent(); 11 | 12 | return ret; 13 | } 14 | 15 | public void setPositionPercentX(float x) { 16 | // TODO Auto-generated method stub 17 | 18 | } 19 | 20 | public void refreshLayout() { 21 | // TODO Auto-generated method stub 22 | 23 | } 24 | 25 | public void setPositionPercentY(float y) { 26 | // TODO Auto-generated method stub 27 | 28 | } 29 | 30 | public float getPositionPercentX() { 31 | // TODO Auto-generated method stub 32 | return 0; 33 | } 34 | 35 | public float getPositionPercentY() { 36 | // TODO Auto-generated method stub 37 | return 0; 38 | } 39 | 40 | public void setPositionPercentXEnabled(boolean b) { 41 | // TODO Auto-generated method stub 42 | 43 | } 44 | 45 | public void setPositionPercentYEnabled(boolean b) { 46 | // TODO Auto-generated method stub 47 | 48 | } 49 | 50 | public void setUsingPercentContentSize(boolean b) { 51 | // TODO Auto-generated method stub 52 | 53 | } 54 | 55 | public void setPercentContentSize(Vector2 percent) { 56 | // TODO Auto-generated method stub 57 | 58 | } 59 | 60 | public Vector2 getPercentContentSize() { 61 | // TODO Auto-generated method stub 62 | return null; 63 | } 64 | 65 | @Override 66 | public void setOwner(Node owner) { 67 | // TODO Auto-generated method stub 68 | 69 | } 70 | 71 | @Override 72 | public Node getOwner() { 73 | // TODO Auto-generated method stub 74 | return null; 75 | } 76 | 77 | @Override 78 | public boolean isEnabled() { 79 | // TODO Auto-generated method stub 80 | return false; 81 | } 82 | 83 | @Override 84 | public void setEnabled(boolean enabled) { 85 | // TODO Auto-generated method stub 86 | 87 | } 88 | 89 | @Override 90 | public String getName() { 91 | // TODO Auto-generated method stub 92 | return null; 93 | } 94 | 95 | @Override 96 | public void setName(String name) { 97 | // TODO Auto-generated method stub 98 | 99 | } 100 | 101 | @Override 102 | public void update(float delta) { 103 | // TODO Auto-generated method stub 104 | 105 | } 106 | 107 | @Override 108 | public void onEnter() { 109 | // TODO Auto-generated method stub 110 | 111 | } 112 | 113 | @Override 114 | public void onExit() { 115 | // TODO Auto-generated method stub 116 | 117 | } 118 | 119 | @Override 120 | public void onAdd() { 121 | // TODO Auto-generated method stub 122 | 123 | } 124 | 125 | @Override 126 | public void onRemove() { 127 | // TODO Auto-generated method stub 128 | 129 | } 130 | 131 | @Override 132 | public void onSleep() { 133 | // TODO Auto-generated method stub 134 | 135 | } 136 | 137 | @Override 138 | public void onAwake() { 139 | // TODO Auto-generated method stub 140 | 141 | } 142 | 143 | } 144 | -------------------------------------------------------------------------------- /src/com/cocos2dj/ui/LayoutParameter.java: -------------------------------------------------------------------------------- 1 | package com.cocos2dj.ui; 2 | 3 | public class LayoutParameter { 4 | 5 | /** 6 | * Protocol for getting a LayoutParameter. 7 | * Every element want to have layout parameter should inherit from this class. 8 | */ 9 | public static interface ILayoutParameter { 10 | // public void release(); 11 | /** 12 | * 13 | *@return A LayoutParameter and its descendant pointer. 14 | */ 15 | public LayoutParameter getLayoutParameter(); 16 | }; 17 | } 18 | -------------------------------------------------------------------------------- /src/com/cocos2dj/utils/Direct.java: -------------------------------------------------------------------------------- 1 | package com.cocos2dj.utils; 2 | 3 | import com.badlogic.gdx.math.MathUtils; 4 | import com.badlogic.gdx.math.Vector2; 5 | 6 | /**������������

    7 | * ����Ӧ�����ķ�����ѷ����� �ṩͳһ�ij�����ʾ 8 | * @author xu jun */ 9 | public class Direct { 10 | 11 | public static final int NULL = 0; 12 | public static final int RIGHT = 1; 13 | public static final int RIGHT_UP = 2; 14 | public static final int UP = 3; 15 | public static final int LEFT_UP = 4; 16 | public static final int LEFT = 5; 17 | public static final int LEFT_DOWN = 6; 18 | public static final int DOWN = 7; 19 | public static final int RIGHT_DOWN = 8; 20 | 21 | /* 22 | * up: 1000 23 | * down: 0100 24 | * left: 0010 25 | * right: 0001 26 | * leftup: 27 | * leftdown: 28 | * rightup: 29 | * rightdown: 30 | */ 31 | public static final int getDirect(boolean up, boolean down, boolean left, boolean right) { 32 | if(left) { 33 | if(up) { 34 | return Direct.LEFT_UP; 35 | } else if(down) { 36 | return Direct.LEFT_DOWN; 37 | } else { 38 | return Direct.LEFT; 39 | } 40 | } else if(right) { 41 | if(up) { 42 | return Direct.RIGHT_UP; 43 | } else if(down) { 44 | return Direct.RIGHT_DOWN; 45 | } else { 46 | return Direct.RIGHT; 47 | } 48 | } else if(up) { 49 | return Direct.UP; 50 | } else if(down) { 51 | return Direct.DOWN; 52 | } 53 | return Direct.NULL; 54 | } 55 | 56 | /**����t1�����t0�ķ�λ���ķ��� 57 | * @return t1�����t0�ķ�λ Direct��ij��� */ 58 | public static final int getDirect4(final Vector2 t1, final Vector2 t0){ 59 | final float dx = t1.x-t0.x; 60 | final float dy = t1.y-t0.y; 61 | 62 | if(Math.abs(dx) < Math.abs(dy)){ 63 | if(dy > 0) {return Direct.UP;} 64 | else {return Direct.DOWN;} 65 | } 66 | else{ 67 | if(dx > 0) {return Direct.RIGHT;} 68 | else {return Direct.LEFT;} 69 | } 70 | } 71 | 72 | /**����t1�����t0�ķ�λ���˷��� 73 | * @return t1�����t0�ķ�λ Direct��ij��� */ 74 | public static final int getDirect8(final Vector2 t1, final Vector2 t0){ 75 | final float dx = t1.x-t0.x; 76 | final float dy = t1.y-t0.y; 77 | 78 | final float tan = dy/dx; 79 | 80 | if(dy > 0){ 81 | if(dx > 0){ 82 | if(tan < 0.414)return Direct.RIGHT; 83 | else if(tan > 2.414)return Direct.UP; 84 | else return Direct.RIGHT_UP; 85 | } 86 | else{ 87 | if(tan > -0.414)return Direct.LEFT; 88 | else if(tan < -2.414)return Direct.UP; 89 | else return Direct.LEFT_UP; 90 | } 91 | } 92 | else{ 93 | if(dx>0){ 94 | if(tan > -0.414)return Direct.RIGHT; 95 | else if(tan < -2.414)return Direct.DOWN; 96 | else return Direct.RIGHT_DOWN; 97 | } 98 | else{ 99 | if(tan < 0.414)return Direct.LEFT; 100 | else if(tan>2.414)return Direct.DOWN; 101 | else return Direct.LEFT_DOWN; 102 | } 103 | } 104 | } 105 | 106 | /**����t1�����t0�ķ�λ������ֵ�� 107 | * @return �����t0����ϵ�Ļ��� */ 108 | public static final float getDirectRad(final Vector2 t1, final Vector2 t0){ 109 | final float dx = t1.x-t0.x; 110 | final float dy = t1.y-t0.y; 111 | 112 | return MathUtils.atan2(dy, dx); 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /src/com/cocos2dj/utils/IObjectPool.java: -------------------------------------------------------------------------------- 1 | package com.cocos2dj.utils; 2 | 3 | public interface IObjectPool { 4 | public T pop(); 5 | public T get(); 6 | public void push(T t); 7 | public T[] getAll(); 8 | public void dispose(); 9 | } 10 | -------------------------------------------------------------------------------- /src/com/cocos2dj/utils/Installation.java: -------------------------------------------------------------------------------- 1 | package com.cocos2dj.utils; 2 | // 3 | //import java.io.File; 4 | //import java.io.FileOutputStream; 5 | //import java.io.IOException; 6 | //import java.io.RandomAccessFile; 7 | //import java.util.UUID; 8 | 9 | /** 10 | * �����Լ���ȡ��ʶ��Ĺ��� 11 | */ 12 | public class Installation { 13 | 14 | private static String sID = null; 15 | // private static final String INSTALLATION = "C2INSTALLATION"; 16 | 17 | public synchronized static String id() { 18 | if (sID == null) { 19 | /* File installation = new File(context.getFilesDir(), INSTALLATION); 20 | try { 21 | if (!installation.exists()) 22 | writeInstallationFile(installation); 23 | sID = readInstallationFile(installation); 24 | } catch (Exception e) { 25 | throw new RuntimeException(e); 26 | }*/ 27 | } 28 | return sID; 29 | } 30 | // private static String readInstallationFile(File installation) throws IOException { 31 | // RandomAccessFile f = new RandomAccessFile(installation, "r"); 32 | // byte[] bytes = new byte[(int) f.length()]; 33 | // f.readFully(bytes); 34 | // f.close(); 35 | // return new String(bytes); 36 | // } 37 | // 38 | // private static void writeInstallationFile(File installation) throws IOException { 39 | // FileOutputStream out = new FileOutputStream(installation); 40 | // String id = UUID.randomUUID().toString(); 41 | // out.write(id.getBytes()); 42 | // out.close(); 43 | // } 44 | } 45 | -------------------------------------------------------------------------------- /src/com/cocos2dj/utils/MessUtils.java: -------------------------------------------------------------------------------- 1 | package com.cocos2dj.utils; 2 | 3 | import java.lang.reflect.Field; 4 | 5 | import com.badlogic.gdx.math.Vector2; 6 | 7 | /** 8 | * MessUtils.java 9 | *

    10 | * 11 | * 各种乱七八糟的功能集合 12 | * 13 | * @author Copyright(c) 2016-2017 xu jun 14 | */ 15 | public class MessUtils { 16 | 17 | public static float[] pointsToFloats(Vector2...verts) { 18 | float[] ps = new float[verts.length]; 19 | for(int i = 0; i < verts.length; ++i) { 20 | ps[i * 2] = verts[i].x; 21 | ps[i * 2 + 1] = verts[i].y; 22 | } 23 | return ps; 24 | } 25 | 26 | /** */ 27 | public static String getFieldsStr(Object o) { 28 | return getFieldsStr(o, true); 29 | } 30 | 31 | /***/ 32 | public static String getFieldsStr(Object o, boolean onlyPublic) { 33 | StringBuilder sb = new StringBuilder(); 34 | Field[] fs; 35 | if(onlyPublic) { 36 | fs = o.getClass().getFields(); 37 | } 38 | else { 39 | fs = o.getClass().getDeclaredFields(); 40 | } 41 | for(int i = 0; i < fs.length; ++i) { 42 | String name = fs[i].getName(); 43 | Object v = null; 44 | try { 45 | v = fs[i].get(o); 46 | } catch (IllegalArgumentException e) { 47 | e.printStackTrace(); 48 | } catch (IllegalAccessException e) { 49 | e.printStackTrace(); 50 | } 51 | sb.append(name + ":").append(v).append(","); 52 | } 53 | return sb.toString(); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/com/cocos2dj/utils/ObjectPoolBuilder.java: -------------------------------------------------------------------------------- 1 | package com.cocos2dj.utils; 2 | 3 | /** 4 | * ObjectPoolBuilder.java 5 | *

    6 | * 包装对象池的创建 7 | *

     8 |  * //ObjectPoolBuilder builder = new ObjectPoolBuilder<>();
     9 |  * ObjectPoolBuilder builder = ObjectPoolBuilder.startBuilder();
    10 |  * builder.setClass(Object.class)
    11 |  * 			.setInitCount(3)
    12 |  * 			.setAddCount(2)
    13 |  * 			.createNormalPool();
    14 |  * 
    15 |  * @author Copyright (c) 2016 xujun
    16 |  */
    17 | public class ObjectPoolBuilder {
    18 | 	
    19 | 	/**开始构建 */
    20 | 	public static  ObjectPoolBuilder startBuilder() {
    21 | 		return new ObjectPoolBuilder();
    22 | 	}
    23 | 	
    24 | 	//fields>>
    25 | 	private Class 	sClass;
    26 | 	private Class[] 	params;
    27 | 	private Object[] 	args;
    28 | 	
    29 | 	private int 		initCount = 2;
    30 | 	private int 		addCount = 1;
    31 | 	//fields<<
    32 | 	
    33 | 	//methods>>
    34 | 	public ObjectPoolBuilder setClass(Class clazz) {
    35 | 		this.sClass = clazz;
    36 | 		return this;
    37 | 	}
    38 | 	
    39 | 	public ObjectPoolBuilder setParamsClass(Class...params) {
    40 | 		this.params = params;
    41 | 		return this;
    42 | 	}
    43 | 	
    44 | 	public ObjectPoolBuilder setParams(Object...args) {
    45 | 		this.args = args;
    46 | 		return this;
    47 | 	}
    48 | 	
    49 | 	public ObjectPoolBuilder setInitCount(int initCount) {
    50 | 		this.initCount = initCount;
    51 | 		return this;
    52 | 	}
    53 | 	
    54 | 	public ObjectPoolBuilder setAddCount(int addCount) {
    55 | 		this.addCount = addCount;
    56 | 		return this;
    57 | 	}
    58 | 	
    59 | 	/**
    60 | 	 * 默认创建方法 
    61 | 	 * @see #createAddingPool()
    62 | 	 * */
    63 | 	public ObjectPoolLinear create() {
    64 | 		return createAddingPool();
    65 | 	}
    66 | 	
    67 | 	/**
    68 | 	 * 创建指数增长对象池
    69 | 	 * 
    newCount = currCount * 2 70 | */ 71 | public ObjectPool createNormalPool() { 72 | return new ObjectPool<>(sClass, initCount, params, args); 73 | } 74 | 75 | /**创建线性增长对象池
    76 | * newCount = currCount + addCount */ 77 | public ObjectPoolLinear createAddingPool() { 78 | return new ObjectPoolLinear<>(sClass, initCount, addCount, params, args); 79 | } 80 | //methods<< 81 | } 82 | -------------------------------------------------------------------------------- /src/com/cocos2dj/utils/TransformUtils.java: -------------------------------------------------------------------------------- 1 | package com.cocos2dj.utils; 2 | 3 | import com.badlogic.gdx.math.Matrix4; 4 | import com.cocos2dj.base.AffineTransform; 5 | 6 | public class TransformUtils { 7 | 8 | /** 9 | Conversion between mat4*4 and AffineTransform. 10 | @param m The Mat4*4 pointer. 11 | @param t Affine transform. 12 | */ 13 | public static void CGAffineToGL(final AffineTransform t, final float[] m) { 14 | // | m[0] m[4] m[8] m[12] | | m11 m21 m31 m41 | | a c 0 tx | 15 | // | m[1] m[5] m[9] m[13] | | m12 m22 m32 m42 | | b d 0 ty | 16 | // | m[2] m[6] m[10] m[14] | <=> | m13 m23 m33 m43 | <=> | 0 0 1 0 | 17 | // | m[3] m[7] m[11] m[15] | | m14 m24 m34 m44 | | 0 0 0 1 | 18 | //in libgdx >>> 19 | // | m[0] m[1] m[2] m[3] | | m00 m01 m02 m03 | | a c 0 tx | 20 | // | m[4] m[5] m[6] m[7] | | m10 m11 m12 m13 | | b d 0 ty | 21 | // | m[8] m[9] m[10] m[11] | <=> | m20 m21 m22 m23 | <=> | 0 0 1 0 | 22 | // | m[12] m[13] m[14] m[15] | | m30 m31 m32 m33 | | 0 0 0 1 | 23 | m[2] = m[3] = m[6] = m[7] = m[8] = m[9] = m[11] = m[14] = 0.0f; 24 | m[10] = m[15] = 1.0f; 25 | m[0] = t.a; m[4] = t.c; m[12] = t.tx; 26 | m[1] = t.b; m[5] = t.d; m[13] = t.ty; 27 | } 28 | 29 | public static void GLToCGAffine(final float[] m, AffineTransform t) { 30 | t.a = m[0]; t.c = m[4]; t.tx = m[Matrix4.M03]; 31 | t.b = m[1]; t.d = m[5]; t.ty = m[Matrix4.M13]; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /tests/src-android/tests/Activity_Tests.java: -------------------------------------------------------------------------------- 1 | package tests; 2 | 3 | import android.os.Bundle; 4 | 5 | import com.badlogic.gdx.LifecycleListener; 6 | import com.badlogic.gdx.backends.android.AndroidApplication; 7 | import com.cocos2dj.platform.android.ApplicationStartup; 8 | 9 | /** 10 | * android 版本测试启动 11 | */ 12 | public class Activity_Tests extends AndroidApplication { 13 | 14 | @Override 15 | protected void onCreate(Bundle savedInstanceState) { 16 | super.onCreate(savedInstanceState); 17 | ApplicationStartup.start(new TestAppDelegate_Tests(), this); 18 | } 19 | 20 | protected void onDestroy() { 21 | super.onDestroy(); 22 | // System.exit(0); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /tests/src-desktop/tests/Main_Empty.java: -------------------------------------------------------------------------------- 1 | package tests; 2 | 3 | import com.cocos2dj.platform.AppDelegate; 4 | import com.cocos2dj.platform.desktop.ApplicationStartup; 5 | 6 | 7 | public class Main_Empty { 8 | 9 | public static void main(String[] args) { 10 | 11 | ApplicationStartup.start(new AppDelegate(){ 12 | 13 | @Override 14 | public void initConfiguration() { 15 | 16 | } 17 | 18 | @Override 19 | public boolean applicationDidFinishLaunching() { 20 | return false; 21 | } 22 | 23 | @Override 24 | public void applicationDidEnterBackground() { 25 | 26 | } 27 | 28 | @Override 29 | public void applicationWillEnterForeground() { 30 | 31 | } 32 | 33 | }); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /tests/src-desktop/tests/Main_GdxUI.java: -------------------------------------------------------------------------------- 1 | package tests; 2 | 3 | import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration; 4 | import com.cocos2dj.platform.desktop.ApplicationStartup; 5 | 6 | /** 7 | * GdxUI 组件测试 8 | * 9 | * @author xujun 10 | */ 11 | public class Main_GdxUI { 12 | 13 | public static void main(String[] args) { 14 | LwjglApplicationConfiguration conf = ApplicationStartup.getConfiguration(); 15 | conf.width = 800; conf.height = 480; 16 | ApplicationStartup.start(new TestAppDelegate_GdxUI()); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /tests/src-desktop/tests/Main_Tests.java: -------------------------------------------------------------------------------- 1 | package tests; 2 | 3 | import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration; 4 | import com.cocos2dj.platform.desktop.ApplicationStartup; 5 | 6 | /** 7 | * 测试 8 | * 9 | * @author xujun 10 | */ 11 | public class Main_Tests { 12 | 13 | public static void main(String[] args) { 14 | LwjglApplicationConfiguration conf = ApplicationStartup.getConfiguration(); 15 | // conf.width = 600; conf.height = 338; 16 | conf.width = 480; conf.height = 270; 17 | conf.x = 50; 18 | // conf.width = 800; conf.height = 450; 19 | // cancel fps limit 20 | // conf.vSyncEnabled = false;conf.backgroundFPS = 0;conf.foregroundFPS = 0; 21 | ApplicationStartup.start(new TestAppDelegate_Tests()); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /tests/src/tests/TestAppDelegate_Tests.java: -------------------------------------------------------------------------------- 1 | package tests; 2 | 3 | import com.badlogic.gdx.Files.FileType; 4 | import com.cocos2dj.base.Director; 5 | import com.cocos2dj.basic.Engine; 6 | import com.cocos2dj.platform.AppDelegate; 7 | import com.cocos2dj.platform.FileUtils; 8 | import com.cocos2dj.platform.ResolutionPolicy; 9 | 10 | /** 11 | * 12 | * @author xujun 13 | */ 14 | public class TestAppDelegate_Tests implements AppDelegate { 15 | 16 | TestController _testController; 17 | 18 | @Override 19 | public void initConfiguration() { 20 | Engine.setSingleThreadMode(); 21 | // Engine.setDoubleThreadMode(); 22 | } 23 | 24 | @Override 25 | public boolean applicationDidFinishLaunching() { 26 | FileUtils.getInstance().addSearchPath("/Users/xujun/remoteProject/Cocos2dJavaImages", FileType.Absolute, true); 27 | FileUtils.getInstance().addSearchPath("Resource", FileType.Internal, true); 28 | 29 | Director.getInstance().getOpenGLView().setDesignResolutionSize(1136, 640, ResolutionPolicy.EXACT_FIT); 30 | 31 | _testController = TestController.getInstance(); 32 | _testController.start(); 33 | return true; 34 | } 35 | 36 | @Override 37 | public void applicationDidEnterBackground() { 38 | if(_testController != null) { 39 | _testController.onEnterBackground(); 40 | } 41 | Director.getInstance().stopAnimation(); 42 | } 43 | 44 | @Override 45 | public void applicationWillEnterForeground() { 46 | if(_testController != null) { 47 | _testController.onEnterForeground(); 48 | } 49 | Director.getInstance().startAnimation(); 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /tests/src/tests/TestBase.java: -------------------------------------------------------------------------------- 1 | package tests; 2 | 3 | import com.badlogic.gdx.utils.Array; 4 | 5 | /** 6 | * 测试用例 7 | * 8 | * @author xujun 9 | */ 10 | public abstract class TestBase { 11 | 12 | public void backsUpOneLevel() { 13 | if(_parentTest != null) { 14 | _parentTest.runThisTest(); 15 | } 16 | } 17 | 18 | public abstract void runThisTest(); 19 | 20 | public boolean isTestList() {return _isTestList;} 21 | public int getChildTestCount() {return _childTestNames.size;} 22 | 23 | public void _setTestParent(TestBase parent) {_parentTest = parent;} 24 | TestBase getTestParent() {return _parentTest;} 25 | 26 | public void setTestName(String name) {_testName = name;} 27 | public String getTestName() {return _testName;} 28 | 29 | //fields>> 30 | String _testName; 31 | TestBase _parentTest = null; 32 | boolean _isTestList = false; 33 | Array _childTestNames = new Array<>(); 34 | //fields<< 35 | } 36 | -------------------------------------------------------------------------------- /tests/src/tests/TestSuite.java: -------------------------------------------------------------------------------- 1 | package tests; 2 | 3 | import com.badlogic.gdx.utils.Array; 4 | import com.cocos2dj.base.Director; 5 | import com.cocos2dj.protocol.IFunctionZeroArg; 6 | import com.cocos2dj.protocol.IScene; 7 | 8 | /** 9 | * suite: [case, case,] 10 | * 11 | * @author xujun 12 | */ 13 | public class TestSuite extends TestBase { 14 | 15 | public static TestCase getTestCase(IScene scene) { 16 | //TODO unfinished 17 | return (TestCase) scene; 18 | } 19 | 20 | 21 | public void addTestCase(String testName, IFunctionZeroArg callback) { 22 | if(testName != null && callback != null) { 23 | _childTestNames.add(testName); 24 | _testCallbacks.add(callback); 25 | } 26 | } 27 | 28 | public void restartCurrTest() { 29 | IScene scene = _testCallbacks.get(_currTestIndex).callback(); 30 | TestCase testCase = getTestCase(scene); 31 | testCase.setTestSuite(this); 32 | testCase.setTestCaseName(_childTestNames.get(_currTestIndex)); 33 | Director.getInstance().replaceScene(scene); 34 | } 35 | 36 | public void enterNextTest() { 37 | _currTestIndex = (_currTestIndex + 1) % _childTestNames.size; 38 | 39 | IScene scene = _testCallbacks.get(_currTestIndex).callback(); 40 | TestCase testCase = getTestCase(scene); 41 | testCase.setTestSuite(this); 42 | testCase.setTestCaseName(_childTestNames.get(_currTestIndex)); 43 | 44 | Director.getInstance().replaceScene(scene); 45 | } 46 | 47 | public void enterPreviousTest() { 48 | if(_currTestIndex > 0) { 49 | _currTestIndex -= 1; 50 | } else { 51 | _currTestIndex = _childTestNames.size - 1; 52 | } 53 | IScene scene = _testCallbacks.get(_currTestIndex).callback(); 54 | TestCase testCase = getTestCase(scene); 55 | testCase.setTestSuite(this); 56 | testCase.setTestCaseName(_childTestNames.get(_currTestIndex)); 57 | 58 | Director.getInstance().replaceScene(scene); 59 | } 60 | 61 | public int getCurrTestIndex() {return _currTestIndex;} 62 | 63 | 64 | @Override 65 | public void runThisTest() { 66 | if(_childTestNames.size > 0) { 67 | TestController.getInstance().setCurrTestSuite(this); 68 | 69 | _currTestIndex = 0; 70 | IScene scene = _testCallbacks.get(0).callback(); 71 | TestCase testCase = getTestCase(scene); 72 | 73 | testCase.setTestSuite(this); 74 | testCase.setTestCaseName(_childTestNames.get(_currTestIndex)); 75 | Director.getInstance().replaceScene(scene); 76 | } 77 | } 78 | 79 | 80 | //fields>> 81 | Array> _testCallbacks = new Array<>(); 82 | int _currTestIndex; 83 | //fields<< 84 | } 85 | -------------------------------------------------------------------------------- /tests/src/tests/testcase/ATempleTests.java: -------------------------------------------------------------------------------- 1 | package tests.testcase; 2 | 3 | import tests.TestCase; 4 | import tests.TestSuite; 5 | 6 | public class ATempleTests extends TestSuite { 7 | 8 | public ATempleTests() { 9 | addTestCase("Test", ()->{return new Test();}); 10 | } 11 | 12 | static class TestDemo extends TestCase { 13 | 14 | } 15 | 16 | static class Test extends TestDemo { 17 | 18 | public void onEnter() { 19 | super.onEnter(); 20 | } 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /tests/src/tests/testcase/Box2dTests.java: -------------------------------------------------------------------------------- 1 | package tests.testcase; 2 | 3 | public class Box2dTests { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /tests/src/tests/testcase/CCUITests.java: -------------------------------------------------------------------------------- 1 | package tests.testcase; 2 | 3 | public class CCUITests { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /tests/src/tests/testcase/EventTests.java: -------------------------------------------------------------------------------- 1 | package tests.testcase; 2 | 3 | import com.cocos2dj.base.Event; 4 | import com.cocos2dj.base.EventDispatcher; 5 | import com.cocos2dj.base.EventListenerKeyboard; 6 | import com.cocos2dj.base.EventListenerTouchOneByOne; 7 | import com.cocos2dj.base.EventListenerTouchOneByOne.TouchCallback; 8 | import com.cocos2dj.base.Touch; 9 | import com.cocos2dj.s2d.DrawNode; 10 | import com.cocos2dj.s2d.Node; 11 | 12 | import tests.TestCase; 13 | import tests.TestSuite; 14 | 15 | /** 16 | * 事件测试

    17 | * 18 | * @author xu jun 19 | */ 20 | public class EventTests extends TestSuite { 21 | 22 | public EventTests() { 23 | addTestCase("TouchEventTest", ()->{return new TouchEventTest();}); 24 | // addTestCase("NodeTest4", ()->{return new NodeTest4();}); 25 | } 26 | 27 | static class EventTestDemo extends TestCase { 28 | 29 | } 30 | 31 | static class TouchEventTest extends EventTestDemo { 32 | 33 | public void onEnter() { 34 | super.onEnter(); 35 | 36 | Node node = Node.create(); 37 | addChild(node); 38 | 39 | EventDispatcher ed = _director.getEventDispatcher(); 40 | 41 | //add touch listener 42 | EventListenerTouchOneByOne l = EventListenerTouchOneByOne.create(); 43 | l.setOnTouchBeganCallback((touch, event)->{ 44 | System.out.println("began" + touch.getLocation()); 45 | return true; 46 | }); 47 | l.setOnTouchMovedCallback((touch, event)->{ 48 | System.out.println("moved > touch = " + touch); 49 | }); 50 | l.setOnTouchEndedCallback((touch, event)->{ 51 | System.out.println("end > touch = " + touch.getLocation()); 52 | }); 53 | ed.addEventListenerWithSceneGraphPriority(l, this); 54 | 55 | //add keylistener 56 | EventListenerKeyboard kl = EventListenerKeyboard.create(); 57 | kl.setOnKeyPressedCallback((key, e)->{ 58 | System.out.println("key is " + key); 59 | }); 60 | ed.addEventListenerWithSceneGraphPriority(kl, this); 61 | 62 | DrawNode dn = new DrawNode(); 63 | addChild(dn); 64 | } 65 | 66 | 67 | public String subtitle() { 68 | return "anchorPoint and children"; 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /tests/src/tests/testcase/InfiniteActionTests.java: -------------------------------------------------------------------------------- 1 | package tests.testcase; 2 | 3 | import com.cocos2dj.s2d.ActionCondition.Bezier; 4 | import com.cocos2dj.s2d.ActionCondition.Jump; 5 | import com.cocos2dj.s2d.ActionCondition.Move; 6 | import com.cocos2dj.s2d.Node; 7 | import com.cocos2dj.s2d.Sprite; 8 | 9 | import tests.TestCase; 10 | import tests.TestSuite; 11 | 12 | /** 13 | * 不限制结束时间对动作测试 14 | * 15 | * @author xujun 16 | */ 17 | public class InfiniteActionTests extends TestSuite { 18 | 19 | public InfiniteActionTests() { 20 | addTestCase("InfiniteMove", ()->{return new InfiniteMoveTest();}); 21 | } 22 | 23 | static class TestDemo extends TestCase { 24 | 25 | } 26 | 27 | static class InfiniteMoveTest extends TestDemo { 28 | 29 | public void onEnter() { 30 | super.onEnter(); 31 | 32 | Node node = Sprite.create("powered.png"); 33 | node.setContentSize(50, 50); 34 | addChild(node); 35 | 36 | //move 37 | Move action = Move.create(-1, 600, 0); 38 | // move when position > 600 39 | action.setUpdateCallback((self, t)->{ 40 | // System.out.println("t = " + t); 41 | if(node.getPositionX() > 600) { 42 | return true; 43 | } 44 | return false; 45 | }); 46 | node.runAction(action); 47 | 48 | //bezier 49 | Bezier bz = new Bezier(); 50 | bz.initWithEndTime(-1, 5, 500, 0, 250, 200, 250, 200); 51 | Node node2 = Sprite.create("powered.png").addTo(this); 52 | node2.setContentSize(50, 50); 53 | node2.setPosition(100, 200); 54 | node2.runAction(bz); 55 | node2.runAction(Move.create(-1, 100, 0)); // 叠加move 56 | 57 | //jump 58 | Jump jp = new Jump(); 59 | jp.initWithEndTime(-1, 3f, -1000, 0, 540); 60 | Node node3 = Sprite.create("powered.png").addTo(this); 61 | node3.setContentSize(50, 50); 62 | node3.setPosition(1000, 100); 63 | node3.runAction(jp); 64 | } 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /tests/src/tests/testcase/NodeTests.java: -------------------------------------------------------------------------------- 1 | package tests.testcase; 2 | 3 | import com.badlogic.gdx.graphics.Color; 4 | import com.cocos2dj.base.Rect; 5 | import com.cocos2dj.s2d.ActionInterval.MoveTo; 6 | import com.cocos2dj.s2d.ActionInterval.RotateBy; 7 | import com.cocos2dj.s2d.DrawNode; 8 | import com.cocos2dj.s2d.Node; 9 | import com.cocos2dj.s2d.Sprite; 10 | 11 | import tests.TestCase; 12 | import tests.TestSuite; 13 | 14 | /** 15 | * 节点相关测试 16 | * 17 | * @author xujun 18 | */ 19 | public class NodeTests extends TestSuite { 20 | 21 | public NodeTests() { 22 | addTestCase("BoundingBoxTest", ()->{return new NodeTest2();}); 23 | addTestCase("NodeTest4", ()->{return new NodeTest4();}); 24 | } 25 | 26 | static class NodeTestDemo extends TestCase { 27 | 28 | } 29 | 30 | static class NodeTest2 extends NodeTestDemo { 31 | 32 | public void onEnter() { 33 | super.onEnter(); 34 | 35 | Node node = Sprite.create("powered.png"); 36 | addChild(node); 37 | 38 | node.setOnTransformCallback((n)->{ 39 | // System.out.println("updateTransform = " + node.getPosition()); 40 | }); 41 | 42 | DrawNode dn = new DrawNode(); 43 | addChild(dn); 44 | 45 | node.setContentSize(100, 100); 46 | 47 | DrawNode debugDraw = (DrawNode) DrawNode.create().addTo(this); 48 | 49 | node.setOnUpdateCallback((n, t)->{ 50 | Rect r = node.getBoundingBox(); 51 | debugDraw.drawRect(r.x, r.y, r.x + r.width, r.y + r.height, null); 52 | }); 53 | node.scheduleUpdate(); 54 | node.setAnchorPoint(0f, 0f); 55 | node.runAction(MoveTo.create(2, 1000, 500)); 56 | node.runAction(RotateBy.create(2, 1000)); 57 | 58 | 59 | // node.runAction(Move.create(2, 0, 100)); 60 | // node.runAction(MoveBy.create(0.5f, 500, 100)); 61 | 62 | node.setColor(Color.RED); 63 | node.setOpacity(0.5f); 64 | } 65 | 66 | 67 | public String subtitle() { 68 | return "anchorPoint and children"; 69 | } 70 | } 71 | 72 | static class NodeTest4 extends NodeTestDemo { 73 | public void onEnter() { 74 | super.onEnter(); 75 | // System.out.println("debug enter >>>>>> "); 76 | } 77 | 78 | public String subtitle() { 79 | return "tags"; 80 | } 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /tests/src/tests/testcase/ShaderTests.java: -------------------------------------------------------------------------------- 1 | package tests.testcase; 2 | 3 | import com.badlogic.gdx.graphics.glutils.ShaderProgram; 4 | import com.cocos2dj.module.base2d.framework.common.MathUtils; 5 | import com.cocos2dj.renderer.GLProgramCache; 6 | import com.cocos2dj.s2d.Sprite; 7 | 8 | import tests.TestCase; 9 | import tests.TestSuite; 10 | 11 | /** 12 | * 着色器测试 13 | * 14 | * @author xujun 15 | */ 16 | public class ShaderTests extends TestSuite { 17 | 18 | public ShaderTests() { 19 | addTestCase("ShaderTest1", ()->{return new ShaderTest1();}); 20 | } 21 | 22 | static class ShaderTestBase extends TestCase { 23 | 24 | } 25 | 26 | static class ShaderTest1 extends ShaderTestBase { 27 | 28 | Sprite spriteShader; 29 | Sprite spriteNormal; 30 | 31 | public void onEnter() { 32 | super.onEnter(); 33 | 34 | // for(int i = 0; i < 2000; ++i) { 35 | // spriteNormal = Sprite.create("powered.png"); 36 | // spriteNormal.setContentSize(20, 20); 37 | // spriteNormal.setPosition(MathUtils.randomFloat(0, 1200), MathUtils.randomFloat(0, 650)); 38 | // addChild(spriteNormal); 39 | // } 40 | 41 | spriteShader = Sprite.create("powered.png"); 42 | spriteShader.setPosition(300, 320); 43 | addChild(spriteShader); 44 | 45 | spriteNormal = Sprite.create("powered.png"); 46 | spriteNormal.setPosition(800, 320); 47 | addChild(spriteNormal); 48 | 49 | ShaderProgram shader = GLProgramCache.getInstance().loadGLProgramFromStringAndFile( 50 | GLProgramCache.getInstance().getSpriteBatchDefaultProgram().getVertexShaderSource(), 51 | "shader/flip.fragment.glsl"); 52 | // shader.setUniformi("", 1); 53 | // spriteShader.setShaderProgram(shader); 54 | 55 | // spriteShader.getGLProgramShader().set; 56 | 57 | 58 | scheduleUpdate(); 59 | } 60 | 61 | public boolean update(float dt) { 62 | // for(int i = 0; i < 1000000; ++i) { 63 | // Math.sqrt(Math.random()); 64 | // } 65 | return false; 66 | } 67 | 68 | public String subtitle() { 69 | return "shader test"; 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /tests/src/tests/testcase/TextureAtlasTests.java: -------------------------------------------------------------------------------- 1 | package tests.testcase; 2 | 3 | import com.badlogic.gdx.graphics.g2d.TextureAtlas; 4 | import com.cocos2dj.macros.CC; 5 | import com.cocos2dj.s2d.Sprite; 6 | 7 | import tests.TestCase; 8 | import tests.TestSuite; 9 | 10 | public class TextureAtlasTests extends TestSuite { 11 | 12 | public TextureAtlasTests() { 13 | addTestCase("SpriteFrameCacheTest", ()->{return new SpriteFrameCacheTest();}); 14 | addTestCase("GdxTextureAtlasTest", ()->{return new GdxTextureAtlasTest();}); 15 | 16 | } 17 | 18 | static class TestDemo extends TestCase { 19 | 20 | } 21 | 22 | //TODO gdx格式直接读取读取 23 | static class GdxTextureAtlasTest extends TestDemo { 24 | public void onEnter() { 25 | super.onEnter(); 26 | 27 | TextureAtlas atlas; 28 | atlas = CC.TextureAtlas("pack.atlas"); 29 | 30 | Sprite.createWithSpriteFrame(atlas.findRegion("scene_b1")).addTo(this).setPosition(100, 300); 31 | Sprite.createWithSpriteFrame(atlas.findRegion("scene_b2")).addTo(this).setPosition(200, 300); 32 | Sprite.createWithSpriteFrame(atlas.findRegion("scene_b3")).addTo(this).setPosition(300, 300); 33 | Sprite.createWithSpriteFrame(atlas.findRegion("scene_b4")).addTo(this).setPosition(400, 300); 34 | Sprite.createWithSpriteFrame(atlas.findRegion("scene_b5")).addTo(this).setPosition(500, 300); 35 | Sprite.createWithSpriteFrame(atlas.findRegion("scene_b6")).addTo(this).setPosition(600, 300); 36 | } 37 | } 38 | 39 | //TODO 使用SptieFrameCache创建纹理 40 | static class SpriteFrameCacheTest extends TestDemo { 41 | public void onEnter() { 42 | super.onEnter(); 43 | 44 | //读取atlas到spriteFrameCache 45 | CC.LoadAtlas("pack.atlas"); //("pack.atlas"); 46 | 47 | Sprite.createWithSpriteFrameName("scene_b1").addTo(this).setPosition(100, 300); 48 | Sprite.createWithSpriteFrameName("scene_b2").addTo(this).setPosition(200, 300); 49 | Sprite.createWithSpriteFrameName("scene_b3").addTo(this).setPosition(300, 300); 50 | 51 | //释放atlas资源 52 | CC.UnloadAtlas("pack.atlas"); 53 | 54 | Sprite.createWithSpriteFrameName("scene_b4").addTo(this).setPosition(400, 300); 55 | Sprite.createWithSpriteFrameName("scene_b5").addTo(this).setPosition(500, 300); 56 | Sprite.createWithSpriteFrameName("scene_b6").addTo(this).setPosition(600, 300); 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /tests/src/tests/testcase/TiledMapTests.java: -------------------------------------------------------------------------------- 1 | package tests.testcase; 2 | 3 | import java.util.Iterator; 4 | 5 | import com.badlogic.gdx.Gdx; 6 | import com.badlogic.gdx.graphics.OrthographicCamera; 7 | import com.badlogic.gdx.maps.tiled.TiledMap; 8 | import com.badlogic.gdx.maps.tiled.TiledMapRenderer; 9 | import com.badlogic.gdx.maps.tiled.TmxMapLoader; 10 | import com.badlogic.gdx.maps.tiled.renderers.OrthogonalTiledMapRenderer; 11 | import com.cocos2dj.basic.BaseUpdater; 12 | import com.cocos2dj.macros.CC; 13 | import com.cocos2dj.s2d.ActionInterval.MoveBy; 14 | import com.cocos2dj.s2d.ActionInterval.RotateBy; 15 | import com.cocos2dj.s2d.ActionInterval.ScaleTo; 16 | import com.cocos2dj.s2d.Sprite; 17 | import com.cocos2dj.s2d.TMXTiledMap; 18 | 19 | import tests.TestCase; 20 | import tests.TestSuite; 21 | 22 | public class TiledMapTests extends TestSuite { 23 | 24 | public TiledMapTests() { 25 | addTestCase("TiledMapTest1", ()->{return new TiledMapTest1();}); 26 | addTestCase("GdxTiledMapTest", ()->{return new GdxTiledMapTest();}); 27 | } 28 | 29 | static class TestDemo extends TestCase { 30 | 31 | } 32 | 33 | 34 | static class TiledMapTest1 extends TestDemo { 35 | public void onEnter() { 36 | super.onEnter(); 37 | 38 | Sprite spriteColor1 = (Sprite) Sprite.create("powered.png").addTo(this); 39 | spriteColor1.setPosition(100, 300); 40 | 41 | TMXTiledMap map = new TMXTiledMap(); 42 | map.initWithTMXFile("Resource/tiles.tmx"); 43 | addChild(map); 44 | 45 | map.runAction(ScaleTo.create(2, 2)); 46 | map.runAction(MoveBy.create(2, 200, 0)); 47 | 48 | Sprite spriteColor2 = (Sprite) Sprite.create("powered.png").addTo(this); 49 | spriteColor2.setPosition(900, 300); 50 | } 51 | } 52 | 53 | //////////////////////////////////////// 54 | //直接使用gdx提供的tiledMap 55 | static class GdxTiledMapTest extends TestDemo { 56 | private TiledMap map; 57 | private TiledMapRenderer renderer; 58 | private OrthographicCamera camera; 59 | 60 | private BaseUpdater func; 61 | 62 | public void onEnter() { 63 | super.onEnter(); 64 | 65 | float w = Gdx.graphics.getWidth(); 66 | float h = Gdx.graphics.getHeight(); 67 | 68 | camera = new OrthographicCamera(); 69 | camera.setToOrtho(false, (w / h) * 640, 640); 70 | camera.update(); 71 | 72 | map = new TmxMapLoader().load("Resource/tiles.tmx"); 73 | renderer = new OrthogonalTiledMapRenderer(map, 2f);//1f / 32f); 74 | 75 | func = CC.Scheduler().renderAfterSchedulePerFrame((t)->{ 76 | camera.position.set(500, 320, 0); 77 | camera.update(); 78 | renderer.setView( 79 | camera.combined, 80 | 0, 0, 1000, 500); 81 | renderer.render(); 82 | return false; 83 | }, 0, false); 84 | } 85 | 86 | public void onExit() { 87 | super.onExit(); 88 | map.dispose(); 89 | func.removeSelf(); 90 | } 91 | } 92 | 93 | } 94 | 95 | -------------------------------------------------------------------------------- /tests/src/tests/testcase/VisUITests.java: -------------------------------------------------------------------------------- 1 | package tests.testcase; 2 | 3 | import com.badlogic.gdx.files.FileHandle; 4 | import com.cocos2dj.module.visui.ModuleVisUI; 5 | import com.cocos2dj.module.visui.VisUIHelper; 6 | import com.kotcrab.vis.ui.widget.VisWindow; 7 | import com.kotcrab.vis.ui.widget.file.FileChooser; 8 | import com.kotcrab.vis.ui.widget.file.FileTypeFilter; 9 | import com.kotcrab.vis.ui.widget.file.StreamingFileChooserListener; 10 | import tests.TestCase; 11 | import tests.TestSuite; 12 | 13 | /** 14 | * VisUI 测试 15 | * 16 | * @author xujun 17 | */ 18 | public class VisUITests extends TestSuite { 19 | 20 | public VisUITests() { 21 | addTestCase("FileChooser", ()->{return new FileChooserTest();}); 22 | } 23 | 24 | static class VisUITestDemo extends TestCase { 25 | protected ModuleVisUI _visUI; 26 | public void onEnter() { 27 | super.onEnter(); 28 | _visUI = createModule(ModuleVisUI.class); 29 | } 30 | } 31 | 32 | static class FileChooserTest extends VisUITestDemo { 33 | 34 | FileChooser chooser; 35 | 36 | public void onEnter() { 37 | super.onEnter(); 38 | 39 | chooser = VisUIHelper.createOpenFileChooser(800, 450); 40 | _visUI.getGdxUI().addUIDefault(chooser); 41 | 42 | chooser.setListener(new StreamingFileChooserListener() { 43 | @Override 44 | public void selected (FileHandle file) { 45 | switch(chooser.getMode()) { 46 | case OPEN: 47 | System.out.println("openFile:" + file.name()); 48 | break; 49 | case SAVE: 50 | System.out.println("saveFile:" + file.name()); 51 | break; 52 | } 53 | } 54 | public void canceled() { 55 | System.out.println("cancel"); 56 | } 57 | }); 58 | final FileTypeFilter typeFilter = new FileTypeFilter(true); 59 | typeFilter.addRule("Image files (*.png, *.jpg, *.gif)", "png", "jpg", "gif"); 60 | typeFilter.addRule("Text files (*.txt)", "txt"); 61 | typeFilter.addRule("Audio files (*.mp3, *.wav, *.ogg)", "mp3", "wav", "ogg"); 62 | chooser.setFileTypeFilter(typeFilter); 63 | 64 | VisWindow window = VisUIHelper.createWindow("testWindow", 600, 388, true); 65 | _visUI.getGdxUI().addUIDefault(window); 66 | } 67 | 68 | 69 | public String subtitle() { 70 | return "anchorPoint and children"; 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /tools/bmpToPng.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mingwuyun/cocos2d-java/f9534d0daa4ded45905ce670936f20ad5a314846/tools/bmpToPng.jar -------------------------------------------------------------------------------- /tools/in/scene_b1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mingwuyun/cocos2d-java/f9534d0daa4ded45905ce670936f20ad5a314846/tools/in/scene_b1.jpg -------------------------------------------------------------------------------- /tools/in/scene_b2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mingwuyun/cocos2d-java/f9534d0daa4ded45905ce670936f20ad5a314846/tools/in/scene_b2.jpg -------------------------------------------------------------------------------- /tools/in/scene_b3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mingwuyun/cocos2d-java/f9534d0daa4ded45905ce670936f20ad5a314846/tools/in/scene_b3.jpg -------------------------------------------------------------------------------- /tools/in/scene_b4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mingwuyun/cocos2d-java/f9534d0daa4ded45905ce670936f20ad5a314846/tools/in/scene_b4.jpg -------------------------------------------------------------------------------- /tools/in/scene_b5.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mingwuyun/cocos2d-java/f9534d0daa4ded45905ce670936f20ad5a314846/tools/in/scene_b5.jpg -------------------------------------------------------------------------------- /tools/in/scene_b6.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mingwuyun/cocos2d-java/f9534d0daa4ded45905ce670936f20ad5a314846/tools/in/scene_b6.jpg -------------------------------------------------------------------------------- /tools/in/scene_copy.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mingwuyun/cocos2d-java/f9534d0daa4ded45905ce670936f20ad5a314846/tools/in/scene_copy.jpg -------------------------------------------------------------------------------- /tools/in/scene_del.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mingwuyun/cocos2d-java/f9534d0daa4ded45905ce670936f20ad5a314846/tools/in/scene_del.jpg -------------------------------------------------------------------------------- /tools/out/pack.atlas: -------------------------------------------------------------------------------- 1 | 2 | pack.png 3 | size: 512,64 4 | format: RGBA8888 5 | filter: Nearest,Nearest 6 | repeat: none 7 | scene_b1 8 | rotate: false 9 | xy: 2, 2 10 | size: 32, 32 11 | orig: 32, 32 12 | offset: 0, 0 13 | index: -1 14 | scene_b2 15 | rotate: false 16 | xy: 36, 2 17 | size: 32, 32 18 | orig: 32, 32 19 | offset: 0, 0 20 | index: -1 21 | scene_b3 22 | rotate: false 23 | xy: 70, 2 24 | size: 32, 32 25 | orig: 32, 32 26 | offset: 0, 0 27 | index: -1 28 | scene_b4 29 | rotate: false 30 | xy: 104, 2 31 | size: 32, 32 32 | orig: 32, 32 33 | offset: 0, 0 34 | index: -1 35 | scene_b5 36 | rotate: false 37 | xy: 138, 2 38 | size: 32, 32 39 | orig: 32, 32 40 | offset: 0, 0 41 | index: -1 42 | scene_b6 43 | rotate: false 44 | xy: 172, 2 45 | size: 32, 32 46 | orig: 32, 32 47 | offset: 0, 0 48 | index: -1 49 | scene_copy 50 | rotate: false 51 | xy: 206, 2 52 | size: 32, 32 53 | orig: 32, 32 54 | offset: 0, 0 55 | index: -1 56 | scene_del 57 | rotate: false 58 | xy: 240, 2 59 | size: 32, 32 60 | orig: 32, 32 61 | offset: 0, 0 62 | index: -1 63 | -------------------------------------------------------------------------------- /tools/out/pack.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mingwuyun/cocos2d-java/f9534d0daa4ded45905ce670936f20ad5a314846/tools/out/pack.png -------------------------------------------------------------------------------- /tools/runnable-texturepacker.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mingwuyun/cocos2d-java/f9534d0daa4ded45905ce670936f20ad5a314846/tools/runnable-texturepacker.jar -------------------------------------------------------------------------------- /tools/工具说明.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mingwuyun/cocos2d-java/f9534d0daa4ded45905ce670936f20ad5a314846/tools/工具说明.txt --------------------------------------------------------------------------------