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
18 | *
19 | * 添加逻辑:如果存在ModuleGdxUI则只添加本组件;
20 | * 如果不存在ModuleGdxUI会同GdxUI一起添加
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 | *
11 | *
12 | * 桌面版本启动函数
13 | *
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 | *
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
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
8 | *
9 | * @author Copyright(c) 2017 xujun
10 | */
11 | public class EventListenerKeyboard extends EventListener implements IFunctionOneArg
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 | *
5 | *
6 | * �ö�ʱ�����ò�ѯ�ķ�ʽ���С���C2Timer�������������У�ֻ�е����ض��IJ�ѯ״̬��
7 | * ���·�����Ż��������ʱ�����ж��Ƿ�ʱʱ�䡣�������Ϊ��Ҫ������������߳�
8 | *
9 | * ͨ������{@link #overTime()}��������ȡ��ʱ��Ϣ��
10 | * ���ע����TimeListener�����ͨ������ {@link #updateTime()}���������¶�ʱ��״̬��
11 | *
12 | * ��ʱ���Ĺ�����ʽ�У�
13 | *
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
8 | *
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
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的位置
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的数据
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 | 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倍
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
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
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} 都会保存在这个管理器中
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
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 | *
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
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
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
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 | *
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
--------------------------------------------------------------------------------
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 | *
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 | *
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 | *
Type
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 | * ����
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 | *
55 | * Gdxui = scene.getModule<'Gdxui'>(Gdxui.class);
56 | *
57 | * @param clazz
58 | * @return
59 | */
60 | @SuppressWarnings("unchecked")
61 | public
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处理后的向量)
用于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 | *
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
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
12 | * 管理器内部采用 Array 管理对象池, 所以可以使用“位置” 以及 “名称” 查询。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 | *
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 | *
8 | * //ObjectPoolBuilder
15 | * @author Copyright (c) 2016 xujun
16 | */
17 | public class ObjectPoolBuilder
newCount = currCount * 2
70 | */
71 | public ObjectPool
76 | * newCount = currCount + addCount */
77 | public ObjectPoolLinear