├── assets ├── tile.png ├── benin.jpg ├── cancel.png ├── tile2.png ├── bionic_0.png ├── picture.png ├── picture2.png ├── background.jpg └── fps_images.png ├── res ├── raw │ ├── cheer.mp3 │ └── tileclick.mp3 ├── drawable-hdpi │ └── ic_launcher.png ├── drawable-mdpi │ └── ic_launcher.png ├── drawable-xhdpi │ └── ic_launcher.png ├── drawable-xxhdpi │ └── ic_launcher.png ├── values-sw600dp │ └── dimens.xml ├── values │ ├── dimens.xml │ ├── strings.xml │ └── styles.xml ├── menu │ └── main.xml ├── values-sw720dp-land │ └── dimens.xml └── layout │ └── activity_main.xml ├── ic_launcher-web.png ├── src ├── org │ └── cocos2d │ │ ├── types │ │ ├── CCPointSize.java │ │ ├── Copyable.java │ │ ├── ccVertex3F.java │ │ ├── CCVertex3D.java │ │ ├── ccV2F_C4F_T2F_Quad.java │ │ ├── ccPointSprite.java │ │ ├── ccV3F_C4B_T2F_Quad.java │ │ ├── util │ │ │ ├── ccQuad2Util.java │ │ │ ├── ccColor4FUtil.java │ │ │ └── CGAffineTransformUtil.java │ │ ├── ccVertex2F.java │ │ ├── ccTex2F.java │ │ ├── ccV3F_C4B_T2F.java │ │ ├── ccV2F_C4F_T2F.java │ │ ├── NoninvertibleTransformException.java │ │ ├── ccGridSize.java │ │ ├── ccBlendFunc.java │ │ ├── CCBezierConfig.java │ │ ├── CCTexParams.java │ │ ├── ccColor4B.java │ │ ├── CGSize.java │ │ ├── ccQuad2.java │ │ ├── ccQuad3.java │ │ ├── ccColor4F.java │ │ └── ccColor3B.java │ │ ├── actions │ │ ├── UpdateCallback.java │ │ ├── ease │ │ │ ├── CCEaseOut.java │ │ │ ├── CCEaseExponentialInOut.java │ │ │ ├── CCEaseIn.java │ │ │ ├── CCEaseSineOut.java │ │ │ ├── CCEaseSineIn.java │ │ │ ├── CCEaseSineInOut.java │ │ │ ├── CCEaseBounceOut.java │ │ │ ├── CCEaseBounceIn.java │ │ │ ├── CCEaseElastic.java │ │ │ ├── CCEaseBackIn.java │ │ │ ├── CCEaseExponentialOut.java │ │ │ ├── CCEaseExponentialIn.java │ │ │ ├── CCEaseBackOut.java │ │ │ ├── CCEaseBounce.java │ │ │ ├── CCEaseInOut.java │ │ │ ├── CCEaseBounceInOut.java │ │ │ ├── CCEaseRateAction.java │ │ │ ├── CCEaseBackInOut.java │ │ │ ├── CCEaseElasticOut.java │ │ │ ├── CCEaseElasticIn.java │ │ │ ├── CCEaseAction.java │ │ │ └── CCEaseElasticInOut.java │ │ ├── instant │ │ │ ├── CCToggleVisibility.java │ │ │ ├── CCHide.java │ │ │ ├── CCShow.java │ │ │ ├── CCCallFuncN.java │ │ │ ├── CCPlace.java │ │ │ ├── CCInstantAction.java │ │ │ ├── CCFlipX.java │ │ │ ├── CCFlipY.java │ │ │ ├── CCCallFuncND.java │ │ │ └── CCCallFunc.java │ │ ├── interval │ │ │ ├── CCDelayTime.java │ │ │ ├── CCSkewBy.java │ │ │ ├── CCFadeIn.java │ │ │ ├── CCFadeOut.java │ │ │ ├── CCBlink.java │ │ │ ├── CCJumpTo.java │ │ │ ├── CCMoveBy.java │ │ │ ├── CCScaleBy.java │ │ │ ├── CCRotateBy.java │ │ │ ├── CCFadeTo.java │ │ │ ├── CCProgressTo.java │ │ │ ├── CCProgressFromTo.java │ │ │ ├── CCTintTo.java │ │ │ ├── CCReverseTime.java │ │ │ ├── CCRotateTo.java │ │ │ ├── CCTintBy.java │ │ │ ├── CCMoveTo.java │ │ │ ├── CCSkewTo.java │ │ │ ├── CCJumpBy.java │ │ │ ├── CCScaleTo.java │ │ │ ├── CCSpawn.java │ │ │ ├── CCBezierTo.java │ │ │ └── CCBezierBy.java │ │ ├── tile │ │ │ ├── Tile.java │ │ │ ├── CCFadeOutDownTiles.java │ │ │ ├── CCFadeOutBLTiles.java │ │ │ ├── CCFadeOutUpTiles.java │ │ │ ├── CCTiledGrid3DAction.java │ │ │ ├── CCSplitRows.java │ │ │ ├── CCSplitCols.java │ │ │ ├── CCWavesTiles3D.java │ │ │ └── CCJumpTiles3D.java │ │ ├── grid │ │ │ ├── CCStopGrid.java │ │ │ ├── CCReuseGrid.java │ │ │ ├── CCWaves3D.java │ │ │ ├── CCAccelAmplitude.java │ │ │ ├── CCDeccelAmplitude.java │ │ │ ├── CCAccelDeccelAmplitude.java │ │ │ ├── CCShaky3D.java │ │ │ ├── CCLiquid.java │ │ │ ├── CCGrid3DAction.java │ │ │ ├── CCWaves.java │ │ │ ├── CCRipple3D.java │ │ │ ├── CCTwirl.java │ │ │ ├── CCGridAction.java │ │ │ ├── CCLens3D.java │ │ │ └── CCFlipY3D.java │ │ ├── base │ │ │ ├── CCFiniteTimeAction.java │ │ │ ├── CCRepeatForever.java │ │ │ └── CCSpeed.java │ │ └── camera │ │ │ └── CCCameraAction.java │ │ ├── protocols │ │ ├── CCMotionEventProtocol.java │ │ ├── CCLabelProtocol.java │ │ ├── CCKeyDelegateProtocol.java │ │ ├── CCBlendProtocol.java │ │ ├── CCTextureProtocol.java │ │ ├── CCTouchDelegateProtocol.java │ │ └── CCRGBAProtocol.java │ │ ├── opengl │ │ ├── OpenGLViewCantInitException.java │ │ ├── OpenGLViewCantDetachException.java │ │ ├── OpenGLViewCantAttachException.java │ │ ├── OpenGLViewNotAttachedException.java │ │ └── OpenGLViewAlreadyAttachedException.java │ │ ├── extensions │ │ └── scroll │ │ │ ├── CCScrollViewDelegate.java │ │ │ ├── CCTableViewCell.java │ │ │ ├── CCTableViewDelegate.java │ │ │ ├── CCTableViewSpriteCell.java │ │ │ └── CCTableViewDataSource.java │ │ ├── utils │ │ ├── Util5.java │ │ ├── pool │ │ │ ├── ConcOneClassPool.java │ │ │ ├── OneClassPool.java │ │ │ └── ObjectPool.java │ │ ├── CCFormatter.java │ │ ├── BufferUtils.java │ │ ├── Util7.java │ │ ├── collections │ │ │ └── ConcArrayStack.java │ │ ├── GeometryUtil.java │ │ ├── TransformUtils.java │ │ └── ContentHelper.java │ │ ├── transitions │ │ ├── CCTransitionEaseScene.java │ │ ├── CCSplitRowsTransition.java │ │ ├── CCFadeUpTransition.java │ │ ├── CCRadialCWTransition.java │ │ ├── CCFadeBLTransition.java │ │ ├── CCFadeDownTransition.java │ │ ├── CCMoveInRTransition.java │ │ ├── CCMoveInTTransition.java │ │ ├── CCMoveInBTransition.java │ │ ├── CCOrientedTransitionScene.java │ │ ├── CCSlideInBTransition.java │ │ ├── CCSlideInTTransition.java │ │ ├── CCSlideInRTransition.java │ │ ├── CCShrinkGrowTransition.java │ │ ├── CCRotoZoomTransition.java │ │ ├── CCSplitColsTransition.java │ │ ├── CCTurnOffTilesTransition.java │ │ ├── CCMoveInLTransition.java │ │ ├── CCFadeTRTransition.java │ │ ├── CCJumpZoomTransition.java │ │ ├── CCFlipXTransition.java │ │ ├── CCFlipYTransition.java │ │ └── CCFlipAngularTransition.java │ │ ├── events │ │ ├── CCTargetedTouchHandler.java │ │ └── CCKeyHandler.java │ │ ├── layers │ │ ├── CCScene.java │ │ ├── CCTMXLayerInfo.java │ │ ├── CCTMXTilesetInfo.java │ │ ├── CCTMXObjectGroup.java │ │ └── CCMultiplexLayer.java │ │ └── menus │ │ ├── CCMenuItemAtlasFont.java │ │ ├── CCMenuItemFont.java │ │ └── CCMenuItemImage.java └── com │ └── example │ └── puzzlegame │ └── CCNodeExt.java ├── gen └── com │ └── example │ └── puzzlegame │ ├── BuildConfig.java │ └── R.java ├── .gitattributes ├── project.properties ├── proguard-project.txt ├── README.md └── AndroidManifest.xml /assets/tile.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/victordibia/PuzzleGame/HEAD/assets/tile.png -------------------------------------------------------------------------------- /assets/benin.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/victordibia/PuzzleGame/HEAD/assets/benin.jpg -------------------------------------------------------------------------------- /assets/cancel.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/victordibia/PuzzleGame/HEAD/assets/cancel.png -------------------------------------------------------------------------------- /assets/tile2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/victordibia/PuzzleGame/HEAD/assets/tile2.png -------------------------------------------------------------------------------- /res/raw/cheer.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/victordibia/PuzzleGame/HEAD/res/raw/cheer.mp3 -------------------------------------------------------------------------------- /assets/bionic_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/victordibia/PuzzleGame/HEAD/assets/bionic_0.png -------------------------------------------------------------------------------- /assets/picture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/victordibia/PuzzleGame/HEAD/assets/picture.png -------------------------------------------------------------------------------- /assets/picture2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/victordibia/PuzzleGame/HEAD/assets/picture2.png -------------------------------------------------------------------------------- /ic_launcher-web.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/victordibia/PuzzleGame/HEAD/ic_launcher-web.png -------------------------------------------------------------------------------- /assets/background.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/victordibia/PuzzleGame/HEAD/assets/background.jpg -------------------------------------------------------------------------------- /assets/fps_images.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/victordibia/PuzzleGame/HEAD/assets/fps_images.png -------------------------------------------------------------------------------- /res/raw/tileclick.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/victordibia/PuzzleGame/HEAD/res/raw/tileclick.mp3 -------------------------------------------------------------------------------- /res/drawable-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/victordibia/PuzzleGame/HEAD/res/drawable-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /res/drawable-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/victordibia/PuzzleGame/HEAD/res/drawable-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /res/drawable-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/victordibia/PuzzleGame/HEAD/res/drawable-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /res/drawable-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/victordibia/PuzzleGame/HEAD/res/drawable-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /src/org/cocos2d/types/CCPointSize.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.types; 2 | 3 | public class CCPointSize { 4 | public float size; 5 | } 6 | -------------------------------------------------------------------------------- /src/org/cocos2d/types/Copyable.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.types; 2 | 3 | public interface Copyable { 4 | public Object copy(); 5 | } 6 | -------------------------------------------------------------------------------- /src/org/cocos2d/actions/UpdateCallback.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.actions; 2 | 3 | public interface UpdateCallback { 4 | void update(float d); 5 | } 6 | -------------------------------------------------------------------------------- /src/org/cocos2d/protocols/CCMotionEventProtocol.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.protocols; 2 | 3 | import android.view.MotionEvent; 4 | 5 | public interface CCMotionEventProtocol 6 | { 7 | void onTouch(MotionEvent e); 8 | } 9 | -------------------------------------------------------------------------------- /gen/com/example/puzzlegame/BuildConfig.java: -------------------------------------------------------------------------------- 1 | /** Automatically generated file. DO NOT MODIFY */ 2 | package com.example.puzzlegame; 3 | 4 | public final class BuildConfig { 5 | public final static boolean DEBUG = true; 6 | } -------------------------------------------------------------------------------- /src/org/cocos2d/opengl/OpenGLViewCantInitException.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.opengl; 2 | 3 | public class OpenGLViewCantInitException extends Exception { 4 | public OpenGLViewCantInitException(String reason) { 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /src/org/cocos2d/opengl/OpenGLViewCantDetachException.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.opengl; 2 | 3 | public class OpenGLViewCantDetachException extends Exception { 4 | public OpenGLViewCantDetachException(String reason) { 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /src/org/cocos2d/types/ccVertex3F.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.types; 2 | 3 | /** A vertex composed of 3 floats: x, y, z 4 | @since v0.8 5 | */ 6 | public class ccVertex3F { 7 | float x; 8 | float y; 9 | float z; 10 | } 11 | 12 | -------------------------------------------------------------------------------- /res/values-sw600dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 16dp 5 | 16dp 6 | 7 | 8 | -------------------------------------------------------------------------------- /res/menu/main.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /src/org/cocos2d/opengl/OpenGLViewCantAttachException.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.opengl; 2 | 3 | public class OpenGLViewCantAttachException extends Exception { 4 | public OpenGLViewCantAttachException(String reason) { 5 | super(reason); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /src/org/cocos2d/opengl/OpenGLViewNotAttachedException.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.opengl; 2 | 3 | public class OpenGLViewNotAttachedException extends Exception { 4 | public OpenGLViewNotAttachedException(String reason) { 5 | super(reason); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | PuzzleGame 5 | Settings 6 | Hello world! 7 | 8 | 9 | -------------------------------------------------------------------------------- /src/org/cocos2d/protocols/CCLabelProtocol.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.protocols; 2 | 3 | /** Common interface for Labels */ 4 | public interface CCLabelProtocol { 5 | /** sets a new label using an NSString */ 6 | public void setString(CharSequence label); 7 | } 8 | 9 | -------------------------------------------------------------------------------- /src/org/cocos2d/opengl/OpenGLViewAlreadyAttachedException.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.opengl; 2 | 3 | public class OpenGLViewAlreadyAttachedException extends Exception { 4 | public OpenGLViewAlreadyAttachedException(String reason) { 5 | super(reason); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /res/values-sw720dp-land/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 128dp 8 | 9 | 10 | -------------------------------------------------------------------------------- /src/org/cocos2d/protocols/CCKeyDelegateProtocol.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.protocols; 2 | 3 | import android.view.KeyEvent; 4 | 5 | /* 6 | 7 | */ 8 | public interface CCKeyDelegateProtocol { 9 | public boolean ccKeyDown(int keyCode, KeyEvent event); 10 | public boolean ccKeyUp(int keyCode, KeyEvent event); 11 | } 12 | //+1-954-919-2120 13 | -------------------------------------------------------------------------------- /src/org/cocos2d/types/CCVertex3D.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.types; 2 | 3 | 4 | //! A 3D vertex 5 | public class CCVertex3D { 6 | public float x; 7 | public float y; 8 | public float z; 9 | 10 | public CCVertex3D(float x, float y, float z) { 11 | this.x = x; 12 | this.y = y; 13 | this.z = z; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/org/cocos2d/types/ccV2F_C4F_T2F_Quad.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.types; 2 | 3 | //! 4 ccVertex2FTex2FColor4F Quad 4 | class ccV2F_C4F_T2F_Quad { 5 | //! bottom left 6 | ccV2F_C4F_T2F bl; 7 | //! bottom right 8 | ccV2F_C4F_T2F br; 9 | //! top left 10 | ccV2F_C4F_T2F tl; 11 | //! top right 12 | ccV2F_C4F_T2F tr; 13 | } 14 | 15 | -------------------------------------------------------------------------------- /src/org/cocos2d/types/ccPointSprite.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.types; 2 | 3 | public class ccPointSprite { 4 | public float x; 5 | public float y; 6 | // public float size; /// size is not supported via this way, implement it separately 7 | public ccColor4F colors = new ccColor4F(); 8 | 9 | public static final int spriteSize = 6; 10 | } 11 | -------------------------------------------------------------------------------- /src/org/cocos2d/types/ccV3F_C4B_T2F_Quad.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.types; 2 | 3 | //! 4 ccVertex3FTex2FColor4B 4 | public class ccV3F_C4B_T2F_Quad { 5 | //! top left 6 | ccV3F_C4B_T2F tl; 7 | //! bottom left 8 | ccV3F_C4B_T2F bl; 9 | //! top right 10 | ccV3F_C4B_T2F tr; 11 | //! bottom right 12 | ccV3F_C4B_T2F br; 13 | } 14 | 15 | -------------------------------------------------------------------------------- /src/org/cocos2d/types/util/ccQuad2Util.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.types.util; 2 | 3 | import org.cocos2d.types.ccQuad2; 4 | 5 | public final class ccQuad2Util { 6 | public static void zero(ccQuad2 q) { 7 | q.bl_x = 0; 8 | q.bl_y = 0; 9 | q.br_x = 0; 10 | q.br_y = 0; 11 | q.tl_x = 0; 12 | q.tl_y = 0; 13 | q.tr_x = 0; 14 | q.tr_y = 0; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/org/cocos2d/extensions/scroll/CCScrollViewDelegate.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Port from SWScrollView and SWTableView for iphone 3 | * by Rodrigo Collavo on 02/03/2012 4 | */ 5 | 6 | package org.cocos2d.extensions.scroll; 7 | 8 | public interface CCScrollViewDelegate { 9 | public void scrollViewDidScroll(CCScrollView view); 10 | public void scrollViewDidZoom(CCScrollView view); 11 | } 12 | -------------------------------------------------------------------------------- /src/org/cocos2d/types/ccVertex2F.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.types; 2 | 3 | /** A vertex composed of 2 floats: x, y 4 | @since v0.8 5 | */ 6 | public class ccVertex2F { 7 | CGPoint pnt; 8 | 9 | public ccVertex2F() { 10 | pnt = CGPoint.zero(); 11 | } 12 | 13 | public void setCGPoint(CGPoint p) { 14 | pnt = CGPoint.make(p.x, p.y); 15 | } 16 | } 17 | 18 | -------------------------------------------------------------------------------- /src/org/cocos2d/types/ccTex2F.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.types; 2 | 3 | /** A texcoord composed of 2 floats: u, y 4 | @since v0.8 5 | */ 6 | public class ccTex2F { 7 | public float u; 8 | public float v; 9 | 10 | public ccTex2F(float uf, float vf){ 11 | u = uf; 12 | v = vf; 13 | } 14 | 15 | public float[] toFloatArray() { 16 | return new float[] {u, v}; 17 | } 18 | } 19 | 20 | -------------------------------------------------------------------------------- /src/org/cocos2d/types/ccV3F_C4B_T2F.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.types; 2 | 3 | //! a Point with a vertex point, a tex coord point and a color 4B 4 | class ccV3F_C4B_T2F { 5 | //! vertices (3F) 6 | ccVertex3F vertices; // 12 bytes 7 | // char __padding__[4]; 8 | 9 | //! colors (4B) 10 | ccColor4B colors; // 4 bytes 11 | // char __padding2__[4]; 12 | 13 | // tex coords (2F) 14 | ccTex2F texCoords; // 8 byts 15 | } 16 | 17 | -------------------------------------------------------------------------------- /src/org/cocos2d/utils/Util5.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.utils; 2 | 3 | import android.view.MotionEvent; 4 | 5 | public class Util5 { 6 | public static int getPointerId(MotionEvent event, int pindex) { 7 | return event.getPointerId(pindex); 8 | } 9 | 10 | public static float getX(MotionEvent event, int pindex) { 11 | return event.getX(pindex); 12 | } 13 | 14 | public static float getY(MotionEvent event, int pindex) { 15 | return event.getY(pindex); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/org/cocos2d/protocols/CCBlendProtocol.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.protocols; 2 | 3 | import org.cocos2d.types.ccBlendFunc; 4 | 5 | /** 6 | You can specify the blending fuction. 7 | @since v0.99.0 8 | */ 9 | public interface CCBlendProtocol { 10 | /** set the source blending function for the texture */ 11 | public void setBlendFunc(ccBlendFunc blendFunc); 12 | 13 | /** returns the blending function used for the texture */ 14 | public ccBlendFunc getBlendFunc(); 15 | } 16 | -------------------------------------------------------------------------------- /src/org/cocos2d/transitions/CCTransitionEaseScene.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.transitions; 2 | 3 | import org.cocos2d.actions.interval.CCIntervalAction; 4 | 5 | /** CCTransitionEaseScene can ease the actions of the scene protocol. 6 | @since v0.8.2 7 | */ 8 | public interface CCTransitionEaseScene { 9 | /** returns the Ease action that will be performed on a linear action. 10 | @since v0.8.2 11 | */ 12 | public CCIntervalAction easeAction(CCIntervalAction action); 13 | } 14 | -------------------------------------------------------------------------------- /src/org/cocos2d/types/util/ccColor4FUtil.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.types.util; 2 | 3 | import org.cocos2d.types.ccColor4F; 4 | 5 | public final class ccColor4FUtil { 6 | 7 | public static void copy(ccColor4F src, ccColor4F dst) { 8 | dst.a = src.a; 9 | dst.r = src.r; 10 | dst.g = src.g; 11 | dst.b = src.b; 12 | } 13 | 14 | public static void set(ccColor4F dst, float r, float g, float b, float a) { 15 | dst.a = a; 16 | dst.r = r; 17 | dst.g = g; 18 | dst.b = b; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/org/cocos2d/types/ccV2F_C4F_T2F.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.types; 2 | 3 | //! a Point with a vertex point, a tex coord point and a color 4F 4 | public class ccV2F_C4F_T2F { 5 | //! vertices (2F) 6 | public CGPoint vertices; 7 | //! colors (4F) 8 | public ccColor4F colors; 9 | //! tex coords (2F) 10 | public ccTex2F texCoords; 11 | 12 | public ccV2F_C4F_T2F() { 13 | vertices = CGPoint.zero(); 14 | colors = new ccColor4F(); 15 | texCoords = new ccTex2F(0, 0); 16 | } 17 | } 18 | 19 | -------------------------------------------------------------------------------- /src/org/cocos2d/types/NoninvertibleTransformException.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.types; 2 | 3 | public class NoninvertibleTransformException extends java.lang.Exception { 4 | 5 | /** 6 | * The Constant serialVersionUID. 7 | */ 8 | private static final long serialVersionUID = 6137225240503990466L; 9 | 10 | /** 11 | * Instantiates a new non-invertible transform exception. 12 | * 13 | * @param s the error message. 14 | */ 15 | public NoninvertibleTransformException(String s) { 16 | super(s); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /src/org/cocos2d/types/ccGridSize.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.types; 2 | 3 | //! A 2D grid_ size 4 | public class ccGridSize { 5 | public int x; 6 | public int y; 7 | 8 | //! helper function to create a ccGridSize 9 | public static ccGridSize ccg(final int x, final int y) { 10 | return new ccGridSize(x, y); 11 | } 12 | 13 | public ccGridSize(int x, int y) { 14 | this.x = x; 15 | this.y = y; 16 | } 17 | 18 | public ccGridSize(ccGridSize gs) { 19 | this.x = gs.x; 20 | this.y = gs.y; 21 | } 22 | } 23 | 24 | -------------------------------------------------------------------------------- /src/org/cocos2d/extensions/scroll/CCTableViewCell.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Port from SWScrollView and SWTableView for iphone 3 | * by Rodrigo Collavo on 02/03/2012 4 | */ 5 | 6 | package org.cocos2d.extensions.scroll; 7 | 8 | import org.cocos2d.nodes.CCNode; 9 | 10 | public class CCTableViewCell extends CCNode { 11 | private int m_idx; 12 | 13 | public void reset() { 14 | m_idx = Integer.MAX_VALUE; 15 | } 16 | 17 | public void setObjectID(int i) { 18 | m_idx = i; 19 | } 20 | 21 | public int getObjectID() { 22 | return m_idx; 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | *.sln merge=union 7 | *.csproj merge=union 8 | *.vbproj merge=union 9 | *.fsproj merge=union 10 | *.dbproj merge=union 11 | 12 | # Standard to msysgit 13 | *.doc diff=astextplain 14 | *.DOC diff=astextplain 15 | *.docx diff=astextplain 16 | *.DOCX diff=astextplain 17 | *.dot diff=astextplain 18 | *.DOT diff=astextplain 19 | *.pdf diff=astextplain 20 | *.PDF diff=astextplain 21 | *.rtf diff=astextplain 22 | *.RTF diff=astextplain 23 | -------------------------------------------------------------------------------- /src/com/example/puzzlegame/CCNodeExt.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Author: Victor Dibia 4 | * Date last modified: Feb 10, 2014 5 | * Model tiles with extra field NodeText 6 | */ 7 | 8 | package com.example.puzzlegame; 9 | 10 | import org.cocos2d.nodes.CCNode; 11 | 12 | public class CCNodeExt extends CCNode{ 13 | public String nodeText ; 14 | 15 | public CCNodeExt(){ 16 | super(); 17 | 18 | } 19 | 20 | public void setNodeText(String nText){ 21 | this.nodeText = nText; 22 | } 23 | 24 | public String getNodeText(){ 25 | return this.nodeText ; 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/org/cocos2d/utils/pool/ConcOneClassPool.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.utils.pool; 2 | 3 | import org.cocos2d.utils.collections.ConcNodeCachingStack; 4 | 5 | public abstract class ConcOneClassPool { 6 | private ConcNodeCachingStack objs; 7 | 8 | public ConcOneClassPool() { 9 | objs = new ConcNodeCachingStack(); 10 | } 11 | 12 | protected abstract T allocate(); 13 | 14 | public T get() { 15 | T ret = objs.pop(); 16 | if(null == ret) { 17 | ret = allocate(); 18 | } 19 | 20 | return ret; 21 | } 22 | 23 | public void free(T obj) { 24 | objs.push(obj); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/org/cocos2d/actions/ease/CCEaseOut.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.actions.ease; 2 | 3 | import org.cocos2d.actions.interval.CCIntervalAction; 4 | 5 | 6 | public class CCEaseOut extends CCEaseRateAction { 7 | 8 | public static CCEaseOut action(CCIntervalAction action, float rate) { 9 | return new CCEaseOut(action, rate); 10 | } 11 | 12 | protected CCEaseOut(CCIntervalAction action, float rate) { 13 | super(action, rate); 14 | } 15 | 16 | @Override 17 | public void update(float t) { 18 | other.update((float) Math.pow(t, 1 / rate)); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /src/org/cocos2d/extensions/scroll/CCTableViewDelegate.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Port from SWScrollView and SWTableView for iphone 3 | * by Rodrigo Collavo on 02/03/2012 4 | */ 5 | 6 | package org.cocos2d.extensions.scroll; 7 | 8 | /** 9 | * Sole purpose of this delegate is to single touch event in this version. 10 | */ 11 | public interface CCTableViewDelegate { 12 | /** 13 | * Delegate to respond touch event 14 | * 15 | * @param table table contains the given cell 16 | * @param cell cell that is touched 17 | */ 18 | public void tableCellTouched(CCTableView table, CCTableViewCell cell); 19 | } 20 | -------------------------------------------------------------------------------- /project.properties: -------------------------------------------------------------------------------- 1 | # This file is automatically generated by Android Tools. 2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED! 3 | # 4 | # This file must be checked in Version Control Systems. 5 | # 6 | # To customize properties used by the Ant build system edit 7 | # "ant.properties", and override values to adapt the script to your 8 | # project structure. 9 | # 10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): 11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt 12 | 13 | # Project target. 14 | target=android-8 15 | -------------------------------------------------------------------------------- /src/org/cocos2d/transitions/CCSplitRowsTransition.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.transitions; 2 | 3 | import org.cocos2d.actions.interval.CCIntervalAction; 4 | import org.cocos2d.actions.tile.CCSplitRows; 5 | import org.cocos2d.layers.CCScene; 6 | 7 | /** 8 | * SplitRows Transition. 9 | * The odd rows goes to the left while the even rows goes to the right. 10 | */ 11 | public class CCSplitRowsTransition extends CCSplitColsTransition { 12 | 13 | public CCSplitRowsTransition(float t, CCScene s) { 14 | super(t, s); 15 | } 16 | 17 | protected CCIntervalAction action() { 18 | return CCSplitRows.action(3, duration/2.0f); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/org/cocos2d/actions/instant/CCToggleVisibility.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.actions.instant; 2 | 3 | import org.cocos2d.nodes.CCNode; 4 | 5 | /** 6 | * Toggles the visibility of a node 7 | */ 8 | public class CCToggleVisibility extends CCInstantAction { 9 | 10 | public static CCToggleVisibility action() { 11 | return new CCToggleVisibility(); 12 | } 13 | 14 | @Override 15 | public CCToggleVisibility copy() { 16 | return new CCToggleVisibility(); 17 | } 18 | 19 | @Override 20 | public void start(CCNode aTarget) { 21 | super.start(aTarget); 22 | target.setVisible(!target.getVisible()); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/org/cocos2d/utils/CCFormatter.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.utils; 2 | 3 | import java.util.Formatter; 4 | 5 | public class CCFormatter { 6 | private static StringBuilder sb = new StringBuilder(50); 7 | private static Formatter formatter = new Formatter(sb); 8 | 9 | public synchronized static String format(String s, Object... objects) { 10 | sb.setLength(0); 11 | formatter.format(s, objects); 12 | return sb.toString(); 13 | } 14 | 15 | public final static int swapIntToLittleEndian(int v) { 16 | return (v >>> 24) | (v << 24) | 17 | ((v << 8) & 0x00FF0000) | ((v >> 8) & 0x0000FF00); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/org/cocos2d/utils/BufferUtils.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.utils; 2 | 3 | import java.nio.ByteBuffer; 4 | import java.nio.FloatBuffer; 5 | 6 | import android.os.Build; 7 | 8 | public class BufferUtils { 9 | /** 10 | * Copy with JNI for devices prior GINGERBREAD(api 9), put for newer versions(HTC Sensation has faster put(float[]) ) 11 | */ 12 | public static void copyFloats(float[] src, int srcOffset, FloatBuffer dst, int numElements) { 13 | if(Build.VERSION.SDK_INT >= 9) { 14 | dst.put(src, srcOffset, numElements); 15 | } else { 16 | //com.badlogic.gdx.utils.BufferUtils.copy(src, srcOffset, dst, numElements); 17 | 18 | 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/org/cocos2d/transitions/CCFadeUpTransition.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.transitions; 2 | 3 | import org.cocos2d.actions.interval.CCIntervalAction; 4 | import org.cocos2d.actions.tile.CCFadeOutUpTiles; 5 | import org.cocos2d.layers.CCScene; 6 | import org.cocos2d.types.ccGridSize; 7 | 8 | /** 9 | * FadeUp Transition. 10 | * Fade the tiles of the outgoing scene from the bottom to the top. 11 | */ 12 | public class CCFadeUpTransition extends CCFadeTRTransition { 13 | 14 | public CCFadeUpTransition(float t, CCScene s) { 15 | super(t, s); 16 | } 17 | 18 | protected CCIntervalAction action(ccGridSize v) { 19 | return CCFadeOutUpTiles.action(v, duration); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/org/cocos2d/transitions/CCRadialCWTransition.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.transitions; 2 | 3 | import org.cocos2d.actions.CCProgressTimer; 4 | import org.cocos2d.layers.CCScene; 5 | 6 | /// 7 | // A counter colock-wise radial transition to the next scene 8 | /// 9 | public class CCRadialCWTransition extends CCRadialCCWTransition { 10 | 11 | public static CCRadialCWTransition transition(float t, CCScene s) { 12 | return new CCRadialCWTransition(t, s); 13 | } 14 | 15 | protected CCRadialCWTransition(float t, CCScene s) { 16 | super(t, s); 17 | } 18 | 19 | @Override 20 | public int radialType() { 21 | return CCProgressTimer.kCCProgressTimerTypeRadialCW; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/org/cocos2d/utils/Util7.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.utils; 2 | 3 | import org.cocos2d.nodes.CCDirector; 4 | 5 | import android.content.pm.PackageManager; 6 | 7 | /** 8 | * Methods are available in 2.1 and above only. 9 | */ 10 | public class Util7 { 11 | 12 | /** 13 | * using: 14 | * if(Build.VERSION.SDK_INT >= 7) { 15 | supportsMultiTouch = Util7.isMultiTouchSupported(); 16 | } 17 | */ 18 | public static boolean isMultiTouchSupported() { 19 | try { 20 | return CCDirector.sharedDirector().getActivity().getPackageManager().hasSystemFeature(PackageManager.FEATURE_TOUCHSCREEN_MULTITOUCH); 21 | } catch(Exception e) { } 22 | return false; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/org/cocos2d/utils/pool/OneClassPool.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.utils.pool; 2 | 3 | import java.util.ArrayList; 4 | 5 | public abstract class OneClassPool { 6 | private ArrayList objs; 7 | 8 | public OneClassPool() { 9 | objs = new ArrayList(); 10 | } 11 | 12 | protected abstract T allocate(); 13 | 14 | public T get() { 15 | int s = objs.size(); 16 | if(0 != s) { 17 | return objs.remove(s-1); 18 | } else { 19 | return allocate(); 20 | } 21 | } 22 | 23 | public void free(T obj) { 24 | objs.add(obj); 25 | } 26 | 27 | public int size() { 28 | return objs.size(); 29 | } 30 | 31 | public void clear() { 32 | objs.clear(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/org/cocos2d/transitions/CCFadeBLTransition.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.transitions; 2 | 3 | import org.cocos2d.actions.interval.CCIntervalAction; 4 | import org.cocos2d.actions.tile.CCFadeOutBLTiles; 5 | import org.cocos2d.layers.CCScene; 6 | import org.cocos2d.types.ccGridSize; 7 | 8 | /** 9 | * FadeBLTransition. 10 | * Fade the tiles of the outgoing scene from the top-right corner to the bottom-left corner. 11 | */ 12 | public class CCFadeBLTransition extends CCFadeTRTransition { 13 | 14 | public CCFadeBLTransition(float t, CCScene s) { 15 | super(t, s); 16 | } 17 | 18 | public CCIntervalAction action(ccGridSize v) { 19 | return CCFadeOutBLTiles.action(v, duration); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/org/cocos2d/actions/interval/CCDelayTime.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.actions.interval; 2 | 3 | /** 4 | * Delays the action a certain amount of seconds 5 | */ 6 | public class CCDelayTime extends CCIntervalAction { 7 | 8 | public static CCDelayTime action(float t) { 9 | return new CCDelayTime(t); 10 | } 11 | 12 | protected CCDelayTime(float t) { 13 | super(t); 14 | } 15 | 16 | @Override 17 | public CCDelayTime copy() { 18 | return new CCDelayTime(duration); 19 | } 20 | 21 | @Override 22 | public void update(float t) { 23 | } 24 | 25 | @Override 26 | public CCDelayTime reverse() { 27 | return new CCDelayTime(duration); 28 | } 29 | } 30 | 31 | -------------------------------------------------------------------------------- /src/org/cocos2d/transitions/CCFadeDownTransition.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.transitions; 2 | 3 | import org.cocos2d.actions.interval.CCIntervalAction; 4 | import org.cocos2d.actions.tile.CCFadeOutDownTiles; 5 | import org.cocos2d.layers.CCScene; 6 | import org.cocos2d.types.ccGridSize; 7 | 8 | /** 9 | * FadeDown Transition. 10 | * Fade the tiles of the outgoing scene from the top to the bottom. 11 | */ 12 | public class CCFadeDownTransition extends CCFadeTRTransition { 13 | 14 | public CCFadeDownTransition(float t, CCScene s) { 15 | super(t, s); 16 | } 17 | 18 | protected CCIntervalAction action(ccGridSize v) { 19 | return CCFadeOutDownTiles.action(v, duration); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/org/cocos2d/actions/instant/CCHide.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.actions.instant; 2 | 3 | import org.cocos2d.actions.base.CCFiniteTimeAction; 4 | import org.cocos2d.nodes.CCNode; 5 | 6 | /** 7 | * Hide the node 8 | */ 9 | public class CCHide extends CCInstantAction { 10 | 11 | public static CCHide action() { 12 | return new CCHide(); 13 | } 14 | 15 | @Override 16 | public CCHide copy() { 17 | return new CCHide(); 18 | } 19 | 20 | @Override 21 | public void start(CCNode aTarget) { 22 | super.start(aTarget); 23 | target.setVisible(false); 24 | } 25 | 26 | @Override 27 | public CCFiniteTimeAction reverse() { 28 | return new CCShow(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/org/cocos2d/actions/instant/CCShow.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.actions.instant; 2 | 3 | import org.cocos2d.actions.base.CCFiniteTimeAction; 4 | import org.cocos2d.nodes.CCNode; 5 | 6 | /** 7 | * Show the node 8 | */ 9 | public class CCShow extends CCInstantAction { 10 | 11 | public static CCShow action() { 12 | return new CCShow(); 13 | } 14 | 15 | @Override 16 | public CCShow copy() { 17 | return new CCShow(); 18 | } 19 | 20 | @Override 21 | public void start(CCNode aTarget) { 22 | super.start(aTarget); 23 | target.setVisible(true); 24 | } 25 | 26 | @Override 27 | public CCFiniteTimeAction reverse() { 28 | return new CCHide(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 10 | 11 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 14 | 15 | 16 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /src/org/cocos2d/utils/collections/ConcArrayStack.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.utils.collections; 2 | 3 | import java.util.ArrayList; 4 | import java.util.concurrent.locks.ReentrantLock; 5 | 6 | /** 7 | * Nonblocking stack, array based. 8 | * @author genius 9 | * 10 | */ 11 | public class ConcArrayStack { 12 | 13 | private ArrayList array = new ArrayList(); 14 | private final ReentrantLock lock = new ReentrantLock(); 15 | 16 | public void push(T obj) { 17 | lock.lock(); 18 | array.add(obj); 19 | lock.unlock(); 20 | } 21 | 22 | public T pop() { 23 | T ret = null; 24 | 25 | lock.lock(); 26 | 27 | int s = array.size(); 28 | if(s > 0) 29 | ret = array.remove( s-1 ); 30 | 31 | lock.unlock(); 32 | 33 | return ret; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/org/cocos2d/actions/ease/CCEaseExponentialInOut.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.actions.ease; 2 | 3 | import org.cocos2d.actions.interval.CCIntervalAction; 4 | 5 | public class CCEaseExponentialInOut extends CCEaseAction { 6 | 7 | public static CCEaseExponentialInOut action(CCIntervalAction action) { 8 | return new CCEaseExponentialInOut(action); 9 | } 10 | 11 | protected CCEaseExponentialInOut(CCIntervalAction action) { 12 | super(action); 13 | } 14 | 15 | @Override 16 | public void update(float t) { 17 | t /= 0.5f; 18 | if (t < 1) 19 | t = 0.5f * (float) Math.pow(2, 10 * (t - 1)); 20 | else 21 | t = 0.5f * (-(float) Math.pow(2, -10 * (t - 1) ) + 2); 22 | other.update(t); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/org/cocos2d/transitions/CCMoveInRTransition.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.transitions; 2 | 3 | import org.cocos2d.layers.CCScene; 4 | import org.cocos2d.nodes.CCDirector; 5 | 6 | /** 7 | * MoveInR Transition. 8 | * Move in from to the right the incoming scene. 9 | */ 10 | public class CCMoveInRTransition extends CCMoveInLTransition { 11 | 12 | public static CCMoveInRTransition transition(float t, CCScene s) { 13 | return new CCMoveInRTransition(t, s); 14 | } 15 | 16 | public CCMoveInRTransition(float t, CCScene s) { 17 | super(t, s); 18 | } 19 | 20 | /** 21 | * initializes the scenes 22 | */ 23 | @Override 24 | protected void initScenes() { 25 | inScene.setPosition(CCDirector.sharedDirector().winSize().width, 0); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/org/cocos2d/transitions/CCMoveInTTransition.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.transitions; 2 | 3 | import org.cocos2d.layers.CCScene; 4 | import org.cocos2d.nodes.CCDirector; 5 | 6 | /** 7 | * MoveInT Transition. 8 | * Move in from to the top the incoming scene. 9 | */ 10 | public class CCMoveInTTransition extends CCMoveInLTransition { 11 | 12 | public static CCMoveInTTransition transition(float t, CCScene s) { 13 | return new CCMoveInTTransition(t, s); 14 | } 15 | 16 | public CCMoveInTTransition(float t, CCScene s) { 17 | super(t, s); 18 | } 19 | 20 | /** 21 | * initializes the scenes 22 | */ 23 | @Override 24 | protected void initScenes() { 25 | inScene.setPosition(0, CCDirector.sharedDirector().winSize().height); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/org/cocos2d/protocols/CCTextureProtocol.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.protocols; 2 | 3 | import org.cocos2d.opengl.CCTexture2D; 4 | 5 | /** CCNode objects that uses a Texture2D to render the images. 6 | The texture can have a blending function. 7 | If the texture has alpha premultiplied the default blending function is: 8 | src=GL_ONE dst= GL_ONE_MINUS_SRC_ALPHA 9 | else 10 | src=GL_SRC_ALPHA dst= GL_ONE_MINUS_SRC_ALPHA 11 | But you can change the blending funtion at any time. 12 | @since v0.8.0 13 | */ 14 | 15 | public interface CCTextureProtocol extends CCBlendProtocol { 16 | /** returns the used texture */ 17 | public CCTexture2D getTexture(); 18 | 19 | /** sets a new texture. it will be retained */ 20 | public void setTexture(CCTexture2D texture); 21 | 22 | } 23 | 24 | -------------------------------------------------------------------------------- /src/org/cocos2d/actions/ease/CCEaseIn.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.actions.ease; 2 | 3 | import org.cocos2d.actions.interval.CCIntervalAction; 4 | 5 | 6 | public class CCEaseIn extends CCEaseRateAction { 7 | 8 | public static CCEaseIn action(CCIntervalAction action, float rate) { 9 | return new CCEaseIn(action, rate); 10 | } 11 | 12 | protected CCEaseIn(CCIntervalAction action, float rate) { 13 | super(action, rate); 14 | } 15 | 16 | @Override 17 | public CCEaseIn copy() { 18 | return new CCEaseIn(other.copy(), rate); 19 | } 20 | 21 | @Override 22 | public void update(float t) { 23 | other.update((float) Math.pow(t, rate)); 24 | } 25 | 26 | @Override 27 | public CCIntervalAction reverse() { 28 | return new CCEaseOut(other.reverse(), rate); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/org/cocos2d/actions/ease/CCEaseSineOut.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.actions.ease; 2 | 3 | import org.cocos2d.actions.interval.CCIntervalAction; 4 | 5 | public class CCEaseSineOut extends CCEaseAction { 6 | 7 | public static CCEaseSineOut action(CCIntervalAction action) { 8 | return new CCEaseSineOut(action); 9 | } 10 | 11 | protected CCEaseSineOut(CCIntervalAction action) { 12 | super(action); 13 | } 14 | 15 | @Override 16 | public CCEaseSineOut copy() { 17 | return new CCEaseSineOut(other.copy()); 18 | } 19 | 20 | @Override 21 | public void update(float t) { 22 | other.update((float)Math.sin(t * (float) Math.PI / 2)); 23 | } 24 | 25 | @Override 26 | public CCIntervalAction reverse() { 27 | return new CCEaseSineIn(other.reverse()); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /src/org/cocos2d/actions/interval/CCSkewBy.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.actions.interval; 2 | 3 | import org.cocos2d.nodes.CCNode; 4 | 5 | public class CCSkewBy extends CCSkewTo { 6 | 7 | private float skewX; 8 | private float skewY; 9 | 10 | public static CCSkewBy action(float t, float dx, float dy) { 11 | return new CCSkewBy(t, dx, dy); 12 | } 13 | 14 | protected CCSkewBy(float t, float dx, float dy) { 15 | super(t, dx, dy); 16 | skewX = dx; 17 | skewY = dy; 18 | } 19 | 20 | @Override 21 | public CCSkewBy copy() { 22 | return new CCSkewBy(duration, skewX, skewY); 23 | } 24 | 25 | @Override 26 | public void start(CCNode aTarget) { 27 | super.start(aTarget); 28 | 29 | deltaX = skewX; 30 | deltaY = skewY; 31 | 32 | endSkewX = startSkewX + deltaX; 33 | endSkewY = startSkewY + deltaY; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/org/cocos2d/actions/ease/CCEaseSineIn.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.actions.ease; 2 | 3 | import org.cocos2d.actions.interval.CCIntervalAction; 4 | 5 | public class CCEaseSineIn extends CCEaseAction { 6 | 7 | public static CCEaseSineIn action(CCIntervalAction action) { 8 | return new CCEaseSineIn(action); 9 | } 10 | 11 | protected CCEaseSineIn(CCIntervalAction action) { 12 | super(action); 13 | } 14 | 15 | @Override 16 | public CCEaseSineIn copy() { 17 | return new CCEaseSineIn(other.copy()); 18 | } 19 | 20 | @Override 21 | public void update(float t) { 22 | other.update(-1 * (float)Math.cos(t * (float) Math.PI / 2) + 1); 23 | } 24 | 25 | @Override 26 | public CCIntervalAction reverse() { 27 | return new CCEaseSineOut(other.reverse()); 28 | } 29 | 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/org/cocos2d/transitions/CCMoveInBTransition.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.transitions; 2 | 3 | import org.cocos2d.layers.CCScene; 4 | import org.cocos2d.nodes.CCDirector; 5 | import org.cocos2d.types.CGSize; 6 | 7 | /** 8 | * MoveInB Transition. 9 | * Move in from to the bottom the incoming scene. 10 | */ 11 | public class CCMoveInBTransition extends CCMoveInLTransition { 12 | 13 | public static CCMoveInBTransition transition(float t, CCScene s) { 14 | return new CCMoveInBTransition(t, s); 15 | } 16 | 17 | public CCMoveInBTransition(float t, CCScene s) { 18 | super(t, s); 19 | } 20 | 21 | /** 22 | * initializes the scenes 23 | */ 24 | protected void initScenes() { 25 | CGSize s = CCDirector.sharedDirector().winSize(); 26 | inScene.setPosition(0, -s.height); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/org/cocos2d/transitions/CCOrientedTransitionScene.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.transitions; 2 | 3 | import org.cocos2d.layers.CCScene; 4 | 5 | /** 6 | * A Transition that supports orientation like. 7 | * Possible orientation: LeftOver, RightOver, UpOver, DownOver 8 | */ 9 | public class CCOrientedTransitionScene extends CCTransitionScene { 10 | int orientation; 11 | 12 | /** creates a base transition with duration and incoming scene */ 13 | public static CCOrientedTransitionScene transition(float t, CCScene s, int o) { 14 | return new CCOrientedTransitionScene(t, s, o); 15 | } 16 | 17 | /** 18 | * initializes a transition with duration and incoming scene 19 | */ 20 | protected CCOrientedTransitionScene(float t, CCScene s, int o) { 21 | super(t, s); 22 | orientation = o; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/org/cocos2d/types/ccBlendFunc.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.types; 2 | 3 | //! Blend Function used for textures 4 | public class ccBlendFunc { 5 | //! source blend function 6 | public int src; 7 | //! destination blend function 8 | public int dst; 9 | 10 | public ccBlendFunc(int s, int d) { 11 | src = s; 12 | dst = d; 13 | } 14 | 15 | public ccBlendFunc() { 16 | src = dst = 0; 17 | } 18 | 19 | public void setSrc(int s) { 20 | src = s; 21 | } 22 | 23 | public int getSrc() { 24 | return src; 25 | } 26 | 27 | public void setDst(int d) { 28 | dst = d; 29 | } 30 | 31 | public int getDst() { 32 | return dst; 33 | } 34 | 35 | public String toString() { 36 | return "< src=" + src + ", dst=" + dst + " >"; 37 | } 38 | } 39 | 40 | -------------------------------------------------------------------------------- /src/org/cocos2d/actions/ease/CCEaseSineInOut.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.actions.ease; 2 | 3 | import org.cocos2d.actions.interval.CCIntervalAction; 4 | 5 | public class CCEaseSineInOut extends CCEaseAction { 6 | 7 | public static CCEaseSineInOut action(CCIntervalAction action) { 8 | return new CCEaseSineInOut(action); 9 | } 10 | 11 | protected CCEaseSineInOut(CCIntervalAction action) { 12 | super(action); 13 | } 14 | 15 | @Override 16 | public CCEaseSineInOut copy() { 17 | return new CCEaseSineInOut(other.copy()); 18 | } 19 | 20 | @Override 21 | public void update(float t) { 22 | other.update(-0.5f * ((float)Math.cos(Math.PI * t) - 1)); 23 | } 24 | 25 | @Override 26 | public CCIntervalAction reverse() { 27 | return new CCEaseSineInOut(other.reverse()); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /src/org/cocos2d/actions/tile/Tile.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.actions.tile; 2 | 3 | import org.cocos2d.types.CGPoint; 4 | import org.cocos2d.types.ccGridSize; 5 | 6 | public class Tile { 7 | CGPoint position; 8 | CGPoint startPosition; 9 | ccGridSize delta; 10 | 11 | public static Tile make(CGPoint pos, CGPoint startPos, ccGridSize gs) { 12 | return new Tile(pos, startPos, gs); 13 | } 14 | 15 | public static Tile make() { 16 | return new Tile(); 17 | } 18 | 19 | protected Tile(CGPoint pos, CGPoint startPos, ccGridSize gs) { 20 | position = CGPoint.make(pos.x, pos.y); 21 | startPosition = CGPoint.make(startPos.x, startPos.y); 22 | delta = ccGridSize.ccg(gs.x, gs.y); 23 | } 24 | 25 | protected Tile() { 26 | // warning: all members are not initialized 27 | } 28 | } 29 | 30 | -------------------------------------------------------------------------------- /src/org/cocos2d/actions/instant/CCCallFuncN.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.actions.instant; 2 | 3 | /** 4 | * Calls a 'callback' with the node as the first argument 5 | * N means Node 6 | */ 7 | public class CCCallFuncN extends CCCallFunc { 8 | 9 | public static CCCallFuncN action(Object t, String s) { 10 | return new CCCallFuncN(t, s, new Class[] { Object.class }); 11 | } 12 | 13 | /** 14 | * creates the action with the callback 15 | * @param classes 16 | */ 17 | protected CCCallFuncN(Object t, String s, Class[] p) { 18 | super(t, s, p); 19 | } 20 | 21 | /** 22 | * executes the callback 23 | */ 24 | public void execute() { 25 | try { 26 | invocation.invoke(targetCallback, new Object[]{target}); 27 | } catch (Exception e) { 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/org/cocos2d/types/CCBezierConfig.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.types; 2 | 3 | /** bezier configuration structure 4 | */ 5 | public class CCBezierConfig { 6 | //! end position of the bezier 7 | public CGPoint endPosition; 8 | //! Bezier control point 1 9 | public CGPoint controlPoint_1; 10 | //! Bezier control point 2 11 | public CGPoint controlPoint_2; 12 | 13 | public CCBezierConfig() { 14 | 15 | } 16 | 17 | // Bezier cubic formula: 18 | // ((1 - t) + t)3 = 1 19 | // Expands to 20 | // (1 - t)3 + 3t(1-t)2 + 3t2(1 - t) + t3 = 1 21 | public static float bezierAt( float a, float b, float c, float d, float t) { 22 | return (float)(Math.pow(1-t,3) * a 23 | + 3*t*(Math.pow(1-t,2)) * b 24 | + 3*Math.pow(t,2)*(1-t) * c 25 | + Math.pow(t,3) * d); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/org/cocos2d/types/CCTexParams.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.types; 2 | 3 | public class CCTexParams { 4 | public int minFilter; 5 | public int magFilter; 6 | public int wrapS; 7 | public int wrapT; 8 | 9 | public CCTexParams(int min, int mag, int s, int t) { 10 | minFilter = min; 11 | magFilter = mag; 12 | wrapS = s; 13 | wrapT = t; 14 | } 15 | 16 | public CCTexParams copy() { 17 | return new CCTexParams(minFilter, magFilter, wrapS, wrapT); 18 | } 19 | 20 | public void set(int min, int mag, int s, int t) { 21 | minFilter = min; 22 | magFilter = mag; 23 | wrapS = s; 24 | wrapT = t; 25 | } 26 | 27 | public void set(CCTexParams texParams) { 28 | set(texParams.minFilter, texParams.magFilter, texParams.wrapS, texParams.wrapT); 29 | } 30 | } 31 | 32 | -------------------------------------------------------------------------------- /src/org/cocos2d/actions/ease/CCEaseBounceOut.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.actions.ease; 2 | 3 | import org.cocos2d.actions.interval.CCIntervalAction; 4 | 5 | public class CCEaseBounceOut extends CCEaseBounce { 6 | 7 | public static CCEaseBounceOut action(CCIntervalAction action) { 8 | return new CCEaseBounceOut(action); 9 | } 10 | 11 | protected CCEaseBounceOut(CCIntervalAction action) { 12 | super(action); 13 | } 14 | 15 | @Override 16 | public CCEaseAction copy() { 17 | return new CCEaseBounceOut(other.copy()); 18 | } 19 | 20 | @Override 21 | public void update(float t) { 22 | float newT = bounceTime(t); 23 | other.update(newT); 24 | } 25 | 26 | @Override 27 | public CCIntervalAction reverse() { 28 | return new CCEaseBounceIn(other.reverse()); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/org/cocos2d/actions/ease/CCEaseBounceIn.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.actions.ease; 2 | 3 | import org.cocos2d.actions.interval.CCIntervalAction; 4 | 5 | public class CCEaseBounceIn extends CCEaseBounce { 6 | 7 | public static CCEaseBounceIn action(CCIntervalAction action) { 8 | return new CCEaseBounceIn(action); 9 | } 10 | 11 | protected CCEaseBounceIn(CCIntervalAction action) { 12 | super(action); 13 | } 14 | 15 | @Override 16 | public CCEaseAction copy() { 17 | return new CCEaseBounceIn(other.copy()); 18 | } 19 | 20 | @Override 21 | public void update(float t) { 22 | float newT = 1 - bounceTime(1 - t); 23 | other.update(newT); 24 | } 25 | 26 | @Override 27 | public CCIntervalAction reverse() { 28 | return new CCEaseBounceOut(other.reverse()); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /proguard-project.txt: -------------------------------------------------------------------------------- 1 | # To enable ProGuard in your project, edit project.properties 2 | # to define the proguard.config property as described in that file. 3 | # 4 | # Add project specific ProGuard rules here. 5 | # By default, the flags in this file are appended to flags specified 6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt 7 | # You can edit the include path and order by changing the ProGuard 8 | # include property in project.properties. 9 | # 10 | # For more details, see 11 | # http://developer.android.com/guide/developing/tools/proguard.html 12 | 13 | # Add any project specific keep options here: 14 | 15 | # If your project uses WebView with JS, uncomment the following 16 | # and specify the fully qualified class name to the JavaScript interface 17 | # class: 18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 19 | # public *; 20 | #} 21 | -------------------------------------------------------------------------------- /src/org/cocos2d/actions/ease/CCEaseElastic.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.actions.ease; 2 | 3 | import org.cocos2d.actions.interval.CCIntervalAction; 4 | 5 | /** Ease Elastic abstract class 6 | @since v0.8.2 7 | */ 8 | public abstract class CCEaseElastic extends CCEaseAction { 9 | /** period of the wave in radians. default is 0.3 */ 10 | protected float period_; 11 | 12 | /** Initializes the action with the inner action 13 | * and the period in radians (default is 0.3) */ 14 | protected CCEaseElastic(CCIntervalAction action, float period) { 15 | super(action); 16 | period_ = period; 17 | } 18 | 19 | protected CCEaseElastic(CCIntervalAction action) { 20 | this(action, 0.3f); 21 | } 22 | 23 | @Override 24 | public abstract CCEaseAction copy(); 25 | 26 | @Override 27 | public abstract CCIntervalAction reverse(); 28 | } 29 | -------------------------------------------------------------------------------- /src/org/cocos2d/actions/ease/CCEaseBackIn.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.actions.ease; 2 | 3 | import org.cocos2d.actions.interval.CCIntervalAction; 4 | 5 | public class CCEaseBackIn extends CCEaseAction { 6 | 7 | public static CCEaseBackIn action(CCIntervalAction action) { 8 | return new CCEaseBackIn(action); 9 | } 10 | 11 | protected CCEaseBackIn(CCIntervalAction action) { 12 | super(action); 13 | } 14 | 15 | @Override 16 | public CCEaseAction copy() { 17 | return new CCEaseBackIn(other.copy()); 18 | } 19 | 20 | @Override 21 | public void update(float t) { 22 | float overshoot = 1.70158f; 23 | other.update(t * t * ((overshoot + 1) * t - overshoot)); 24 | } 25 | 26 | @Override 27 | public CCIntervalAction reverse() { 28 | return new CCEaseBackOut(other.reverse()); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/org/cocos2d/actions/grid/CCStopGrid.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.actions.grid; 2 | 3 | import org.cocos2d.actions.instant.CCInstantAction; 4 | import org.cocos2d.grid.CCGridBase; 5 | import org.cocos2d.nodes.CCNode; 6 | 7 | //////////////////////////////////////////////////////////// 8 | 9 | /** CCStopGrid action. 10 | Don't call this action if another grid action is active. 11 | Call if you want to remove the the grid effect. Example: 12 | [Sequence actions:[Lens ...], [StopGrid action], nil]; 13 | */ 14 | public class CCStopGrid extends CCInstantAction { 15 | 16 | public static CCStopGrid action() { 17 | return new CCStopGrid(); 18 | } 19 | 20 | @Override 21 | public void start(CCNode aTarget) { 22 | super.start(aTarget); 23 | 24 | CCGridBase gb = this.target.getGrid(); 25 | if ( gb != null && gb.isActive() ) { 26 | gb.setActive(false); 27 | } 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /src/org/cocos2d/actions/instant/CCPlace.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.actions.instant; 2 | 3 | import org.cocos2d.nodes.CCNode; 4 | import org.cocos2d.types.CGPoint; 5 | 6 | /** 7 | * Places the node in a certain position 8 | */ 9 | public class CCPlace extends CCInstantAction { 10 | private CGPoint position; 11 | 12 | public static CCPlace action(CGPoint pnt) { 13 | return new CCPlace(pnt); 14 | } 15 | 16 | /** 17 | * creates a Place action with a position 18 | */ 19 | protected CCPlace(CGPoint pnt) { 20 | super(); 21 | position = CGPoint.make(pnt.x, pnt.y); 22 | } 23 | 24 | @Override 25 | public CCPlace copy() { 26 | return new CCPlace(position); 27 | } 28 | 29 | @Override 30 | public void start(CCNode aTarget) { 31 | super.start(aTarget); 32 | target.setPosition(position); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/org/cocos2d/events/CCTargetedTouchHandler.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.events; 2 | 3 | import java.util.ArrayList; 4 | 5 | import org.cocos2d.protocols.CCTouchDelegateProtocol; 6 | 7 | public class CCTargetedTouchHandler extends CCTouchHandler { 8 | 9 | boolean swallowsTouches; 10 | 11 | private ArrayList claimedSet; 12 | 13 | public CCTargetedTouchHandler(CCTouchDelegateProtocol delegate, int priority, boolean swallow) { 14 | super(delegate, priority); 15 | swallowsTouches = swallow; 16 | claimedSet = new ArrayList(); 17 | } 18 | 19 | void addClaimed(int pid) { 20 | if (!claimedSet.contains(pid)) { 21 | claimedSet.add(pid); 22 | } 23 | } 24 | 25 | void removeClaimed(int pid) { 26 | int ind = claimedSet.indexOf(pid); 27 | claimedSet.remove(ind); 28 | } 29 | 30 | boolean hasClaimed(int pid) { 31 | return claimedSet.contains(pid); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/org/cocos2d/actions/ease/CCEaseExponentialOut.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.actions.ease; 2 | 3 | import org.cocos2d.actions.interval.CCIntervalAction; 4 | 5 | public class CCEaseExponentialOut extends CCEaseAction { 6 | 7 | public static CCEaseExponentialOut action(CCIntervalAction action) { 8 | return new CCEaseExponentialOut(action); 9 | } 10 | 11 | protected CCEaseExponentialOut(CCIntervalAction action) { 12 | super(action); 13 | } 14 | 15 | @Override 16 | public CCEaseExponentialOut copy() { 17 | return new CCEaseExponentialOut(other.copy()); 18 | } 19 | 20 | @Override 21 | public void update(float t) { 22 | other.update((t == 1) ? 1 : ((float) (-Math.pow(2, -10 * t / 1) + 1))); 23 | } 24 | 25 | @Override 26 | public CCIntervalAction reverse() { 27 | return new CCEaseExponentialIn(other.reverse()); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /src/org/cocos2d/utils/pool/ObjectPool.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.utils.pool; 2 | 3 | import java.util.HashMap; 4 | 5 | @SuppressWarnings({ "rawtypes", "unchecked" }) 6 | public class ObjectPool { 7 | 8 | private HashMap, OneClassPool> lists; 9 | 10 | public ObjectPool() { 11 | lists = new HashMap, OneClassPool>(); 12 | } 13 | 14 | public OneClassPool registerPool(Class clazz, OneClassPool newPool) { 15 | OneClassPool pool = (OneClassPool)lists.get(clazz); 16 | if(pool == null) { 17 | // pool = new OneClassPool(clazz); 18 | lists.put(clazz, newPool); 19 | } 20 | return pool; 21 | } 22 | 23 | 24 | public OneClassPool getPool(Class clazz) { 25 | return (OneClassPool)lists.get(clazz); 26 | } 27 | 28 | public void clearAll() { 29 | for(OneClassPool objs : lists.values()) { 30 | objs.clear(); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | PuzzleGame 2 | ========== 3 | ![alt tag](http://denvycom.com/blog/wp-content/uploads/2014/04/Screenshot_2014-04-21-01-49-34-e1398016504406.png) 4 | Cocos2D for android project implementing a slider puzzle game. 5 | The Original cocos2d for Android Project can be found on git here : https://github.com/ZhouWeikuan/cocos2d 6 | 7 | 8 | This code is the same as seen in Gidigames for Android on Google Play. Feel free to modify and include in your commercial projects. 9 | 10 | ## Official Tutorial Document 11 | 12 | A detailed tutorial document for the project can be found on the [Denvycom website](http://denvycom.com/blog/step-by-step-guide-on-how-to-build-your-first-slider-puzzle-game-in-cocos2d-for-android-part-1/). 13 | 14 | ### License 15 | 16 | Code in this repository is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT) 17 | 18 | 19 | 20 | Victor Dibia. 21 | -------------------------------------------------------------------------------- /src/org/cocos2d/actions/ease/CCEaseExponentialIn.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.actions.ease; 2 | 3 | import org.cocos2d.actions.interval.CCIntervalAction; 4 | 5 | public class CCEaseExponentialIn extends CCEaseAction { 6 | 7 | public static CCEaseExponentialIn action(CCIntervalAction action) { 8 | return new CCEaseExponentialIn(action); 9 | } 10 | 11 | protected CCEaseExponentialIn(CCIntervalAction action) { 12 | super(action); 13 | } 14 | 15 | @Override 16 | public CCEaseExponentialIn copy() { 17 | return new CCEaseExponentialIn(other.copy()); 18 | } 19 | 20 | @Override 21 | public void update(float t) { 22 | other.update((t == 0) ? 0 : (float) Math.pow(2, 10 * (t / 1 - 1)) - 1 * 0.001f); 23 | } 24 | 25 | @Override 26 | public CCIntervalAction reverse() { 27 | return new CCEaseExponentialOut(other.reverse()); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /src/org/cocos2d/actions/interval/CCFadeIn.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.actions.interval; 2 | 3 | import org.cocos2d.protocols.CCRGBAProtocol; 4 | 5 | /** Fades In an object that implements the CCRGBAProtocol protocol. 6 | * It modifies the opacity from 0 to 255. 7 | * The "reverse" of this action is FadeOut 8 | */ 9 | public class CCFadeIn extends CCIntervalAction { 10 | 11 | public static CCFadeIn action(float t) { 12 | return new CCFadeIn(t); 13 | } 14 | 15 | protected CCFadeIn(float t) { 16 | super(t); 17 | } 18 | 19 | @Override 20 | public CCFadeIn copy() { 21 | return new CCFadeIn(duration); 22 | } 23 | 24 | @Override 25 | public void update(float t) { 26 | ((CCRGBAProtocol) target).setOpacity((int) (255.0f * t)); 27 | } 28 | 29 | @Override 30 | public CCFadeOut reverse() { 31 | return new CCFadeOut(duration); 32 | } 33 | } 34 | 35 | -------------------------------------------------------------------------------- /src/org/cocos2d/actions/interval/CCFadeOut.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.actions.interval; 2 | 3 | import org.cocos2d.protocols.CCRGBAProtocol; 4 | 5 | /** Fades Out an object that implements the CCRGBAProtocol protocol. 6 | * It modifies the opacity from 255 to 0. 7 | * The "reverse" of this action is FadeIn 8 | */ 9 | public class CCFadeOut extends CCIntervalAction { 10 | 11 | public static CCFadeOut action(float t) { 12 | return new CCFadeOut(t); 13 | } 14 | 15 | protected CCFadeOut(float t) { 16 | super(t); 17 | } 18 | 19 | @Override 20 | public CCFadeOut copy() { 21 | return new CCFadeOut(duration); 22 | } 23 | 24 | @Override 25 | public void update(float t) { 26 | ((CCRGBAProtocol) target).setOpacity((int) (255.0f * (1 - t))); 27 | } 28 | 29 | @Override 30 | public CCFadeIn reverse() { 31 | return new CCFadeIn(duration); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/org/cocos2d/actions/ease/CCEaseBackOut.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.actions.ease; 2 | 3 | import org.cocos2d.actions.interval.CCIntervalAction; 4 | 5 | public class CCEaseBackOut extends CCEaseAction { 6 | 7 | public static CCEaseBackOut action(CCIntervalAction action) { 8 | return new CCEaseBackOut(action); 9 | } 10 | 11 | protected CCEaseBackOut(CCIntervalAction action) { 12 | super(action); 13 | } 14 | 15 | @Override 16 | public CCEaseAction copy() { 17 | return new CCEaseBackOut(other.copy()); 18 | } 19 | 20 | @Override 21 | public void update(float t) { 22 | float overshoot = 1.70158f; 23 | 24 | t = t - 1; 25 | other.update(t * t * ((overshoot + 1) * t + overshoot) + 1); 26 | } 27 | 28 | @Override 29 | public CCIntervalAction reverse() { 30 | return new CCEaseBackIn(other.reverse()); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/org/cocos2d/actions/instant/CCInstantAction.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.actions.instant; 2 | 3 | import org.cocos2d.actions.base.CCFiniteTimeAction; 4 | 5 | /** Instant actions are immediate actions. They don't have a duration like 6 | the CCIntervalAction actions. 7 | */ 8 | public class CCInstantAction extends CCFiniteTimeAction { 9 | 10 | protected CCInstantAction() { 11 | super(0); 12 | } 13 | 14 | @Override 15 | public CCInstantAction copy() { 16 | return new CCInstantAction(); 17 | } 18 | 19 | @Override 20 | public boolean isDone() { 21 | return true; 22 | } 23 | 24 | @Override 25 | public void step(float dt) { 26 | update(1.0f); 27 | } 28 | 29 | @Override 30 | public void update(float t) { 31 | // ignore 32 | } 33 | 34 | @Override 35 | public CCFiniteTimeAction reverse() { 36 | return copy(); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/org/cocos2d/actions/tile/CCFadeOutDownTiles.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.actions.tile; 2 | 3 | import org.cocos2d.types.CGPoint; 4 | import org.cocos2d.types.ccGridSize; 5 | 6 | //////////////////////////////////////////////////////////// 7 | 8 | /** CCFadeOutDownTiles action. 9 | Fades out the tiles in downwards direction 10 | */ 11 | public class CCFadeOutDownTiles extends CCFadeOutUpTiles { 12 | public static CCFadeOutDownTiles action(ccGridSize gSize, float d) { 13 | return new CCFadeOutDownTiles(gSize, d); 14 | } 15 | 16 | protected CCFadeOutDownTiles(ccGridSize gSize, float d) { 17 | super(gSize, d); 18 | } 19 | 20 | @Override 21 | public float testFunc(ccGridSize pos, float time) { 22 | CGPoint n = CGPoint.ccpMult(CGPoint.ccp(gridSize.x,gridSize.y), (1.0f - time)); 23 | if ( pos.y == 0 ) 24 | return 1.0f; 25 | return (float)Math.pow( n.y / pos.y, 6 ); 26 | } 27 | 28 | } 29 | 30 | -------------------------------------------------------------------------------- /src/org/cocos2d/actions/ease/CCEaseBounce.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.actions.ease; 2 | 3 | import org.cocos2d.actions.interval.CCIntervalAction; 4 | 5 | public abstract class CCEaseBounce extends CCEaseAction { 6 | 7 | protected CCEaseBounce(CCIntervalAction action) { 8 | super(action); 9 | } 10 | 11 | @Override 12 | public abstract void update(float t); 13 | 14 | protected float bounceTime(float t) { 15 | if (t < 1 / 2.75) { 16 | return 7.5625f * t * t; 17 | } else if (t < 2 / 2.75) { 18 | t -= 1.5f / 2.75f; 19 | return 7.5625f * t * t + 0.75f; 20 | } else if (t < 2.5 / 2.75) { 21 | t -= 2.25f / 2.75f; 22 | return 7.5625f * t * t + 0.9375f; 23 | } 24 | 25 | t -= 2.625f / 2.75f; 26 | return 7.5625f * t * t + 0.984375f; 27 | } 28 | 29 | @Override 30 | public abstract CCIntervalAction reverse(); 31 | } 32 | -------------------------------------------------------------------------------- /src/org/cocos2d/actions/tile/CCFadeOutBLTiles.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.actions.tile; 2 | 3 | import org.cocos2d.types.CGPoint; 4 | import org.cocos2d.types.ccGridSize; 5 | 6 | //////////////////////////////////////////////////////////// 7 | 8 | /** CCFadeOutBLTiles action. 9 | Fades out the tiles in a Bottom-Left direction 10 | */ 11 | public class CCFadeOutBLTiles extends CCFadeOutTRTiles { 12 | 13 | public static CCFadeOutBLTiles action(ccGridSize gSize, float d) { 14 | return new CCFadeOutBLTiles(gSize, d); 15 | } 16 | 17 | protected CCFadeOutBLTiles(ccGridSize gSize, float d) { 18 | super(gSize, d); 19 | } 20 | 21 | @Override 22 | public float testFunc(ccGridSize pos, float time) { 23 | CGPoint n = CGPoint.ccpMult(CGPoint.ccp(gridSize.x, gridSize.y), (1.0f-time)); 24 | 25 | if ( (pos.x+pos.y) == 0 ) 26 | return 1.0f; 27 | return (float)Math.pow( (n.x+n.y) / (pos.x+pos.y), 6 ); 28 | } 29 | 30 | } 31 | 32 | -------------------------------------------------------------------------------- /src/org/cocos2d/actions/instant/CCFlipX.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.actions.instant; 2 | 3 | import org.cocos2d.nodes.CCNode; 4 | import org.cocos2d.nodes.CCSprite; 5 | 6 | /** Flips the sprite horizontally 7 | @since v0.99.0 8 | */ 9 | public class CCFlipX extends CCInstantAction { 10 | boolean flipX; 11 | 12 | public static CCFlipX action(boolean fx) { 13 | return new CCFlipX(fx); 14 | } 15 | 16 | public CCFlipX(boolean fx) { 17 | super(); 18 | flipX = fx; 19 | } 20 | 21 | @Override 22 | public CCFlipX copy() { 23 | CCFlipX copy = new CCFlipX(flipX); 24 | return copy; 25 | } 26 | 27 | @Override 28 | public void start(CCNode aTarget) { 29 | super.start(aTarget); 30 | CCSprite sprite = (CCSprite)aTarget; 31 | sprite.setFlipX(flipX); 32 | } 33 | 34 | @Override 35 | public CCFlipX reverse() { 36 | return CCFlipX.action(!flipX); 37 | } 38 | } 39 | 40 | -------------------------------------------------------------------------------- /src/org/cocos2d/actions/instant/CCFlipY.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.actions.instant; 2 | 3 | import org.cocos2d.nodes.CCNode; 4 | import org.cocos2d.nodes.CCSprite; 5 | 6 | /** Flips the sprite vertically 7 | @since v0.99.0 8 | */ 9 | public class CCFlipY extends CCInstantAction { 10 | boolean flipY; 11 | 12 | public static CCFlipY action(boolean fy) { 13 | return new CCFlipY(fy); 14 | } 15 | 16 | public CCFlipY(boolean fy) { 17 | super(); 18 | flipY = fy; 19 | } 20 | 21 | @Override 22 | public CCFlipY copy() { 23 | CCFlipY copy = new CCFlipY(flipY); 24 | return copy; 25 | } 26 | 27 | @Override 28 | public void start(CCNode aTarget) { 29 | super.start(aTarget); 30 | CCSprite sprite = (CCSprite)aTarget; 31 | sprite.setFlipY(flipY); 32 | } 33 | 34 | @Override 35 | public CCFlipY reverse() { 36 | return CCFlipY.action(!flipY); 37 | } 38 | } 39 | 40 | -------------------------------------------------------------------------------- /src/org/cocos2d/utils/GeometryUtil.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.utils; 2 | 3 | import org.cocos2d.types.CGPoint; 4 | import org.cocos2d.types.CGRect; 5 | import org.cocos2d.types.CGSize; 6 | 7 | public class GeometryUtil { 8 | 9 | public static CGPoint CGPointFromString(String str) { 10 | String coords = str.replaceAll("[{|}]", ""); 11 | String c[] = coords.split(","); 12 | return CGPoint.make(Float.parseFloat(c[0]), Float.parseFloat(c[1])); 13 | } 14 | 15 | public static CGSize CGSizeFromString(String str) { 16 | String coords = str.replaceAll("[{|}]", ""); 17 | String c[] = coords.split(","); 18 | return CGSize.make(Float.parseFloat(c[0]), Float.parseFloat(c[1])); 19 | } 20 | 21 | public static CGRect CGRectFromString(String str) { 22 | String c[] = str.replaceAll("[{|}]", "").split(","); 23 | return CGRect.make(Float.parseFloat(c[0]), 24 | Float.parseFloat(c[1]), 25 | Float.parseFloat(c[2]), 26 | Float.parseFloat(c[3])); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/org/cocos2d/actions/interval/CCBlink.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.actions.interval; 2 | 3 | /** Blinks a CCNode object by modifying it's visible attribute 4 | */ 5 | public class CCBlink extends CCIntervalAction { 6 | private int times; 7 | 8 | /** creates the action */ 9 | public static CCBlink action(float t, int b) { 10 | return new CCBlink(t, b); 11 | } 12 | 13 | /** initilizes the action */ 14 | protected CCBlink(float t, int b) { 15 | super(t); 16 | times = b; 17 | } 18 | 19 | @Override 20 | public CCBlink copy() { 21 | return new CCBlink(duration, times); 22 | } 23 | 24 | @Override 25 | public void update(float t) { 26 | float slice = 1.0f / times; 27 | float m = t % slice; 28 | target.setVisible(m > slice / 2 ? true : false); 29 | } 30 | 31 | @Override 32 | public CCBlink reverse() { 33 | return new CCBlink(duration, times); 34 | } 35 | } 36 | 37 | -------------------------------------------------------------------------------- /src/org/cocos2d/extensions/scroll/CCTableViewSpriteCell.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Port from SWScrollView and SWTableView for iphone 3 | * by Rodrigo Collavo on 02/03/2012 4 | */ 5 | 6 | package org.cocos2d.extensions.scroll; 7 | 8 | import org.cocos2d.nodes.CCSprite; 9 | import org.cocos2d.types.CGPoint; 10 | 11 | public class CCTableViewSpriteCell extends CCTableViewCell { 12 | 13 | private CCSprite m_sprite; 14 | 15 | public void setSprite(CCSprite s) { 16 | if (m_sprite != null) { 17 | removeChild(m_sprite, false); 18 | } 19 | 20 | s.setAnchorPoint(CGPoint.zero()); 21 | s.setPosition(CGPoint.zero()); 22 | m_sprite = s; 23 | addChild(m_sprite); 24 | } 25 | 26 | public CCSprite getSprite() { 27 | return m_sprite; 28 | } 29 | 30 | @Override 31 | public void reset() { 32 | super.reset(); 33 | 34 | if (m_sprite != null) { 35 | removeChild(m_sprite, false); 36 | } 37 | m_sprite = null; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/org/cocos2d/actions/grid/CCReuseGrid.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.actions.grid; 2 | 3 | import org.cocos2d.actions.instant.CCInstantAction; 4 | import org.cocos2d.grid.CCGridBase; 5 | import org.cocos2d.nodes.CCNode; 6 | 7 | //////////////////////////////////////////////////////////// 8 | 9 | /** CCReuseGrid action */ 10 | public class CCReuseGrid extends CCInstantAction { 11 | int t; 12 | 13 | /** creates an action with the number of times that the current grid will be reused */ 14 | public static CCReuseGrid action(int times) { 15 | return new CCReuseGrid(times); 16 | } 17 | 18 | /** initializes an action with the number of times that the current grid will be reused */ 19 | public CCReuseGrid(int times) { 20 | super(); 21 | t = times; 22 | } 23 | 24 | @Override 25 | public void start(CCNode aTarget) { 26 | super.start(aTarget); 27 | 28 | CCGridBase gb = target.getGrid(); 29 | if ( gb != null && gb.isActive() ) 30 | gb.setReuseGrid(gb.reuseGrid() + t); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/org/cocos2d/actions/instant/CCCallFuncND.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.actions.instant; 2 | 3 | 4 | /** 5 | * Calls a 'callback' with the node as the first argument and the 2nd argument is data 6 | * ND means: Node Data 7 | */ 8 | public class CCCallFuncND extends CCCallFuncN { 9 | protected Object data; 10 | 11 | /** creates the action with the callback and the data to pass as an argument */ 12 | public static CCCallFuncND action(Object t, String s, Object d) { 13 | return new CCCallFuncND(t, s, d, new Class[] { 14 | Object.class, Object.class, 15 | }); 16 | } 17 | 18 | /** 19 | * creates the action with the callback and the data to pass as an argument 20 | */ 21 | protected CCCallFuncND(Object t, String s, Object d, Class[] p) { 22 | super(t, s, p); 23 | data = d; 24 | } 25 | 26 | /** 27 | * executes the callback 28 | */ 29 | public void execute() { 30 | try { 31 | invocation.invoke(targetCallback, new Object[]{target, data}); 32 | } catch (Exception e) { 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 10 | 11 | 16 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /src/org/cocos2d/actions/interval/CCJumpTo.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.actions.interval; 2 | 3 | import org.cocos2d.nodes.CCNode; 4 | import org.cocos2d.types.CGPoint; 5 | 6 | // 7 | // JumpTo 8 | // 9 | 10 | /** 11 | * Moves a CCNode object to a parabolic position simulating a jump movement 12 | * by modifying it's position attribute. 13 | */ 14 | public class CCJumpTo extends CCJumpBy { 15 | 16 | public static CCJumpTo action(float time, CGPoint pos, float height, int jumps) { 17 | return new CCJumpTo(time, pos, height, jumps); 18 | } 19 | 20 | protected CCJumpTo(float time, CGPoint pos, float height, int jumps) { 21 | super(time, pos, height, jumps); 22 | } 23 | 24 | @Override 25 | public CCJumpTo copy() { 26 | return new CCJumpTo(duration, delta, height, jumps); 27 | } 28 | 29 | @Override 30 | public void start(CCNode aTarget) { 31 | super.start(aTarget); 32 | delta.x -= startPosition.x; 33 | delta.y -= startPosition.y; 34 | } 35 | } 36 | 37 | -------------------------------------------------------------------------------- /src/org/cocos2d/types/ccColor4B.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.types; 2 | 3 | /** RGBA color composed of 4 bytes 4 | @since v0.8 5 | */ 6 | public class ccColor4B { 7 | public static final int size = 4; 8 | 9 | public int r; 10 | public int g; 11 | public int b; 12 | public int a; 13 | 14 | public ccColor4B(int rr, int gg, int bb, int aa) { 15 | r = rr; 16 | g = gg; 17 | b = bb; 18 | a = aa; 19 | } 20 | 21 | public byte[] toByteArray() { 22 | return new byte[]{(byte) r, (byte) g, (byte) b, (byte) a}; 23 | } 24 | 25 | public float[] toFloatArray() { 26 | return new float[] {r/255f, g/255f, b/255f, a/255f}; 27 | } 28 | 29 | //! helper macro that creates an ccColor4B type 30 | public static ccColor4B ccc4(final int r, final int g, final int b, final int a) { 31 | return new ccColor4B(r, g, b, a); 32 | } 33 | 34 | public String toString() { 35 | return "< r=" + r + ", g=" + g + ", b=" + b + ", a=" + a + " >"; 36 | } 37 | } 38 | 39 | -------------------------------------------------------------------------------- /src/org/cocos2d/layers/CCScene.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.layers; 2 | 3 | import org.cocos2d.nodes.CCDirector; 4 | import org.cocos2d.nodes.CCNode; 5 | import org.cocos2d.types.CGSize; 6 | 7 | /** CCScene is a subclass of CCNode that is used only as an abstract concept. 8 | 9 | CCScene an CCNode are almost identical with the difference that CCScene has it's 10 | anchor point (by default) at the center of the screen. 11 | 12 | For the moment CCScene has no other logic than that, but in future releases it might have 13 | additional logic. 14 | 15 | It is a good practice to use and CCScene as the parent of all your nodes. 16 | */ 17 | public class CCScene extends CCNode { 18 | 19 | public static CCScene node() { 20 | return new CCScene(); 21 | } 22 | 23 | protected CCScene() { 24 | super(); 25 | 26 | CGSize s = CCDirector.sharedDirector().winSize(); 27 | 28 | setRelativeAnchorPoint(false); 29 | 30 | setAnchorPoint(0.5f, 0.5f); 31 | setContentSize(s); 32 | } 33 | } 34 | 35 | -------------------------------------------------------------------------------- /src/org/cocos2d/actions/ease/CCEaseInOut.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.actions.ease; 2 | 3 | import org.cocos2d.actions.interval.CCIntervalAction; 4 | 5 | public class CCEaseInOut extends CCEaseRateAction { 6 | 7 | public static CCEaseInOut action(CCIntervalAction action, float rate) { 8 | return new CCEaseInOut(action, rate); 9 | } 10 | 11 | protected CCEaseInOut(CCIntervalAction action, float rate) { 12 | super(action, rate); 13 | } 14 | 15 | @Override 16 | public void update(float t) { 17 | int sign = 1; 18 | int r = (int) rate; 19 | if (r % 2 == 0) 20 | sign = -1; 21 | 22 | t *= 2; 23 | if (t < 1) 24 | other.update(0.5f * (float) Math.pow(t, rate)); 25 | else 26 | other.update(sign * 0.5f * ((float) Math.pow(t - 2, rate) + sign * 2)); 27 | } 28 | 29 | 30 | // InOut and OutIn are symmetrical 31 | @Override 32 | public CCIntervalAction reverse() { 33 | return new CCEaseInOut(other.reverse(), rate); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/org/cocos2d/utils/TransformUtils.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.utils; 2 | 3 | import org.cocos2d.types.CGAffineTransform; 4 | 5 | public class TransformUtils { 6 | 7 | public static void CCAffineToGL(final CGAffineTransform t, float[] m) 8 | { 9 | // | m[0] m[4] m[8] m[12] | | m11 m21 m31 m41 | | a c 0 tx | 10 | // | m[1] m[5] m[9] m[13] | | m12 m22 m32 m42 | | b d 0 ty | 11 | // | m[2] m[6] m[10] m[14] | <=> | m13 m23 m33 m43 | <=> | 0 0 1 0 | 12 | // | m[3] m[7] m[11] m[15] | | m14 m24 m34 m44 | | 0 0 0 1 | 13 | 14 | m[2] = m[3] = m[6] = m[7] = m[8] = m[9] = m[11] = m[14] = 0.0f; 15 | m[10] = m[15] = 1.0f; 16 | m[0] = (float)t.m00; m[4] = (float)t.m01; m[12] = (float)t.m02; 17 | m[1] = (float)t.m10; m[5] = (float)t.m11; m[13] = (float)t.m12; 18 | } 19 | 20 | void GLToCGAffine(final float[] m, CGAffineTransform t) 21 | { 22 | t.m00 = m[0]; t.m01 = m[4]; t.m02 = m[12]; 23 | t.m10 = m[1]; t.m11 = m[5]; t.m12 = m[13]; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/org/cocos2d/actions/ease/CCEaseBounceInOut.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.actions.ease; 2 | 3 | import org.cocos2d.actions.interval.CCIntervalAction; 4 | 5 | public class CCEaseBounceInOut extends CCEaseBounce { 6 | 7 | public static CCEaseBounceInOut action(CCIntervalAction action) { 8 | return new CCEaseBounceInOut(action); 9 | } 10 | 11 | protected CCEaseBounceInOut(CCIntervalAction action) { 12 | super(action); 13 | } 14 | 15 | @Override 16 | public CCEaseAction copy() { 17 | return new CCEaseBounceInOut(other.copy()); 18 | } 19 | 20 | @Override 21 | public void update(float t) { 22 | float newT = 0; 23 | if (t < 0.5) { 24 | t = t * 2; 25 | newT = (1 - bounceTime(1 - t)) * 0.5f; 26 | } else 27 | newT = bounceTime(t * 2 - 1) * 0.5f + 0.5f; 28 | 29 | other.update(newT); 30 | } 31 | 32 | @Override 33 | public CCIntervalAction reverse() { 34 | return new CCEaseBounceInOut(other.reverse()); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/org/cocos2d/actions/ease/CCEaseRateAction.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.actions.ease; 2 | 3 | import org.cocos2d.actions.interval.CCIntervalAction; 4 | 5 | 6 | /** 7 | * Base class for Easing actions with rate parameters 8 | */ 9 | public class CCEaseRateAction extends CCEaseAction { 10 | /** rate value for the actions */ 11 | float rate; 12 | 13 | /** Creates the action with the inner action and the rate parameter */ 14 | public static CCEaseRateAction action(CCIntervalAction action, float rate) { 15 | return new CCEaseRateAction(action, rate); 16 | } 17 | 18 | /** Initializes the action with the inner action and the rate parameter */ 19 | protected CCEaseRateAction(CCIntervalAction action, float aRate) { 20 | super(action); 21 | rate = aRate; 22 | } 23 | 24 | @Override 25 | public CCEaseRateAction copy() { 26 | return new CCEaseRateAction(other.copy(), rate); 27 | } 28 | 29 | @Override 30 | public CCIntervalAction reverse() { 31 | return new CCEaseRateAction(other.reverse(), 1 / rate); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/org/cocos2d/layers/CCTMXLayerInfo.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.layers; 2 | 3 | import java.nio.IntBuffer; 4 | import java.util.HashMap; 5 | 6 | import org.cocos2d.types.CGPoint; 7 | import org.cocos2d.types.CGSize; 8 | 9 | /* CCTMXLayerInfo contains the information about the layers like: 10 | - Layer name 11 | - Layer size 12 | - Layer opacity at creation time (it can be modified at runtime) 13 | - Whether the layer is visible (if it's not visible, then the CocosNode won't be created) 14 | 15 | This information is obtained from the TMX file. 16 | */ 17 | public class CCTMXLayerInfo { 18 | String name; 19 | CGSize layerSize; 20 | IntBuffer tiles; 21 | boolean visible; 22 | int opacity = 255; 23 | boolean ownTiles; 24 | int minGID; 25 | int maxGID; 26 | HashMap properties; 27 | CGPoint offset; 28 | 29 | public CCTMXLayerInfo() { 30 | super(); 31 | 32 | ownTiles = true; 33 | minGID = 100000; 34 | maxGID = 0; 35 | name = null; 36 | tiles = null; 37 | offset = CGPoint.zero(); 38 | properties = new HashMap(); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/org/cocos2d/actions/ease/CCEaseBackInOut.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.actions.ease; 2 | 3 | import org.cocos2d.actions.interval.CCIntervalAction; 4 | 5 | public class CCEaseBackInOut extends CCEaseAction { 6 | 7 | public static CCEaseBackInOut action(CCIntervalAction action) { 8 | return new CCEaseBackInOut(action); 9 | } 10 | 11 | protected CCEaseBackInOut(CCIntervalAction action) { 12 | super(action); 13 | } 14 | 15 | @Override 16 | public CCEaseAction copy() { 17 | return new CCEaseBackInOut(other.copy()); 18 | } 19 | 20 | @Override 21 | public void update(float t) { 22 | float overshoot = 1.70158f * 1.525f; 23 | 24 | t = t * 2; 25 | if (t < 1) { 26 | other.update((t * t * ((overshoot + 1) * t - overshoot)) / 2); 27 | } else { 28 | t = t - 2; 29 | other.update((t * t * ((overshoot + 1) * t + overshoot)) / 2 + 1); 30 | } 31 | } 32 | 33 | @Override 34 | public CCIntervalAction reverse() { 35 | return new CCEaseBackInOut(other.reverse()); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /src/org/cocos2d/extensions/scroll/CCTableViewDataSource.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Port from SWScrollView and SWTableView for iphone 3 | * by Rodrigo Collavo on 02/03/2012 4 | */ 5 | 6 | package org.cocos2d.extensions.scroll; 7 | 8 | import org.cocos2d.types.CGSize; 9 | 10 | /** 11 | * Data source that governs table backend data. 12 | */ 13 | public interface CCTableViewDataSource { 14 | /** 15 | * cell height for a given table. 16 | * 17 | * @param table table to hold the instances of Class 18 | * @return cell size 19 | */ 20 | public CGSize cellSizeForTable(CCTableView table); 21 | /** 22 | * a cell instance at a given index 23 | * 24 | * @param idx index to search for a cell 25 | * @return cell found at idx 26 | */ 27 | public CCTableViewCell tableCellAtIndex(CCTableView table, int idx); 28 | /** 29 | * Returns number of cells in a given table view. 30 | * 31 | * @return number of cells 32 | */ 33 | public int numberOfCellsInTableView(CCTableView table); 34 | } 35 | -------------------------------------------------------------------------------- /src/org/cocos2d/actions/interval/CCMoveBy.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.actions.interval; 2 | 3 | import org.cocos2d.nodes.CCNode; 4 | import org.cocos2d.types.CGPoint; 5 | 6 | /** Moves a CCNode object x,y pixels by modifying it's position attribute. 7 | x and y are relative to the position of the object. 8 | Duration is is seconds. 9 | */ 10 | public class CCMoveBy extends CCMoveTo { 11 | /** creates the action */ 12 | public static CCMoveBy action(float duration, CGPoint pos) { 13 | return new CCMoveBy(duration, pos); 14 | } 15 | 16 | /** initializes the action */ 17 | protected CCMoveBy(float t, CGPoint pos) { 18 | super(t, pos); 19 | delta.set(pos.x, pos.y); 20 | } 21 | 22 | @Override 23 | public CCMoveBy copy() { 24 | return new CCMoveBy(duration, delta); 25 | } 26 | 27 | @Override 28 | public void start(CCNode aTarget) { 29 | float tmpx = delta.x; 30 | float tmpy = delta.y; 31 | 32 | super.start(aTarget); 33 | delta.set(tmpx, tmpy); 34 | } 35 | 36 | @Override 37 | public CCMoveBy reverse() { 38 | return new CCMoveBy(duration, CGPoint.ccpNeg(delta)); 39 | } 40 | } 41 | 42 | -------------------------------------------------------------------------------- /src/org/cocos2d/protocols/CCTouchDelegateProtocol.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.protocols; 2 | 3 | import android.view.MotionEvent; 4 | 5 | /** 6 | CCTargetedTouchDelegate. 7 | 8 | Using this type of delegate results in two benefits: 9 | 1. You don't need to deal with NSSets, the dispatcher does the job of splitting 10 | them. You get exactly one UITouch per call. 11 | 2. You can *claim* a UITouch by returning YES in ccTouchBegan. Updates of claimed 12 | touches are sent only to the delegate(s) that claimed them. So if you get a move/ 13 | ended/cancelled update you're sure it's your touch. This frees you from doing a 14 | lot of checks when doing multi-touch. 15 | 16 | (The name TargetedTouchDelegate relates to updates "targeting" their specific 17 | handler, without bothering the other handlers.) 18 | @since v0.8 19 | */ 20 | public interface CCTouchDelegateProtocol { 21 | /** Return YES to claim the touch. 22 | @since v0.8 23 | */ 24 | public boolean ccTouchesBegan(MotionEvent event); 25 | 26 | public boolean ccTouchesMoved(MotionEvent event); 27 | 28 | public boolean ccTouchesEnded(MotionEvent event); 29 | 30 | public boolean ccTouchesCancelled(MotionEvent event); 31 | 32 | } 33 | 34 | -------------------------------------------------------------------------------- /src/org/cocos2d/actions/interval/CCScaleBy.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.actions.interval; 2 | 3 | import org.cocos2d.nodes.CCNode; 4 | 5 | /** 6 | * Scales a CCNode object a zoom factor by modifying it's scale attribute. 7 | */ 8 | public class CCScaleBy extends CCScaleTo { 9 | 10 | public static CCScaleBy action(float t, float s) { 11 | return new CCScaleBy(t, s, s); 12 | } 13 | 14 | public static CCScaleBy action(float t, float sx, float sy) { 15 | return new CCScaleBy(t, sx, sy); 16 | } 17 | 18 | protected CCScaleBy(float t, float s) { 19 | super(t, s, s); 20 | } 21 | 22 | protected CCScaleBy(float t, float sx, float sy) { 23 | super(t, sx, sy); 24 | } 25 | 26 | 27 | @Override 28 | public CCScaleBy copy() { 29 | return new CCScaleBy(duration, endScaleX, endScaleY); 30 | } 31 | 32 | @Override 33 | public void start(CCNode aTarget) { 34 | super.start(aTarget); 35 | deltaX = startScaleX * endScaleX - startScaleX; 36 | deltaY = startScaleY * endScaleY - startScaleY; 37 | } 38 | 39 | @Override 40 | public CCScaleBy reverse() { 41 | return new CCScaleBy(duration, 1 / endScaleX, 1 / endScaleY); 42 | } 43 | } 44 | 45 | -------------------------------------------------------------------------------- /src/org/cocos2d/types/CGSize.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.types; 2 | 3 | 4 | public class CGSize { 5 | public float width, height; 6 | 7 | private CGSize() { 8 | this(0, 0); 9 | } 10 | 11 | private CGSize(float w, float h) { 12 | width = w; 13 | height = h; 14 | } 15 | 16 | public static CGSize make(float w, float h) { 17 | return new CGSize(w, h); 18 | } 19 | 20 | public static CGSize zero() { 21 | return new CGSize(0, 0); 22 | } 23 | 24 | public void set(CGSize s) { 25 | width = s.width; 26 | height = s.height; 27 | } 28 | 29 | public void set(float w, float h) { 30 | width = w; 31 | height = h; 32 | } 33 | 34 | private static CGSize ZERO_SIZE = CGSize.zero(); 35 | public static CGSize getZero() { 36 | return ZERO_SIZE; 37 | } 38 | 39 | public float getWidth() { 40 | return width; 41 | } 42 | 43 | public float getHeight() { 44 | return height; 45 | } 46 | 47 | public static boolean equalToSize(CGSize s1, CGSize s2) { 48 | return s1.width == s2.width && s1.height == s2.height; 49 | } 50 | 51 | public String toString() { 52 | return "<" + width + ", " + height + ">"; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/org/cocos2d/actions/grid/CCWaves3D.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.actions.grid; 2 | 3 | import org.cocos2d.types.CCVertex3D; 4 | import org.cocos2d.types.ccGridSize; 5 | 6 | /** CCWaves3D action */ 7 | public class CCWaves3D extends CCGrid3DAction { 8 | int waves; 9 | /** amplitude of the wave */ 10 | float amplitude; 11 | /** amplitude rate of the wave */ 12 | float amplitudeRate; 13 | 14 | public static CCWaves3D action(int wav, float amp, ccGridSize gSize, float d) { 15 | return new CCWaves3D(wav, amp, gSize, d); 16 | } 17 | 18 | public CCWaves3D(int wav, float amp, ccGridSize gSize, float d) { 19 | super(gSize, d); 20 | waves = wav; 21 | amplitude = amp; 22 | amplitudeRate = 1.0f; 23 | } 24 | 25 | @Override 26 | public CCWaves3D copy() { 27 | CCWaves3D copy = new CCWaves3D(waves, amplitude, gridSize, duration); 28 | return copy; 29 | } 30 | 31 | @Override 32 | public void update(float time) { 33 | int i, j; 34 | 35 | for( i = 0; i < (gridSize.x+1); i++ ) { 36 | for( j = 0; j < (gridSize.y+1); j++ ) { 37 | CCVertex3D v = originalVertex(ccGridSize.ccg(i,j)); 38 | v.z += (float)(Math.sin(Math.PI*time*waves*2 + (v.y+v.x) * .01f) * amplitude * amplitudeRate); 39 | setVertex(ccGridSize.ccg(i,j), v); 40 | } 41 | } 42 | } 43 | } 44 | 45 | -------------------------------------------------------------------------------- /src/org/cocos2d/actions/interval/CCRotateBy.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.actions.interval; 2 | 3 | import org.cocos2d.nodes.CCNode; 4 | 5 | // 6 | // RotateBy 7 | // 8 | 9 | /** 10 | * Rotates a CCNode object clockwise a number of degrees by modiying it's rotation attribute. 11 | */ 12 | public class CCRotateBy extends CCIntervalAction { 13 | private float angle; 14 | private float startAngle; 15 | 16 | /** creates the action */ 17 | public static CCRotateBy action(float t, float a) { 18 | return new CCRotateBy(t, a); 19 | } 20 | 21 | /** initializes the action */ 22 | protected CCRotateBy(float t, float a) { 23 | super(t); 24 | angle = a; 25 | } 26 | 27 | @Override 28 | public CCRotateBy copy() { 29 | return new CCRotateBy(duration, angle); 30 | } 31 | 32 | @Override 33 | public void start(CCNode aTarget) { 34 | super.start(aTarget); 35 | startAngle = target.getRotation(); 36 | } 37 | 38 | @Override 39 | public void update(float t) { 40 | // XXX: shall I add % 360 41 | target.setRotation(startAngle + angle * t); 42 | } 43 | 44 | @Override 45 | public CCRotateBy reverse() { 46 | return new CCRotateBy(duration, -angle); 47 | } 48 | 49 | } 50 | 51 | -------------------------------------------------------------------------------- /src/org/cocos2d/actions/ease/CCEaseElasticOut.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.actions.ease; 2 | 3 | import org.cocos2d.actions.interval.CCIntervalAction; 4 | 5 | public class CCEaseElasticOut extends CCEaseElastic { 6 | 7 | public static CCEaseElasticOut action(CCIntervalAction action) { 8 | return new CCEaseElasticOut(action, 0.3f); 9 | } 10 | 11 | public static CCEaseElasticOut action(CCIntervalAction action, float period) { 12 | return new CCEaseElasticOut(action, period); 13 | } 14 | 15 | protected CCEaseElasticOut(CCIntervalAction action, float period) { 16 | super(action, period); 17 | } 18 | 19 | @Override 20 | public CCEaseAction copy() { 21 | return new CCEaseElasticOut(other.copy(), period_); 22 | } 23 | 24 | @Override 25 | public void update(float t) { 26 | float newT = 0; 27 | if (t == 0 || t == 1) { 28 | newT = t; 29 | } else { 30 | float s = period_ / 4; 31 | newT = (float) (Math.pow(2, -10 * t) * Math.sin((t - s) * M_PI_X_2 / period_) + 1); 32 | } 33 | other.update(newT); 34 | } 35 | 36 | @Override 37 | public CCIntervalAction reverse() { 38 | return new CCEaseElasticIn(other.reverse(), period_); 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /src/org/cocos2d/layers/CCTMXTilesetInfo.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.layers; 2 | 3 | import org.cocos2d.types.CGPoint; 4 | import org.cocos2d.types.CGRect; 5 | import org.cocos2d.types.CGSize; 6 | 7 | /** 8 | * CCTMXTilesetInfo contains the information about the tilesets like: 9 | - Tileset name 10 | - Tilset spacing 11 | - Tileset margin 12 | - size of the tiles 13 | - Image used for the tiles 14 | - Image size 15 | 16 | This information is obtained from the TMX file. 17 | */ 18 | public class CCTMXTilesetInfo { 19 | String name; 20 | int firstGid; 21 | CGSize tileSize; 22 | int spacing; 23 | int margin; 24 | 25 | // filename containing the tiles (should be spritesheet / texture atlas) 26 | String sourceImage; 27 | 28 | // size in pixels of the image 29 | CGSize imageSize; 30 | 31 | 32 | public CGRect rectForGID(int gid) { 33 | CGRect rect = CGRect.make(CGPoint.zero(), tileSize); 34 | 35 | gid = gid - firstGid; 36 | 37 | int max_x = (int) ((imageSize.width - margin*2 + spacing) / (tileSize.width + spacing)); 38 | if (max_x == 0) { 39 | max_x = 1; 40 | } 41 | 42 | rect.origin.x = (gid % max_x) * (tileSize.width + spacing) + margin; 43 | rect.origin.y = (gid / max_x) * (tileSize.height + spacing) + margin; 44 | 45 | return rect; 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/org/cocos2d/actions/interval/CCFadeTo.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.actions.interval; 2 | 3 | import org.cocos2d.nodes.CCNode; 4 | import org.cocos2d.protocols.CCRGBAProtocol; 5 | 6 | /** Fades an object that implements the CCRGBAProtocol protocol. 7 | * It modifies the opacity from the current value to a custom one. 8 | * @warning This action doesn't support "reverse" 9 | */ 10 | public class CCFadeTo extends CCIntervalAction { 11 | int toOpacity; 12 | int fromOpacity; 13 | 14 | /** creates an action with duration and opactiy */ 15 | public static CCFadeTo action(float t, int a) { 16 | return new CCFadeTo(t, a); 17 | } 18 | 19 | /** initializes the action with duration and opacity */ 20 | protected CCFadeTo(float t, int a) { 21 | super(t); 22 | toOpacity = a; 23 | } 24 | 25 | @Override 26 | public CCFadeTo copy() { 27 | return new CCFadeTo(duration, toOpacity); 28 | } 29 | 30 | @Override 31 | public void start(CCNode aTarget) { 32 | super.start(aTarget); 33 | fromOpacity = ((CCRGBAProtocol) target).getOpacity(); 34 | } 35 | 36 | @Override 37 | public void update(float t) { 38 | ((CCRGBAProtocol) target).setOpacity((int)(fromOpacity + (toOpacity - fromOpacity) * t)); 39 | } 40 | } 41 | 42 | -------------------------------------------------------------------------------- /src/org/cocos2d/transitions/CCSlideInBTransition.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.transitions; 2 | 3 | import org.cocos2d.actions.interval.CCIntervalAction; 4 | import org.cocos2d.actions.interval.CCMoveBy; 5 | import org.cocos2d.layers.CCScene; 6 | import org.cocos2d.nodes.CCDirector; 7 | import org.cocos2d.types.CGPoint; 8 | import org.cocos2d.types.CGSize; 9 | 10 | /** 11 | * SlideInB Transition. 12 | * Slide in the incoming scene from the bottom border. 13 | */ 14 | public class CCSlideInBTransition extends CCSlideInLTransition { 15 | 16 | public static CCSlideInBTransition transition(float t, CCScene s) { 17 | return new CCSlideInBTransition(t, s); 18 | } 19 | 20 | public CCSlideInBTransition(float t, CCScene s) { 21 | super(t, s); 22 | } 23 | 24 | public void sceneOrder() { 25 | inSceneOnTop = true; 26 | } 27 | 28 | /** 29 | * initializes the scenes 30 | */ 31 | protected void initScenes() { 32 | CGSize s = CCDirector.sharedDirector().winSize(); 33 | inScene.setPosition(0,-(s.height-ADJUST_FACTOR)); 34 | } 35 | 36 | protected CCIntervalAction action() { 37 | CGSize s = CCDirector.sharedDirector().winSize(); 38 | return CCMoveBy.action(duration, CGPoint.make(0,s.height-ADJUST_FACTOR)); 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /src/org/cocos2d/actions/ease/CCEaseElasticIn.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.actions.ease; 2 | 3 | import org.cocos2d.actions.interval.CCIntervalAction; 4 | 5 | public class CCEaseElasticIn extends CCEaseElastic { 6 | 7 | public static CCEaseElasticIn action(CCIntervalAction action) { 8 | return new CCEaseElasticIn(action, 0.3f); 9 | } 10 | 11 | public static CCEaseElasticIn action(CCIntervalAction action, float period) { 12 | return new CCEaseElasticIn(action, period); 13 | } 14 | 15 | protected CCEaseElasticIn(CCIntervalAction action, float period) { 16 | super(action, period); 17 | } 18 | 19 | @Override 20 | public CCEaseAction copy() { 21 | return new CCEaseElasticIn(other.copy(), period_); 22 | } 23 | 24 | @Override 25 | public void update(float t) { 26 | float newT = 0; 27 | if (t == 0 || t == 1) { 28 | newT = t; 29 | 30 | } else { 31 | float s = period_ / 4; 32 | t = t - 1; 33 | newT = (float) (-Math.pow(2, 10 * t) * Math.sin((t - s) * M_PI_X_2 / period_)); 34 | } 35 | other.update(newT); 36 | } 37 | 38 | @Override 39 | public CCIntervalAction reverse() { 40 | return new CCEaseElasticOut(other.reverse(), period_); 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /src/org/cocos2d/transitions/CCSlideInTTransition.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.transitions; 2 | 3 | import org.cocos2d.actions.interval.CCIntervalAction; 4 | import org.cocos2d.actions.interval.CCMoveBy; 5 | import org.cocos2d.layers.CCScene; 6 | import org.cocos2d.nodes.CCDirector; 7 | import org.cocos2d.types.CGPoint; 8 | import org.cocos2d.types.CGSize; 9 | 10 | /** 11 | * SlideInT Transition. 12 | * Slide in the incoming scene from the top border. 13 | */ 14 | public class CCSlideInTTransition extends CCSlideInLTransition { 15 | 16 | public static CCSlideInTTransition transition(float t, CCScene s) { 17 | return new CCSlideInTTransition(t, s); 18 | } 19 | 20 | public CCSlideInTTransition(float t, CCScene s) { 21 | super(t, s); 22 | } 23 | 24 | public void sceneOrder() { 25 | inSceneOnTop = false; 26 | } 27 | 28 | /** 29 | * initializes the scenes 30 | */ 31 | protected void initScenes() { 32 | CGSize s = CCDirector.sharedDirector().winSize(); 33 | inScene.setPosition(0, s.height-ADJUST_FACTOR); 34 | } 35 | 36 | @Override 37 | public CCIntervalAction action() { 38 | CGSize s = CCDirector.sharedDirector().winSize(); 39 | return CCMoveBy.action(duration, CGPoint.make(0,-(s.height-ADJUST_FACTOR))); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /src/org/cocos2d/types/ccQuad2.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.types; 2 | 3 | //! A 2D Quad. 8 floats 4 | public class ccQuad2 { 5 | 6 | public static final int size = 4 * 2; 7 | 8 | public float tl_x, tl_y; 9 | public float tr_x, tr_y; 10 | public float bl_x, bl_y; 11 | public float br_x, br_y; 12 | 13 | public ccQuad2(float a, float b, float c, float d, float e, float f, float g, float h) { 14 | tl_x = a; 15 | tl_y = b; 16 | tr_x = c; 17 | tr_y = d; 18 | bl_x = e; 19 | bl_y = f; 20 | br_x = g; 21 | br_y = h; 22 | } 23 | 24 | public ccQuad2() { 25 | this(0, 0, 0, 0, 0, 0, 0, 0); 26 | } 27 | 28 | public ccQuad2(float[] f) { 29 | this(f[0], f[1], 30 | f[2], f[3], 31 | f[4], f[5], 32 | f[6], f[7] 33 | ); 34 | } 35 | 36 | public float[] toFloatArray() { 37 | return new float[]{tl_x, tl_y, 38 | tr_x, tr_y, 39 | bl_x, bl_y, 40 | br_x, br_y}; 41 | } 42 | 43 | public String toString() { 44 | return "CCQuad2: ( " + tl_x + ", " + tl_y + " " + 45 | tr_x + ", " + tr_y + " " + 46 | bl_x + ", " + bl_y + " " + 47 | br_x + ", " + br_y + " )"; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/org/cocos2d/transitions/CCSlideInRTransition.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.transitions; 2 | 3 | import org.cocos2d.actions.interval.CCIntervalAction; 4 | import org.cocos2d.actions.interval.CCMoveBy; 5 | import org.cocos2d.layers.CCScene; 6 | import org.cocos2d.nodes.CCDirector; 7 | import org.cocos2d.types.CGPoint; 8 | import org.cocos2d.types.CGSize; 9 | 10 | /** 11 | * SlideInR Transition. 12 | * Slide in the incoming scene from the right border. 13 | */ 14 | public class CCSlideInRTransition extends CCSlideInLTransition { 15 | 16 | public static CCSlideInRTransition transition(float t, CCScene s) { 17 | return new CCSlideInRTransition(t, s); 18 | } 19 | 20 | public CCSlideInRTransition(float t, CCScene s) { 21 | super(t, s); 22 | } 23 | 24 | @Override 25 | public void sceneOrder() { 26 | inSceneOnTop = true; 27 | } 28 | 29 | /** 30 | * initializes the scenes 31 | */ 32 | @Override 33 | protected void initScenes() { 34 | CGSize s = CCDirector.sharedDirector().winSize(); 35 | inScene.setPosition(s.width-ADJUST_FACTOR, 0); 36 | } 37 | 38 | @Override 39 | public CCIntervalAction action() { 40 | CGSize s = CCDirector.sharedDirector().winSize(); 41 | return CCMoveBy.action(duration, CGPoint.make(-(s.width-ADJUST_FACTOR),0)); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/org/cocos2d/actions/interval/CCProgressTo.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.actions.interval; 2 | 3 | import org.cocos2d.actions.CCProgressTimer; 4 | import org.cocos2d.nodes.CCNode; 5 | 6 | /** 7 | Progress to percentage 8 | @since v0.99.1 9 | */ 10 | public class CCProgressTo extends CCIntervalAction 11 | { 12 | float to_; 13 | float from_; 14 | 15 | /** Creates and initializes with a duration and a percent */ 16 | public static CCProgressTo action(float duration, float percent) { 17 | return new CCProgressTo(duration, percent); 18 | } 19 | 20 | /** Initializes with a duration and a percent */ 21 | protected CCProgressTo(float duration, float percent) { 22 | super(duration); 23 | to_ = percent; 24 | } 25 | 26 | @Override 27 | public CCProgressTo copy() { 28 | return new CCProgressTo(duration, to_); 29 | } 30 | 31 | @Override 32 | public void start(CCNode aTarget) { 33 | super.start(aTarget); 34 | from_ = ((CCProgressTimer)target).getPercentage(); 35 | 36 | // XXX: Is this correct ? 37 | // Adding it to support CCRepeat 38 | if( from_ == 100) 39 | from_ = 0; 40 | } 41 | 42 | @Override 43 | public void update(float t) { 44 | ((CCProgressTimer)target).setPercentage(from_ + ( to_ - from_ ) * t); 45 | } 46 | 47 | } 48 | 49 | -------------------------------------------------------------------------------- /src/org/cocos2d/actions/ease/CCEaseAction.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.actions.ease; 2 | 3 | import org.cocos2d.actions.interval.CCIntervalAction; 4 | import org.cocos2d.nodes.CCNode; 5 | 6 | 7 | /** Base class for Easing actions 8 | */ 9 | public class CCEaseAction extends CCIntervalAction { 10 | public static final float M_PI_X_2 = (float) (Math.PI * 2.0f); 11 | 12 | protected CCIntervalAction other; 13 | 14 | /** creates the action */ 15 | public static CCEaseAction action(CCIntervalAction action) { 16 | return new CCEaseAction(action); 17 | } 18 | 19 | /** initializes the action */ 20 | protected CCEaseAction(CCIntervalAction action) { 21 | super(action.getDuration()); 22 | other = action; 23 | } 24 | 25 | @Override 26 | public CCEaseAction copy() { 27 | return new CCEaseAction(other.copy()); 28 | } 29 | 30 | @Override 31 | public void start(CCNode aTarget) { 32 | super.start(aTarget); 33 | other.start(target); 34 | } 35 | 36 | @Override 37 | public void stop() { 38 | other.stop(); 39 | super.stop(); 40 | } 41 | 42 | @Override 43 | public void update(float t) { 44 | other.update(t); 45 | } 46 | 47 | @Override 48 | public CCIntervalAction reverse() { 49 | return new CCEaseAction(other.reverse()); 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /src/org/cocos2d/actions/grid/CCAccelAmplitude.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.actions.grid; 2 | 3 | import org.cocos2d.actions.interval.CCIntervalAction; 4 | import org.cocos2d.nodes.CCNode; 5 | 6 | //////////////////////////////////////////////////////////// 7 | 8 | /** CCAccelAmplitude action */ 9 | public class CCAccelAmplitude extends CCIntervalAction { 10 | /** amplitude rate */ 11 | float rate; 12 | 13 | CCIntervalAction other; 14 | 15 | /** creates the action with an inner action that has the amplitude property, 16 | * and a duration time */ 17 | public static CCAccelAmplitude action(CCIntervalAction action, float d) { 18 | return new CCAccelAmplitude(action, d); 19 | } 20 | 21 | /** initializes the action with an inner action that has the amplitude property, 22 | * and a duration time */ 23 | public CCAccelAmplitude (CCIntervalAction action, float d) { 24 | super(d); 25 | 26 | rate = 1.0f; 27 | other = action; 28 | } 29 | 30 | @Override 31 | public void start(CCNode aTarget) { 32 | super.start(aTarget); 33 | other.start(target); 34 | } 35 | 36 | @Override 37 | public void update(float time) { 38 | other.setAmplitudeRate((float)Math.pow(time, rate)); 39 | other.update(time); 40 | } 41 | 42 | @Override 43 | public CCIntervalAction reverse() { 44 | return CCAccelAmplitude.action(other.reverse(), duration); 45 | } 46 | 47 | } 48 | 49 | -------------------------------------------------------------------------------- /src/org/cocos2d/protocols/CCRGBAProtocol.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.protocols; 2 | 3 | import org.cocos2d.types.ccColor3B; 4 | 5 | 6 | /// CC RGBA protocol 7 | public interface CCRGBAProtocol { 8 | /** sets Color 9 | @since v0.8 10 | */ 11 | public void setColor(ccColor3B color); 12 | 13 | /** returns the color 14 | @since v0.8 15 | */ 16 | public ccColor3B getColor(); 17 | 18 | /// returns the opacity 19 | public int getOpacity(); 20 | 21 | /** sets the opacity. 22 | @warning If the the texture has premultiplied alpha then, the R, G and B channels will be modifed. 23 | Values goes from 0 to 255, where 255 means fully opaque. 24 | */ 25 | public void setOpacity(int opacity); 26 | 27 | /** sets the premultipliedAlphaOpacity property. 28 | If set to NO then opacity will be applied as: glColor(R,G,B,opacity); 29 | If set to YES then oapcity will be applied as: glColor(opacity, opacity, opacity, opacity ); 30 | Textures with premultiplied alpha will have this property by default on YES. 31 | Otherwise the default value is NO 32 | @since v0.8 33 | */ 34 | public void setOpacityModifyRGB(boolean b); 35 | 36 | /** returns whether or not the opacity will be applied using glColor(R,G,B,opacity) 37 | or glColor(opacity, opacity, opacity, opacity); 38 | @since v0.8 39 | */ 40 | public boolean doesOpacityModifyRGB(); 41 | } 42 | 43 | -------------------------------------------------------------------------------- /src/org/cocos2d/actions/tile/CCFadeOutUpTiles.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.actions.tile; 2 | 3 | import org.cocos2d.types.CGPoint; 4 | import org.cocos2d.types.ccGridSize; 5 | import org.cocos2d.types.ccQuad3; 6 | 7 | //////////////////////////////////////////////////////////// 8 | 9 | /** CCFadeOutUpTiles action. 10 | Fades out the tiles in upwards direction 11 | */ 12 | public class CCFadeOutUpTiles extends CCFadeOutTRTiles { 13 | public static CCFadeOutUpTiles action(ccGridSize gSize, float d) { 14 | return new CCFadeOutUpTiles(gSize, d); 15 | } 16 | 17 | protected CCFadeOutUpTiles(ccGridSize gSize, float d) { 18 | super(gSize, d); 19 | } 20 | 21 | 22 | @Override 23 | public float testFunc(ccGridSize pos, float time) { 24 | CGPoint n = CGPoint.ccpMult(CGPoint.ccp(gridSize.x, gridSize.y), time); 25 | if ( n.y == 0 ) 26 | return 1.0f; 27 | return (float)Math.pow( pos.y / n.y, 6 ); 28 | } 29 | 30 | @Override 31 | public void transformTile(ccGridSize pos, float distance) { 32 | ccQuad3 coords = originalTile(pos); 33 | CGPoint step = target.getGrid().getStep(); 34 | 35 | coords.bl_y += (step.y / 2) * (1.0f - distance); 36 | coords.br_y += (step.y / 2) * (1.0f - distance); 37 | coords.tl_y -= (step.y / 2) * (1.0f - distance); 38 | coords.tr_y -= (step.y / 2) * (1.0f - distance); 39 | 40 | setTile(pos, coords); 41 | } 42 | 43 | } 44 | 45 | -------------------------------------------------------------------------------- /src/org/cocos2d/actions/grid/CCDeccelAmplitude.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.actions.grid; 2 | 3 | import org.cocos2d.actions.interval.CCIntervalAction; 4 | import org.cocos2d.nodes.CCNode; 5 | 6 | //////////////////////////////////////////////////////////// 7 | 8 | /** CCDeccelAmplitude action */ 9 | public class CCDeccelAmplitude extends CCIntervalAction { 10 | /** amplitude rate */ 11 | float rate; 12 | CCIntervalAction other; 13 | 14 | public void setRate(float r){ 15 | rate = r; 16 | } 17 | public float getRate() { 18 | return rate; 19 | } 20 | 21 | /** creates the action with an inner action that has the amplitude property, and a duration time */ 22 | public static CCDeccelAmplitude action(CCIntervalAction action, float d) { 23 | return new CCDeccelAmplitude(action, d); 24 | } 25 | /** initializes the action with an inner action that has the amplitude property, and a duration time */ 26 | public CCDeccelAmplitude(CCIntervalAction action, float d) { 27 | super(d); 28 | rate = 1.0f; 29 | other = action; 30 | } 31 | 32 | @Override 33 | public void start(CCNode aTarget) { 34 | super.start(aTarget); 35 | other.start(target); 36 | } 37 | 38 | @Override 39 | public void update(float time) { 40 | other.setAmplitudeRate((float)Math.pow((1-time), rate)); 41 | other.update(time); 42 | } 43 | 44 | @Override 45 | public CCIntervalAction reverse() { 46 | return CCDeccelAmplitude.action(other.reverse(), duration); 47 | } 48 | 49 | } 50 | 51 | -------------------------------------------------------------------------------- /src/org/cocos2d/actions/grid/CCAccelDeccelAmplitude.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.actions.grid; 2 | 3 | import org.cocos2d.actions.interval.CCIntervalAction; 4 | import org.cocos2d.nodes.CCNode; 5 | 6 | //////////////////////////////////////////////////////////// 7 | 8 | /** CCAccelDeccelAmplitude action */ 9 | public class CCAccelDeccelAmplitude extends CCIntervalAction { 10 | /** amplitude rate */ 11 | float rate; 12 | 13 | CCIntervalAction other; 14 | 15 | 16 | /** creates the action with an inner action that has the amplitude property, and a duration time */ 17 | public static CCAccelDeccelAmplitude action(CCIntervalAction action, float d) { 18 | return new CCAccelDeccelAmplitude(action, d); 19 | } 20 | 21 | /** initializes the action with an inner action that has the amplitude property, and a duration time */ 22 | public CCAccelDeccelAmplitude(CCIntervalAction action, float d) { 23 | super(d); 24 | rate = 1.0f; 25 | other = action; 26 | } 27 | 28 | @Override 29 | public void start(CCNode aTarget) { 30 | super.start(aTarget); 31 | other.start(target); 32 | } 33 | 34 | @Override 35 | public void update(float time) { 36 | float f = time * 2; 37 | 38 | if (f > 1) { 39 | f -= 1; 40 | f = 1 - f; 41 | } 42 | 43 | other.setAmplitudeRate((float)Math.pow(f, rate)); 44 | other.update(time); 45 | } 46 | 47 | @Override 48 | public CCIntervalAction reverse() { 49 | return CCAccelDeccelAmplitude.action(other.reverse(), duration); 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /src/org/cocos2d/actions/grid/CCShaky3D.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.actions.grid; 2 | 3 | import org.cocos2d.types.CCVertex3D; 4 | import org.cocos2d.types.ccGridSize; 5 | 6 | //////////////////////////////////////////////////////////// 7 | 8 | /** CCShaky3D action */ 9 | public class CCShaky3D extends CCGrid3DAction { 10 | int randrange; 11 | boolean shakeZ; 12 | 13 | 14 | /** creates the action with a range, shake Z vertices, a grid and duration */ 15 | public static CCShaky3D action(int range, boolean sz, ccGridSize gridSize, float d) { 16 | return new CCShaky3D(range, sz, gridSize, d); 17 | } 18 | 19 | /** initializes the action with a range, shake Z vertices, a grid and duration */ 20 | public CCShaky3D(int range, boolean sz, ccGridSize gSize, float d) { 21 | super(gSize, d); 22 | randrange = range; 23 | shakeZ = sz; 24 | } 25 | 26 | @Override 27 | public CCShaky3D copy() { 28 | CCShaky3D copy = new CCShaky3D(randrange, shakeZ, gridSize, duration); 29 | return copy; 30 | } 31 | 32 | @Override 33 | public void update(float time) { 34 | int i, j; 35 | 36 | for( i = 0; i < (gridSize.x+1); i++ ) { 37 | for( j = 0; j < (gridSize.y+1); j++ ) { 38 | CCVertex3D v = originalVertex(ccGridSize.ccg(i,j)); 39 | float r = (float)Math.random() * (randrange*2); 40 | v.x += r - randrange; 41 | v.y += r - randrange; 42 | if( shakeZ ) 43 | v.z += r - randrange; 44 | 45 | setVertex(ccGridSize.ccg(i,j), v); 46 | } 47 | } 48 | } 49 | 50 | } 51 | 52 | -------------------------------------------------------------------------------- /src/org/cocos2d/actions/interval/CCProgressFromTo.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.actions.interval; 2 | 3 | import org.cocos2d.actions.CCProgressTimer; 4 | import org.cocos2d.nodes.CCNode; 5 | 6 | /** 7 | Progress from a percentage to another percentage 8 | @since v0.99.1 9 | */ 10 | public class CCProgressFromTo extends CCIntervalAction { 11 | float to_; 12 | float from_; 13 | 14 | /** Creates and initializes the action with a duration, a "from" percentage and a "to" percentage */ 15 | public static CCProgressFromTo action(float t, float fromPercentage, float toPercentage) { 16 | return new CCProgressFromTo(t, fromPercentage, toPercentage); 17 | } 18 | 19 | /** Initializes the action with a duration, a "from" percentage and a "to" percentage */ 20 | protected CCProgressFromTo(float t, float fromPercentage, float toPercentage) { 21 | super(t); 22 | to_ = toPercentage; 23 | from_ = fromPercentage; 24 | } 25 | 26 | @Override 27 | public CCProgressFromTo copy() { 28 | return new CCProgressFromTo(duration, from_, to_); 29 | } 30 | 31 | @Override 32 | public CCProgressFromTo reverse() { 33 | return new CCProgressFromTo(duration, to_, from_); 34 | } 35 | 36 | @Override 37 | public void start(CCNode aTarget) { 38 | super.start(aTarget); 39 | } 40 | 41 | @Override 42 | public void update(float t) { 43 | ((CCProgressTimer)target).setPercentage(from_ + ( to_ - from_ ) * t); 44 | } 45 | } 46 | 47 | -------------------------------------------------------------------------------- /src/org/cocos2d/actions/base/CCFiniteTimeAction.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.actions.base; 2 | 3 | import org.cocos2d.config.ccMacros; 4 | 5 | /** Base class actions that do have a finite time duration. 6 | Possible actions: 7 | - An action with a duration of 0 seconds 8 | - An action with a duration of 35.5 seconds 9 | Infitite time actions are valid 10 | */ 11 | public class CCFiniteTimeAction extends CCAction { 12 | private static final String LOG_TAG = CCFiniteTimeAction.class.getSimpleName(); 13 | 14 | // ! duration in seconds of the action 15 | protected float duration; 16 | 17 | public static CCFiniteTimeAction action(float d) { 18 | return new CCFiniteTimeAction(d); 19 | } 20 | 21 | protected CCFiniteTimeAction(float d) { 22 | duration = d; 23 | } 24 | 25 | public float getDuration() { 26 | return duration; 27 | } 28 | 29 | public void setDuration(float duration) { 30 | this.duration = duration; 31 | } 32 | 33 | @Override 34 | public CCFiniteTimeAction copy() { 35 | return new CCFiniteTimeAction(duration); 36 | } 37 | 38 | /** returns a reversed action */ 39 | public CCFiniteTimeAction reverse() { 40 | ccMacros.CCLOG(LOG_TAG, "Override me"); 41 | return null; 42 | } 43 | 44 | @Override 45 | public void step(float dt) { 46 | // TODO Auto-generated method stub 47 | } 48 | 49 | @Override 50 | public void update(float time) { 51 | // TODO Auto-generated method stub 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/org/cocos2d/actions/interval/CCTintTo.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.actions.interval; 2 | 3 | import org.cocos2d.nodes.CCNode; 4 | import org.cocos2d.protocols.CCRGBAProtocol; 5 | import org.cocos2d.types.ccColor3B; 6 | 7 | /** Tints a CCNode that implements the CCNodeRGB protocol from current tint to a custom one. 8 | @warning This action doesn't support "reverse" 9 | @since v0.7.2 10 | */ 11 | public class CCTintTo extends CCIntervalAction { 12 | protected ccColor3B to; 13 | protected ccColor3B from; 14 | 15 | /** creates an action with duration and color */ 16 | public static CCTintTo action(float t, ccColor3B c) { 17 | return new CCTintTo(t, c); 18 | } 19 | 20 | /** initializes the action with duration and color */ 21 | protected CCTintTo(float t, ccColor3B c) { 22 | super(t); 23 | to = new ccColor3B(c); 24 | } 25 | 26 | @Override 27 | public CCTintTo copy() { 28 | return new CCTintTo(duration, to); 29 | } 30 | 31 | @Override 32 | public void start(CCNode aTarget) { 33 | super.start(aTarget); 34 | 35 | CCRGBAProtocol tn = (CCRGBAProtocol) target; 36 | 37 | from = tn.getColor(); 38 | } 39 | 40 | @Override 41 | public void update(float t) { 42 | ((CCRGBAProtocol) target).setColor( 43 | new ccColor3B((int) (from.r + (to.r - from.r) * t), 44 | (int) (from.g + (to.g - from.g) * t), 45 | (int) (from.b + (to.b - from.b) * t))); 46 | } 47 | } 48 | 49 | -------------------------------------------------------------------------------- /src/org/cocos2d/actions/grid/CCLiquid.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.actions.grid; 2 | 3 | import org.cocos2d.types.CCVertex3D; 4 | import org.cocos2d.types.ccGridSize; 5 | 6 | //////////////////////////////////////////////////////////// 7 | 8 | /** CCLiquid action */ 9 | public class CCLiquid extends CCGrid3DAction { 10 | int waves; 11 | /** amplitude */ 12 | float amplitude; 13 | /** amplitude rate */ 14 | float amplitudeRate; 15 | 16 | /** creates the action with amplitude, a grid and duration */ 17 | public static CCLiquid action(int wav, float amp, ccGridSize gridSize, float d) { 18 | return new CCLiquid(wav, amp, gridSize, d); 19 | } 20 | 21 | /** initializes the action with amplitude, a grid and duration */ 22 | public CCLiquid(int wav, float amp, ccGridSize gSize, float d) { 23 | super(gSize, d); 24 | waves = wav; 25 | amplitude = amp; 26 | amplitudeRate = 1.0f; 27 | } 28 | 29 | @Override 30 | public void update(float time) { 31 | int i, j; 32 | 33 | for( i = 1; i < gridSize.x; i++ ) { 34 | for( j = 1; j < gridSize.y; j++ ) { 35 | CCVertex3D v = originalVertex(ccGridSize.ccg(i,j)); 36 | v.x = (float)(v.x + (Math.sin(time*Math.PI*waves*2 + v.x * .01f) * amplitude * amplitudeRate)); 37 | v.y = (float)(v.y + (Math.sin(time*Math.PI*waves*2 + v.y * .01f) * amplitude * amplitudeRate)); 38 | setVertex(ccGridSize.ccg(i,j), v); 39 | } 40 | } 41 | } 42 | 43 | @Override 44 | public CCLiquid copy() { 45 | CCLiquid copy = new CCLiquid(waves, amplitude, gridSize, duration); 46 | return copy; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/org/cocos2d/menus/CCMenuItemAtlasFont.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.menus; 2 | 3 | import org.cocos2d.nodes.CCLabelAtlas; 4 | import org.cocos2d.nodes.CCNode; 5 | 6 | /** A CCMenuItemAtlasFont 7 | Helper class that creates a MenuItemLabel class with a LabelAtlas 8 | */ 9 | public class CCMenuItemAtlasFont extends CCMenuItemLabel { 10 | 11 | /** creates a menu item from a string and atlas with a target/selector */ 12 | public static CCMenuItemAtlasFont item(CharSequence value, String charMapFile, int itemWidth, int itemHeight, char startCharMap) { 13 | assert value.length() != 0 :"value length must be greater than 0"; 14 | 15 | CCLabelAtlas label = CCLabelAtlas.label(value, charMapFile, itemWidth, itemHeight, startCharMap); 16 | return new CCMenuItemAtlasFont(label, null, null); 17 | } 18 | 19 | /** creates a menu item from a string and atlas. Use it with MenuItemToggle */ 20 | public static CCMenuItemAtlasFont item(CharSequence value, String charMapFile, int itemWidth, int itemHeight, char startCharMap, CCNode rec, String cb) { 21 | assert value.length() != 0 :"value length must be greater than 0"; 22 | 23 | CCLabelAtlas label = CCLabelAtlas.label(value, charMapFile, itemWidth, itemHeight, startCharMap); 24 | return new CCMenuItemAtlasFont(label, rec, cb); 25 | } 26 | 27 | /** initializes a menu item from a string and atlas with a target/selector */ 28 | protected CCMenuItemAtlasFont(CCLabelAtlas label, CCNode rec, String cb) { 29 | super(label, rec, cb); 30 | } 31 | } 32 | 33 | -------------------------------------------------------------------------------- /src/org/cocos2d/actions/camera/CCCameraAction.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.actions.camera; 2 | 3 | import org.cocos2d.actions.interval.CCIntervalAction; 4 | import org.cocos2d.actions.interval.CCReverseTime; 5 | import org.cocos2d.nodes.CCNode; 6 | 7 | /** Base class for CCCamera actions 8 | */ 9 | public abstract class CCCameraAction extends CCIntervalAction { 10 | protected float centerXOrig; 11 | protected float centerYOrig; 12 | protected float centerZOrig; 13 | 14 | protected float eyeXOrig; 15 | protected float eyeYOrig; 16 | protected float eyeZOrig; 17 | 18 | protected float upXOrig; 19 | protected float upYOrig; 20 | protected float upZOrig; 21 | 22 | protected CCCameraAction(float t) { 23 | super(t); 24 | } 25 | 26 | @Override 27 | public void start(CCNode aTarget) { 28 | super.start(aTarget); 29 | 30 | float x[] = new float[1]; 31 | float y[] = new float[1]; 32 | float z[] = new float[1]; 33 | 34 | target.getCamera().getCenter(x, y, z); 35 | centerXOrig = x[0]; 36 | centerYOrig = y[0]; 37 | centerZOrig = z[0]; 38 | 39 | target.getCamera().getEye(x, y, z); 40 | eyeXOrig = x[0]; 41 | eyeYOrig = y[0]; 42 | eyeZOrig = z[0]; 43 | 44 | target.getCamera().getUp(x, y, z); 45 | upXOrig = x[0]; 46 | upYOrig = y[0]; 47 | upZOrig = z[0]; 48 | } 49 | 50 | @Override 51 | public CCReverseTime reverse() { 52 | return CCReverseTime.action(this); 53 | } 54 | 55 | } 56 | 57 | -------------------------------------------------------------------------------- /src/org/cocos2d/actions/interval/CCReverseTime.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.actions.interval; 2 | 3 | import org.cocos2d.actions.base.CCFiniteTimeAction; 4 | import org.cocos2d.nodes.CCNode; 5 | 6 | /** Executes an action in reverse order, from time=duration to time=0 7 | 8 | @warning Use this action carefully. This action is not 9 | sequenceable. Use it as the default "reversed" method 10 | of your own actions, but using it outside the "reversed" 11 | scope is not recommended. 12 | */ 13 | public class CCReverseTime extends CCIntervalAction { 14 | private CCFiniteTimeAction other; 15 | 16 | /** creates the action */ 17 | public static CCReverseTime action(CCFiniteTimeAction action) { 18 | return new CCReverseTime(action); 19 | } 20 | 21 | /** initializes the action */ 22 | protected CCReverseTime(CCFiniteTimeAction action) { 23 | super(action.getDuration()); 24 | 25 | other = action; 26 | } 27 | 28 | @Override 29 | public CCReverseTime copy() { 30 | return new CCReverseTime(other.copy()); 31 | } 32 | 33 | @Override 34 | public void start(CCNode aTarget) { 35 | super.start(aTarget); 36 | other.start(target); 37 | } 38 | 39 | @Override 40 | public void stop() { 41 | other.stop(); 42 | super.stop(); 43 | } 44 | 45 | @Override 46 | public void update(float t) { 47 | other.update(1 - t); 48 | } 49 | 50 | @Override 51 | public CCReverseTime reverse() { 52 | return new CCReverseTime(other.copy()); 53 | } 54 | } 55 | 56 | -------------------------------------------------------------------------------- /src/org/cocos2d/actions/interval/CCRotateTo.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.actions.interval; 2 | 3 | import org.cocos2d.nodes.CCNode; 4 | 5 | /** Rotates a CCNode object to a certain angle by modifying it's 6 | rotation attribute. 7 | The direction will be decided by the shortest angle. 8 | */ 9 | 10 | public class CCRotateTo extends CCIntervalAction { 11 | private float dstAngle; 12 | private float diffAngle; 13 | private float startAngle; 14 | 15 | /** creates the action */ 16 | public static CCRotateTo action(float duration, float ang) { 17 | return new CCRotateTo(duration, ang); 18 | } 19 | 20 | /** initializes the action */ 21 | protected CCRotateTo(float duration, float ang) { 22 | super(duration); 23 | dstAngle = ang; 24 | } 25 | 26 | @Override 27 | public CCRotateTo copy() { 28 | return new CCRotateTo(duration, dstAngle); 29 | } 30 | 31 | @Override 32 | public void start(CCNode aTarget) { 33 | super.start(aTarget); 34 | startAngle = target.getRotation(); 35 | if (startAngle > 0) 36 | startAngle = (float) (startAngle % 360.0f); 37 | else 38 | startAngle = (float) (startAngle % -360.0f); 39 | 40 | diffAngle = dstAngle - startAngle; 41 | if (diffAngle > 180) 42 | diffAngle -= 360; 43 | if (diffAngle < -180) 44 | diffAngle += 360; 45 | } 46 | 47 | @Override 48 | public void update(float t) { 49 | target.setRotation(startAngle + diffAngle * t); 50 | } 51 | 52 | } 53 | 54 | -------------------------------------------------------------------------------- /src/org/cocos2d/types/ccQuad3.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.types; 2 | 3 | //! A 3D Quad. 12 floats 4 | public class ccQuad3 { 5 | 6 | public static final int size = 4 * 3; 7 | 8 | public float bl_x, bl_y, bl_z; 9 | public float br_x, br_y, br_z; 10 | public float tl_x, tl_y, tl_z; 11 | public float tr_x, tr_y, tr_z; 12 | 13 | public ccQuad3() { 14 | this(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); 15 | } 16 | 17 | public ccQuad3(float[] f) { 18 | this(f[0], f[1], f[2], 19 | f[3], f[4], f[5], 20 | f[6], f[7], f[8], 21 | f[9], f[10], f[11] 22 | ); 23 | } 24 | 25 | public ccQuad3(float a, float b, float c, float d, float e, float f, float g, float h, float i, float j, float k, float l) { 26 | bl_x = a; 27 | bl_y = b; 28 | bl_z = c; 29 | br_x = d; 30 | br_y = e; 31 | br_z = f; 32 | tl_x = g; 33 | tl_y = h; 34 | tl_z = i; 35 | tr_x = j; 36 | tr_y = k; 37 | tr_z = l; 38 | } 39 | 40 | public float[] toFloatArray() { 41 | return new float[]{bl_x, bl_y, bl_z, 42 | br_x, br_y, br_z, 43 | tl_x, tl_y, tl_z, 44 | tr_x, tr_y, tr_z}; 45 | } 46 | 47 | public String toString() { 48 | return "CCQuad3: ( " + tl_x + ", " + tl_y + ", " + tl_z + " " + 49 | tr_x + ", " + tr_y + ", " + tl_z + " " + 50 | bl_x + ", " + bl_y + ", " + tl_z + " " + 51 | br_x + ", " + br_y + ", " + tl_z + " )"; 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/org/cocos2d/transitions/CCShrinkGrowTransition.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.transitions; 2 | 3 | import org.cocos2d.actions.ease.CCEaseOut; 4 | import org.cocos2d.actions.instant.CCCallFunc; 5 | import org.cocos2d.actions.interval.CCIntervalAction; 6 | import org.cocos2d.actions.interval.CCScaleTo; 7 | import org.cocos2d.actions.interval.CCSequence; 8 | import org.cocos2d.layers.CCScene; 9 | 10 | /** 11 | * Shrink the outgoing scene while grow the incoming scene 12 | */ 13 | public class CCShrinkGrowTransition extends CCTransitionScene implements CCTransitionEaseScene { 14 | 15 | public static CCShrinkGrowTransition transition(float t, CCScene s) { 16 | return new CCShrinkGrowTransition(t, s); 17 | } 18 | 19 | public CCShrinkGrowTransition(float t, CCScene s) { 20 | super(t, s); 21 | } 22 | 23 | @Override 24 | public void onEnter() { 25 | super.onEnter(); 26 | 27 | inScene.setScale(0.001f); 28 | outScene.setScale(1.0f); 29 | 30 | inScene.setAnchorPoint(2/3.0f, 0.5f); 31 | outScene.setAnchorPoint(1/3.0f, 0.5f); 32 | 33 | CCIntervalAction scaleOut = CCScaleTo.action(duration, 0.01f); 34 | CCIntervalAction scaleIn = CCScaleTo.action(duration, 1.0f); 35 | 36 | inScene.runAction(easeAction(scaleIn)); 37 | outScene.runAction(CCSequence.actions( 38 | easeAction(scaleOut), 39 | CCCallFunc.action(this, "finish"))); 40 | } 41 | 42 | public CCIntervalAction easeAction(CCIntervalAction action) { 43 | return CCEaseOut.action(action, 2.0f); 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /src/org/cocos2d/actions/ease/CCEaseElasticInOut.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.actions.ease; 2 | 3 | import org.cocos2d.actions.interval.CCIntervalAction; 4 | 5 | public class CCEaseElasticInOut extends CCEaseElastic { 6 | 7 | public static CCEaseElasticInOut action(CCIntervalAction action) { 8 | return new CCEaseElasticInOut(action, 0.3f); 9 | } 10 | 11 | public static CCEaseElasticInOut action(CCIntervalAction action, float period) { 12 | return new CCEaseElasticInOut(action, period); 13 | } 14 | 15 | protected CCEaseElasticInOut(CCIntervalAction action, float period) { 16 | super(action, period); 17 | } 18 | 19 | @Override 20 | public CCEaseAction copy() { 21 | return new CCEaseElasticInOut(other.copy(), period_); 22 | } 23 | 24 | public void update(float t) { 25 | float newT = 0; 26 | 27 | if (t == 0 || t == 1) 28 | newT = t; 29 | else { 30 | t = t * 2; 31 | if (period_ == 0) 32 | period_ = 0.3f * 1.5f; 33 | float s = period_ / 4; 34 | 35 | t = t - 1; 36 | if (t < 0) { 37 | newT = (float) (-0.5f * Math.pow(2, 10 * t) * Math.sin((t - s) * M_PI_X_2 / period_)); 38 | } else { 39 | newT = (float) (Math.pow(2, -10 * t) * Math.sin((t - s) * M_PI_X_2 / period_) * 0.5f + 1); 40 | } 41 | } 42 | other.update(newT); 43 | } 44 | 45 | @Override 46 | public CCIntervalAction reverse() { 47 | return new CCEaseElasticInOut(other.reverse(), period_); 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /src/org/cocos2d/actions/tile/CCTiledGrid3DAction.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.actions.tile; 2 | 3 | import org.cocos2d.actions.grid.CCGridAction; 4 | import org.cocos2d.grid.CCGridBase; 5 | import org.cocos2d.grid.CCTiledGrid3D; 6 | import org.cocos2d.types.ccGridSize; 7 | import org.cocos2d.types.ccQuad3; 8 | 9 | //////////////////////////////////////////////////////////// 10 | 11 | /** Base class for CCTiledGrid3D actions */ 12 | public class CCTiledGrid3DAction extends CCGridAction { 13 | public static CCTiledGrid3DAction action(ccGridSize gSize, float d) { 14 | return new CCTiledGrid3DAction(gSize, d); 15 | } 16 | 17 | protected CCTiledGrid3DAction(ccGridSize gSize, float d) { 18 | super(gSize, d); 19 | } 20 | 21 | public CCGridBase grid() { 22 | return CCTiledGrid3D.make(gridSize); 23 | } 24 | 25 | /** returns the tile that belongs to a certain position of the grid */ 26 | public ccQuad3 tile(ccGridSize pos) { 27 | CCTiledGrid3D g = (CCTiledGrid3D)target.getGrid(); 28 | return g.tile(pos); 29 | } 30 | 31 | /** returns the non-transformed tile that belongs to a certain position of the grid */ 32 | public ccQuad3 originalTile(ccGridSize pos) { 33 | CCTiledGrid3D g = (CCTiledGrid3D)target.getGrid(); 34 | return g.originalTile(pos); 35 | } 36 | 37 | /** sets a new tile to a certain position of the grid */ 38 | public void setTile(ccGridSize pos, ccQuad3 coords) { 39 | CCTiledGrid3D g = (CCTiledGrid3D)target.getGrid(); 40 | g.setTile(pos, coords); 41 | } 42 | 43 | @Override 44 | public CCTiledGrid3DAction copy() { 45 | return new CCTiledGrid3DAction(getGridSize(), getDuration()); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/org/cocos2d/transitions/CCRotoZoomTransition.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.transitions; 2 | 3 | import org.cocos2d.actions.instant.CCCallFunc; 4 | import org.cocos2d.actions.interval.CCDelayTime; 5 | import org.cocos2d.actions.interval.CCIntervalAction; 6 | import org.cocos2d.actions.interval.CCRotateBy; 7 | import org.cocos2d.actions.interval.CCScaleBy; 8 | import org.cocos2d.actions.interval.CCSequence; 9 | import org.cocos2d.actions.interval.CCSpawn; 10 | import org.cocos2d.layers.CCScene; 11 | 12 | /** 13 | * RotoZoom Transition. 14 | * Rotate and zoom out the outgoing scene, and then rotate and zoom in the incoming 15 | */ 16 | public class CCRotoZoomTransition extends CCTransitionScene { 17 | 18 | public static CCRotoZoomTransition transition(float t, CCScene s) { 19 | return new CCRotoZoomTransition(t, s); 20 | } 21 | 22 | public CCRotoZoomTransition(float t, CCScene s) { 23 | super(t, s); 24 | } 25 | 26 | @Override 27 | public void onEnter() { 28 | super.onEnter(); 29 | 30 | inScene.setScale(0.001f); 31 | outScene.setScale(1.0f); 32 | 33 | inScene.setAnchorPoint(0.5f, 0.5f); 34 | outScene.setAnchorPoint(0.5f, 0.5f); 35 | 36 | CCIntervalAction rotozoom = CCSequence.actions( 37 | CCSpawn.actions(CCScaleBy.action(duration / 2, 0.001f), 38 | CCRotateBy.action(duration / 2, 360 * 2) 39 | ), 40 | CCDelayTime.action(duration / 2)); 41 | 42 | 43 | outScene.runAction(rotozoom); 44 | inScene.runAction(CCSequence.actions(rotozoom.reverse(), 45 | CCCallFunc.action(this, "finish"))); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/org/cocos2d/layers/CCTMXObjectGroup.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.layers; 2 | 3 | import java.util.ArrayList; 4 | import java.util.HashMap; 5 | 6 | import org.cocos2d.types.CGPoint; 7 | 8 | /* 9 | * 10 | * 11 | * TMX Tiled Map support: 12 | * http://www.mapeditor.org 13 | * 14 | */ 15 | 16 | 17 | /** CCTMXObjectGroup represents the TMX object group. 18 | @since v0.99.0 19 | */ 20 | public class CCTMXObjectGroup { 21 | /** name of the group */ 22 | public String groupName; 23 | 24 | /** offset position of child objects */ 25 | public CGPoint positionOffset; 26 | 27 | /** array of the objects */ 28 | public ArrayList > objects; 29 | 30 | 31 | /** list of properties stored in a dictionary */ 32 | public HashMap properties; 33 | 34 | 35 | /** return the value for the specific property name */ 36 | public Object propertyNamed(String propertyName) { 37 | return properties.get(propertyName); 38 | } 39 | 40 | 41 | /** return the dictionary for the specific object name. 42 | It will return the 1st object found on the array for the given name. 43 | */ 44 | public HashMap objectNamed(String objectName) { 45 | for (HashMap object : objects) { 46 | if (object.get("name").equals(objectName)) 47 | return object; 48 | } 49 | 50 | // object not found 51 | return null; 52 | } 53 | 54 | public CCTMXObjectGroup() { 55 | super(); 56 | 57 | groupName = null; 58 | positionOffset = CGPoint.zero(); 59 | objects = new ArrayList >(); 60 | properties = new HashMap(); 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /src/org/cocos2d/actions/interval/CCTintBy.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.actions.interval; 2 | 3 | import org.cocos2d.nodes.CCNode; 4 | import org.cocos2d.protocols.CCRGBAProtocol; 5 | import org.cocos2d.types.ccColor3B; 6 | 7 | /** Tints a CCNode that implements the CCNodeRGB protocol from current tint to a custom one. 8 | @since v0.7.2 9 | */ 10 | public class CCTintBy extends CCIntervalAction { 11 | protected ccColor3B delta; 12 | protected ccColor3B from; 13 | 14 | /** creates an action with duration and color */ 15 | public static CCTintBy action(float t, ccColor3B c) { 16 | return new CCTintBy(t, c); 17 | } 18 | 19 | /** initializes the action with duration and color */ 20 | protected CCTintBy(float t, ccColor3B c) { 21 | super(t); 22 | delta = new ccColor3B(c); 23 | } 24 | 25 | @Override 26 | public CCTintBy copy() { 27 | return new CCTintBy(duration, delta); 28 | } 29 | 30 | @Override 31 | public void start(CCNode aTarget) { 32 | super.start(aTarget); 33 | 34 | ccColor3B c = ((CCRGBAProtocol) target).getColor(); 35 | from = new ccColor3B(c); 36 | } 37 | 38 | @Override 39 | public void update(float t) { 40 | CCRGBAProtocol tn = (CCRGBAProtocol) target; 41 | tn.setColor(new ccColor3B((int) (from.r + delta.r * t), 42 | (int) (from.g + delta.g * t), 43 | (int) (from.b + delta.b * t))); 44 | } 45 | 46 | @Override 47 | public CCTintBy reverse() { 48 | return new CCTintBy(duration, new ccColor3B(-delta.r, -delta.g, -delta.b)); 49 | } 50 | } 51 | 52 | -------------------------------------------------------------------------------- /src/org/cocos2d/actions/grid/CCGrid3DAction.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.actions.grid; 2 | 3 | import org.cocos2d.grid.CCGrid3D; 4 | import org.cocos2d.grid.CCGridBase; 5 | import org.cocos2d.types.CCVertex3D; 6 | import org.cocos2d.types.ccGridSize; 7 | 8 | /** Base class for CCGrid3D actions. 9 | Grid3D actions can modify a non-tiled grid. 10 | */ 11 | public class CCGrid3DAction extends CCGridAction { 12 | 13 | public static CCGrid3DAction action(ccGridSize gSize, float d) { 14 | return new CCGrid3DAction(gSize, d); 15 | } 16 | 17 | protected CCGrid3DAction(ccGridSize gSize, float d) { 18 | super(gSize, d); 19 | } 20 | 21 | public CCGridBase grid() { 22 | return new CCGrid3D(gridSize); 23 | } 24 | 25 | /** returns the vertex than belongs to certain position 26 | * in the grid */ 27 | public CCVertex3D vertex(ccGridSize pos) { 28 | CCGrid3D g = (CCGrid3D) target.getGrid(); 29 | return g.vertex(pos); 30 | } 31 | 32 | /** returns the non-transformed vertex than belongs to 33 | * certain position in the grid */ 34 | public CCVertex3D originalVertex(ccGridSize pos) { 35 | CCGrid3D g = (CCGrid3D) target.getGrid(); 36 | return g.originalVertex(pos); 37 | } 38 | 39 | /** sets a new vertex to a certain position of the grid */ 40 | public void setVertex(ccGridSize pos, CCVertex3D vertex) { 41 | CCGrid3D g = (CCGrid3D) target.getGrid(); 42 | g.setVertex(pos, vertex); 43 | } 44 | 45 | @Override 46 | public CCGrid3DAction copy() { 47 | return new CCGrid3DAction(getGridSize(), getDuration()); 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /src/org/cocos2d/actions/interval/CCMoveTo.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.actions.interval; 2 | 3 | import org.cocos2d.nodes.CCNode; 4 | import org.cocos2d.types.CGPoint; 5 | 6 | // 7 | // MoveTo 8 | // 9 | 10 | /** Moves a CCNode object to the position x,y. x and y are absolute coordinates by modifying it's position attribute. 11 | */ 12 | public class CCMoveTo extends CCIntervalAction { 13 | private CGPoint endPosition; 14 | private CGPoint startPosition; 15 | protected CGPoint delta; 16 | 17 | /** creates the action */ 18 | public static CCMoveTo action(float t, CGPoint pos) { 19 | return new CCMoveTo(t, pos); 20 | } 21 | 22 | /** initializes the action */ 23 | protected CCMoveTo(float t, CGPoint pos) { 24 | super(t); 25 | startPosition = CGPoint.zero(); 26 | endPosition = CGPoint.make(pos.x, pos.y); 27 | delta = CGPoint.zero(); 28 | } 29 | 30 | /** 31 | * Lets extend basic functionality for reuse action. 32 | */ 33 | public void setEndPosition(CGPoint pos) { 34 | endPosition.set(pos); 35 | } 36 | 37 | @Override 38 | public CCIntervalAction copy() { 39 | return new CCMoveTo(duration, endPosition); 40 | } 41 | 42 | @Override 43 | public void start(CCNode aTarget) { 44 | super.start(aTarget); 45 | 46 | startPosition.set(target.getPositionRef()); 47 | delta.set(endPosition.x - startPosition.x, endPosition.y - startPosition.y); 48 | } 49 | 50 | @Override 51 | public void update(float t) { 52 | target.setPosition(startPosition.x + delta.x * t, 53 | startPosition.y + delta.y * t); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/org/cocos2d/actions/base/CCRepeatForever.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.actions.base; 2 | 3 | import org.cocos2d.actions.interval.CCIntervalAction; 4 | import org.cocos2d.nodes.CCNode; 5 | 6 | 7 | /** Repeats an action for ever. 8 | To repeat the an action for a limited number of times use the Repeat action. 9 | @warning This action can't be Sequenceable because it is not an IntervalAction 10 | */ 11 | public class CCRepeatForever extends CCAction { 12 | protected CCIntervalAction other; 13 | 14 | /** creates the action */ 15 | public static CCRepeatForever action(CCIntervalAction action) { 16 | return new CCRepeatForever(action); 17 | } 18 | 19 | /** initializes the action */ 20 | protected CCRepeatForever(CCIntervalAction action) { 21 | other = action; 22 | } 23 | 24 | @Override 25 | public CCAction copy() { 26 | return new CCRepeatForever(other.copy()); 27 | } 28 | 29 | @Override 30 | public void start(CCNode aTarget) { 31 | super.start(aTarget); 32 | other.start(target); 33 | } 34 | 35 | @Override 36 | public void step(float dt) { 37 | other.step(dt); 38 | if (other.isDone()) { 39 | float diff = dt + other.duration - other.getElapsed(); 40 | other.start(target); 41 | other.step(diff); 42 | } 43 | } 44 | 45 | @Override 46 | public boolean isDone() { 47 | return false; 48 | } 49 | 50 | public CCRepeatForever reverse() { 51 | return CCRepeatForever.action(other.reverse()); 52 | } 53 | 54 | @Override 55 | public void update(float time) { 56 | // TODO Auto-generated method stub 57 | 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/org/cocos2d/utils/ContentHelper.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.utils; 2 | 3 | import java.io.IOException; 4 | import java.io.InputStream; 5 | 6 | import org.cocos2d.nodes.CCDirector; 7 | 8 | /** 9 | * Class can register ContentProvider for loading resources from input stream, 10 | * Default is using assets provider. 11 | */ 12 | public class ContentHelper { 13 | 14 | private static ContentHelper sContentHelper = new ContentHelper(); 15 | 16 | /** singleton of the ContentHelper */ 17 | public static ContentHelper sharedHelper() { 18 | return sContentHelper; 19 | } 20 | 21 | /** 22 | * loader interface for resources 23 | */ 24 | public interface StreamProvider { 25 | InputStream openStream(final String path) throws IOException; 26 | } 27 | 28 | // external loader registered with setExternalLoader(StreamProvider) 29 | private StreamProvider mExternalLoader; 30 | 31 | // default provider uses assets for loading 32 | private StreamProvider mDefaultLoader; 33 | 34 | public void setExternalLoader(StreamProvider mExternalLoader) { 35 | this.mExternalLoader = mExternalLoader; 36 | } 37 | 38 | public ContentHelper() { 39 | mDefaultLoader = new StreamProvider() { 40 | 41 | public InputStream openStream(String path) throws IOException { 42 | return CCDirector.theApp.getAssets().open(path); 43 | } 44 | }; 45 | } 46 | 47 | public InputStream openInputStream(final String path) throws IOException { 48 | if(mExternalLoader != null) { 49 | return mExternalLoader.openStream(path); 50 | } else { 51 | return mDefaultLoader.openStream(path); 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/org/cocos2d/actions/interval/CCSkewTo.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.actions.interval; 2 | 3 | import org.cocos2d.nodes.CCNode; 4 | 5 | public class CCSkewTo extends CCIntervalAction { 6 | 7 | protected float endSkewX; 8 | protected float endSkewY; 9 | protected float startSkewX; 10 | protected float deltaX; 11 | protected float startSkewY; 12 | protected float deltaY; 13 | 14 | public static CCSkewTo action(float t, float sx, float sy) { 15 | return new CCSkewTo(t, sx, sy); 16 | } 17 | 18 | protected CCSkewTo(float t, float sx, float sy) { 19 | super(t); 20 | endSkewX = sx; 21 | endSkewY = sy; 22 | } 23 | 24 | @Override 25 | public CCSkewTo copy() { 26 | return new CCSkewTo(duration, endSkewX, endSkewY); 27 | } 28 | 29 | @Override 30 | public void start(CCNode aTarget) { 31 | super.start(aTarget); 32 | 33 | /** Calculate Skew X */ 34 | startSkewX = target.getSkewX(); 35 | 36 | if (startSkewX > 0) 37 | startSkewX = startSkewX % 180f; 38 | else 39 | startSkewX = startSkewX % -180f; 40 | 41 | deltaX = endSkewX - startSkewX; 42 | 43 | if (deltaX > 180) 44 | deltaX -= 360; 45 | else if (deltaX < -180) 46 | deltaX += 360; 47 | 48 | /** Calculate Skew Y */ 49 | startSkewY = target.getSkewY(); 50 | 51 | if (startSkewY > 0) 52 | startSkewY = startSkewY % 180f; 53 | else 54 | startSkewY = startSkewY % -180f; 55 | 56 | deltaY = endSkewY - startSkewY; 57 | 58 | if (deltaY > 180) 59 | deltaY -= 360f; 60 | else if (deltaY < -180) 61 | deltaY += 360f; 62 | } 63 | 64 | @Override 65 | public void update(float t) { 66 | target.setSkewX(startSkewX + deltaX * t); 67 | target.setSkewY(startSkewY + deltaY * t); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/org/cocos2d/menus/CCMenuItemFont.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.menus; 2 | 3 | import org.cocos2d.nodes.CCLabel; 4 | import org.cocos2d.nodes.CCNode; 5 | 6 | /** A CCMenuItemFont 7 | Helper class that creates a CCMenuItemLabel class with a Label 8 | */ 9 | public class CCMenuItemFont extends CCMenuItemLabel { 10 | // private CCLabel label_; 11 | 12 | static int _fontSize = kItemSize; 13 | static String _fontName = "DroidSans"; 14 | 15 | /** set font size */ 16 | public static void setFontSize(int s) { 17 | _fontSize = s; 18 | } 19 | 20 | /** get font size */ 21 | public static int fontSize() { 22 | return _fontSize; 23 | } 24 | 25 | /** set the font name */ 26 | public static void setFontName(String n) { 27 | _fontName = n; 28 | } 29 | 30 | /** get the font name */ 31 | public static String fontName() { 32 | return _fontName; 33 | } 34 | 35 | /** creates a menu item from a string without target/selector. 36 | * To be used with CCMenuItemToggle */ 37 | public static CCMenuItemFont item(String value) { 38 | return new CCMenuItemFont(CCLabel.makeLabel(value, _fontName, _fontSize), null, null); 39 | } 40 | 41 | /** creates a menu item from a string with a target/selector */ 42 | public static CCMenuItemFont item(String value, CCNode rec, String cb) { 43 | CCLabel lbl = CCLabel.makeLabel(value, _fontName, _fontSize); 44 | return new CCMenuItemFont(lbl, rec, cb); 45 | } 46 | 47 | /** initializes a menu item from a string with a target/selector */ 48 | protected CCMenuItemFont(CCLabel label, CCNode rec, String cb) { 49 | super(label, rec, cb); 50 | } 51 | } 52 | 53 | -------------------------------------------------------------------------------- /src/org/cocos2d/transitions/CCSplitColsTransition.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.transitions; 2 | 3 | import org.cocos2d.actions.ease.CCEaseInOut; 4 | import org.cocos2d.actions.grid.CCStopGrid; 5 | import org.cocos2d.actions.instant.CCCallFunc; 6 | import org.cocos2d.actions.interval.CCIntervalAction; 7 | import org.cocos2d.actions.interval.CCSequence; 8 | import org.cocos2d.actions.tile.CCSplitCols; 9 | import org.cocos2d.layers.CCScene; 10 | 11 | /** 12 | * SplitCols Transition. 13 | * The odd columns goes upwards while the even columns goes downwards. 14 | */ 15 | public class CCSplitColsTransition extends CCTransitionScene implements CCTransitionEaseScene { 16 | 17 | public static CCSplitColsTransition transition(float t, CCScene s) { 18 | return new CCSplitColsTransition(t, s); 19 | } 20 | 21 | public CCSplitColsTransition(float t, CCScene s) { 22 | super(t, s); 23 | } 24 | 25 | @Override 26 | public void onEnter() { 27 | super.onEnter(); 28 | 29 | inScene.setVisible(false); 30 | 31 | CCIntervalAction split = action(); 32 | CCIntervalAction seq = CCSequence.actions( 33 | split, 34 | CCCallFunc.action(this, "hideOutShowIn"), 35 | split.reverse()); 36 | runAction(CCSequence.actions( 37 | easeAction(seq), 38 | CCCallFunc.action(this, "finish"), 39 | CCStopGrid.action())); 40 | } 41 | 42 | 43 | public CCIntervalAction easeAction(CCIntervalAction action) { 44 | return CCEaseInOut.action(action, 3.0f); 45 | } 46 | 47 | protected CCIntervalAction action() { 48 | return CCSplitCols.action(3, duration/2.0f); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/org/cocos2d/events/CCKeyHandler.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.events; 2 | 3 | import org.cocos2d.protocols.CCKeyDelegateProtocol; 4 | 5 | import android.view.KeyEvent; 6 | 7 | public class CCKeyHandler implements CCKeyDelegateProtocol { 8 | private CCKeyDelegateProtocol delegate_; 9 | boolean enabledSelectors_; 10 | private int priority_; 11 | 12 | 13 | public CCKeyDelegateProtocol getDelegate() { 14 | return delegate_; 15 | } 16 | 17 | public void setSelectorFlag(boolean sf) { 18 | enabledSelectors_ = sf; 19 | } 20 | 21 | public boolean getSelectorFlag() { 22 | return enabledSelectors_; 23 | } 24 | 25 | public int getPriority() { 26 | return priority_; 27 | } 28 | 29 | public void setPriority(int prio) { 30 | priority_ = prio; 31 | } 32 | 33 | public static CCKeyHandler makeHandler(CCKeyDelegateProtocol delegate, int priority) { 34 | return new CCKeyHandler(delegate, priority); 35 | } 36 | 37 | public CCKeyHandler(CCKeyDelegateProtocol delegate, int priority) { 38 | assert delegate !=null : "Key delegate may not be nil"; 39 | delegate_ = delegate; 40 | enabledSelectors_ = false; 41 | priority_ = priority; 42 | } 43 | 44 | public boolean ccKeyDown(int keyCode, KeyEvent event) { 45 | // TODO Auto-generated method stub 46 | if( delegate_ != null ) 47 | return delegate_.ccKeyDown(keyCode, event); 48 | else 49 | return CCKeyDispatcher.kEventIgnored; 50 | } 51 | 52 | public boolean ccKeyUp(int keyCode, KeyEvent event) { 53 | // TODO Auto-generated method stub 54 | if( delegate_ != null ) 55 | return delegate_.ccKeyUp(keyCode, event); 56 | else 57 | return CCKeyDispatcher.kEventIgnored; 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /src/org/cocos2d/transitions/CCTurnOffTilesTransition.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.transitions; 2 | 3 | import org.cocos2d.actions.grid.CCStopGrid; 4 | import org.cocos2d.actions.instant.CCCallFunc; 5 | import org.cocos2d.actions.interval.CCIntervalAction; 6 | import org.cocos2d.actions.interval.CCSequence; 7 | import org.cocos2d.actions.tile.CCTurnOffTiles; 8 | import org.cocos2d.layers.CCScene; 9 | import org.cocos2d.nodes.CCDirector; 10 | import org.cocos2d.types.CGSize; 11 | import org.cocos2d.types.ccGridSize; 12 | 13 | /** 14 | * TurnOffTiles Transition. 15 | * Turn off the tiles of the outgoing scene in random order 16 | */ 17 | public class CCTurnOffTilesTransition extends CCTransitionScene implements CCTransitionEaseScene { 18 | 19 | public static CCTransitionScene transition(float t, CCScene s) { 20 | return new CCTurnOffTilesTransition(t, s); 21 | } 22 | 23 | public CCTurnOffTilesTransition(float t, CCScene s) { 24 | super(t, s); 25 | } 26 | 27 | // override addScenes, and change the order 28 | public void sceneOrder() { 29 | inSceneOnTop = false; 30 | } 31 | 32 | public void onEnter() { 33 | super.onEnter(); 34 | 35 | CGSize s = CCDirector.sharedDirector().winSize(); 36 | float aspect = s.width / s.height; 37 | int x = (int)(12 * aspect); 38 | int y = 12; 39 | 40 | CCTurnOffTiles toff = CCTurnOffTiles.action((int)System.currentTimeMillis(), ccGridSize.ccg(x,y), duration); 41 | CCIntervalAction action = easeAction(toff); 42 | outScene.runAction(CCSequence.actions(action, 43 | CCCallFunc.action(this, "finish"), 44 | CCStopGrid.action() 45 | ) 46 | ); 47 | } 48 | 49 | public CCIntervalAction easeAction(CCIntervalAction action) { 50 | return action; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/org/cocos2d/menus/CCMenuItemImage.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.menus; 2 | 3 | import org.cocos2d.nodes.CCNode; 4 | import org.cocos2d.nodes.CCSprite; 5 | 6 | 7 | /** CCMenuItemImage accepts images as items. 8 | The images has 3 different states: 9 | - unselected image 10 | - selected image 11 | - disabled image 12 | 13 | For best results try that all images are of the same size 14 | */ 15 | public class CCMenuItemImage extends CCMenuItemSprite { 16 | 17 | /** creates a menu item with a normal and selected image*/ 18 | public static CCMenuItemImage item(String value, String value2) { 19 | return item(value, value2, null, null, null); 20 | } 21 | 22 | /** creates a menu item with a normal and selected image with target/selector */ 23 | public static CCMenuItemImage item(String value, String value2, CCNode t, String s) { 24 | return item(value, value2, null, t, s); 25 | } 26 | 27 | public static CCMenuItemImage item(String value, String value2, String value3) { 28 | return item(value, value2, value3, null, null); 29 | } 30 | 31 | /** creates a menu item with a normal,selected and disabled image with target/selector */ 32 | public static CCMenuItemImage item(String normalI, String selectedI, String disabledI, 33 | CCNode t, String sel) { 34 | return new CCMenuItemImage(CCSprite.sprite(normalI), CCSprite.sprite(selectedI), 35 | (disabledI == null) ? null : CCSprite.sprite(disabledI), t, sel); 36 | } 37 | 38 | /** initializes a menu item with a normal, selected and disabled image with target/selector */ 39 | protected CCMenuItemImage(CCSprite normal, CCSprite selected, CCSprite disabled, CCNode t, String sel) { 40 | super(normal, selected, disabled, t, sel); 41 | } 42 | } 43 | 44 | -------------------------------------------------------------------------------- /src/org/cocos2d/transitions/CCMoveInLTransition.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.transitions; 2 | 3 | import org.cocos2d.actions.ease.CCEaseOut; 4 | import org.cocos2d.actions.instant.CCCallFunc; 5 | import org.cocos2d.actions.interval.CCIntervalAction; 6 | import org.cocos2d.actions.interval.CCMoveTo; 7 | import org.cocos2d.actions.interval.CCSequence; 8 | import org.cocos2d.layers.CCScene; 9 | import org.cocos2d.nodes.CCDirector; 10 | import org.cocos2d.types.CGPoint; 11 | import org.cocos2d.types.CGSize; 12 | 13 | /** 14 | * MoveInL Transition. 15 | * Move in from to the left the incoming scene. 16 | */ 17 | public class CCMoveInLTransition extends CCTransitionScene implements CCTransitionEaseScene { 18 | 19 | public static CCMoveInLTransition transition(float t, CCScene s) { 20 | return new CCMoveInLTransition(t, s); 21 | } 22 | 23 | protected CCMoveInLTransition(float t, CCScene s) { 24 | super(t, s); 25 | } 26 | 27 | @Override 28 | public void onEnter() { 29 | super.onEnter(); 30 | 31 | initScenes(); 32 | 33 | CCIntervalAction a = action(); 34 | 35 | inScene.runAction(CCSequence.actions( 36 | easeAction(a), 37 | CCCallFunc.action(this, "finish"))); 38 | } 39 | 40 | /** 41 | * returns the action that will be performed 42 | */ 43 | protected CCIntervalAction action() { 44 | return CCMoveTo.action(duration, new CGPoint()); 45 | } 46 | 47 | public CCIntervalAction easeAction(CCIntervalAction action) { 48 | return CCEaseOut.action(action, 2.0f); 49 | } 50 | 51 | /** 52 | * initializes the scenes 53 | */ 54 | protected void initScenes() { 55 | CGSize s = CCDirector.sharedDirector().winSize(); 56 | inScene.setPosition(-s.width, 0); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/org/cocos2d/actions/interval/CCJumpBy.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.actions.interval; 2 | 3 | import org.cocos2d.nodes.CCNode; 4 | import org.cocos2d.types.CGPoint; 5 | 6 | /** 7 | * Moves a CCNode object simulating a parabolic jump movement by modifying it's position attribute. 8 | */ 9 | public class CCJumpBy extends CCIntervalAction { 10 | protected CGPoint startPosition; 11 | protected CGPoint delta; 12 | protected float height; 13 | protected int jumps; 14 | 15 | /** creates the action */ 16 | public static CCJumpBy action(float time, CGPoint pos, float height, int jumps) { 17 | return new CCJumpBy(time, pos, height, jumps); 18 | } 19 | 20 | /** initializes the action */ 21 | protected CCJumpBy(float time, CGPoint pos, float h, int j) { 22 | super(time); 23 | startPosition = CGPoint.make(0,0); 24 | delta = CGPoint.make(pos.x, pos.y); 25 | height = h; 26 | jumps = j; 27 | } 28 | 29 | @Override 30 | public CCJumpBy copy() { 31 | return new CCJumpBy(duration, delta, height, jumps); 32 | } 33 | 34 | @Override 35 | public void start(CCNode aTarget) { 36 | super.start(aTarget); 37 | CGPoint pnt = target.getPosition(); 38 | startPosition = CGPoint.make(pnt.x, pnt.y); 39 | } 40 | 41 | @Override 42 | public void update(float t) { 43 | // parabolic jump (since v0.8.2) 44 | float frac = (t * jumps) % 1.0f; 45 | float y = height * 4 * frac * (1 - frac); 46 | y += delta.y * t; 47 | float x = delta.x * t; 48 | target.setPosition(CGPoint.ccp(startPosition.x + x, startPosition.y + y)); 49 | } 50 | 51 | @Override 52 | public CCJumpBy reverse() { 53 | return new CCJumpBy(duration, CGPoint.ccpNeg(delta), height, jumps); 54 | } 55 | } 56 | 57 | -------------------------------------------------------------------------------- /src/org/cocos2d/actions/grid/CCWaves.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.actions.grid; 2 | 3 | import org.cocos2d.types.CCVertex3D; 4 | import org.cocos2d.types.ccGridSize; 5 | 6 | //////////////////////////////////////////////////////////// 7 | 8 | /** CCWaves action */ 9 | public class CCWaves extends CCGrid3DAction { 10 | int waves; 11 | /** amplitude */ 12 | float amplitude; 13 | /** amplitude rate */ 14 | float amplitudeRate; 15 | boolean vertical; 16 | boolean horizontal; 17 | 18 | 19 | /** initializes the action with amplitude, horizontal sin, vertical sin, a grid and duration */ 20 | public static CCWaves action(int wav, float amp, boolean h, boolean v, ccGridSize gridSize, float d) { 21 | return new CCWaves(wav, amp, h, v, gridSize, d); 22 | } 23 | 24 | /** creates the action with amplitude, horizontal sin, vertical sin, a grid and duration */ 25 | public CCWaves(int wav, float amp, boolean h, boolean v, ccGridSize gSize, float d) { 26 | super(gSize, d); 27 | waves = wav; 28 | amplitude = amp; 29 | amplitudeRate = 1.0f; 30 | horizontal = h; 31 | vertical = v; 32 | } 33 | 34 | @Override 35 | public void update(float time) { 36 | int i, j; 37 | 38 | for( i = 0; i < (gridSize.x+1); i++ ) { 39 | for( j = 0; j < (gridSize.y+1); j++ ) { 40 | CCVertex3D v = originalVertex(ccGridSize.ccg(i,j)); 41 | 42 | if ( vertical ) 43 | v.x = (float)(v.x + (Math.sin(time*Math.PI*waves*2 + v.y * .01f) * amplitude * amplitudeRate)); 44 | 45 | if ( horizontal ) 46 | v.y = (float)(v.y + (Math.sin(time*Math.PI*waves*2 + v.x * .01f) * amplitude * amplitudeRate)); 47 | 48 | setVertex(ccGridSize.ccg(i,j), v); 49 | } 50 | } 51 | } 52 | 53 | @Override 54 | public CCWaves copy() { 55 | CCWaves copy = new CCWaves(waves, amplitude, horizontal, vertical, gridSize, duration); 56 | return copy; 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /src/org/cocos2d/transitions/CCFadeTRTransition.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.transitions; 2 | 3 | import org.cocos2d.actions.grid.CCStopGrid; 4 | import org.cocos2d.actions.instant.CCCallFunc; 5 | import org.cocos2d.actions.interval.CCIntervalAction; 6 | import org.cocos2d.actions.interval.CCSequence; 7 | import org.cocos2d.actions.tile.CCFadeOutTRTiles; 8 | import org.cocos2d.layers.CCScene; 9 | import org.cocos2d.nodes.CCDirector; 10 | import org.cocos2d.types.CGSize; 11 | import org.cocos2d.types.ccGridSize; 12 | 13 | /** 14 | * FadeTRTransition. 15 | * Fade the tiles of the outgoing scene from the left-bottom corner to the top-right corner. 16 | */ 17 | public class CCFadeTRTransition extends CCTransitionScene implements CCTransitionEaseScene{ 18 | 19 | public static CCFadeTRTransition transition(float t, CCScene s) { 20 | return new CCFadeTRTransition(t, s); 21 | } 22 | 23 | public CCFadeTRTransition(float t, CCScene s) { 24 | super(t, s); 25 | } 26 | 27 | // override addScenes, and change the order 28 | @Override 29 | public void sceneOrder() { 30 | inSceneOnTop = false; 31 | } 32 | 33 | @Override 34 | public void onEnter() { 35 | super.onEnter(); 36 | 37 | CGSize s = CCDirector.sharedDirector().winSize(); 38 | float aspect = s.width / s.height; 39 | int x = (int) (12 * aspect); 40 | int y = 12; 41 | 42 | CCIntervalAction action = this.action(ccGridSize.ccg(x,y)); 43 | 44 | outScene.runAction( 45 | CCSequence.actions( 46 | easeAction(action), 47 | CCCallFunc.action(this, "finish"), 48 | CCStopGrid.action() 49 | ) 50 | ); 51 | 52 | } 53 | 54 | protected CCIntervalAction action(ccGridSize v) { 55 | return CCFadeOutTRTiles.action(v, duration); 56 | } 57 | 58 | public CCIntervalAction easeAction(CCIntervalAction action) { 59 | // TODO Auto-generated method stub 60 | return action; 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /src/org/cocos2d/actions/tile/CCSplitRows.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.actions.tile; 2 | 3 | import org.cocos2d.nodes.CCDirector; 4 | import org.cocos2d.nodes.CCNode; 5 | import org.cocos2d.types.CGSize; 6 | import org.cocos2d.types.ccGridSize; 7 | import org.cocos2d.types.ccQuad3; 8 | 9 | //////////////////////////////////////////////////////////// 10 | 11 | /** CCSplitRows action */ 12 | public class CCSplitRows extends CCTiledGrid3DAction { 13 | int rows; 14 | CGSize winSize; 15 | 16 | /** creates the action with the number of rows to split and the duration */ 17 | public static CCSplitRows action(int r, float d) { 18 | return new CCSplitRows(r, d); 19 | } 20 | 21 | /** initializes the action with the number of rows to split and the duration */ 22 | protected CCSplitRows(int r, float d) { 23 | super(ccGridSize.ccg(1, r), d); 24 | rows = r; 25 | } 26 | 27 | @Override 28 | public CCSplitRows copy() { 29 | return new CCSplitRows(rows, duration); 30 | } 31 | 32 | @Override 33 | public void start(CCNode aTarget) { 34 | super.start(aTarget); 35 | winSize = CCDirector.sharedDirector().winSize(); 36 | } 37 | 38 | @Override 39 | public void update(float time) { 40 | int j; 41 | 42 | for( j = 0; j < gridSize.y; j++ ) { 43 | ccQuad3 coords = originalTile(ccGridSize.ccg(0,j)); 44 | float direction = 1; 45 | 46 | if ( (j % 2 ) == 0 ) 47 | direction = -1; 48 | 49 | coords.bl_x += direction * winSize.width * time; 50 | coords.br_x += direction * winSize.width * time; 51 | coords.tl_x += direction * winSize.width * time; 52 | coords.tr_x += direction * winSize.width * time; 53 | 54 | setTile(ccGridSize.ccg(0,j), coords); 55 | } 56 | } 57 | 58 | } 59 | 60 | -------------------------------------------------------------------------------- /src/org/cocos2d/actions/tile/CCSplitCols.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.actions.tile; 2 | 3 | import org.cocos2d.nodes.CCDirector; 4 | import org.cocos2d.nodes.CCNode; 5 | import org.cocos2d.types.CGSize; 6 | import org.cocos2d.types.ccGridSize; 7 | import org.cocos2d.types.ccQuad3; 8 | 9 | //////////////////////////////////////////////////////////// 10 | 11 | /** CCSplitCols action */ 12 | public class CCSplitCols extends CCTiledGrid3DAction { 13 | int cols; 14 | CGSize winSize; 15 | 16 | /** creates the action with the number of columns to split and the duration */ 17 | public static CCSplitCols action(int c, float d) { 18 | return new CCSplitCols(c, d); 19 | } 20 | 21 | /** initializes the action with the number of columns to split and the duration */ 22 | protected CCSplitCols(int c, float d) { 23 | super(ccGridSize.ccg(c, 1), d); 24 | cols = c; 25 | } 26 | 27 | @Override 28 | public CCSplitCols copy() { 29 | return new CCSplitCols(cols, duration); 30 | } 31 | 32 | @Override 33 | public void start(CCNode aTarget) { 34 | super.start(aTarget); 35 | winSize = CCDirector.sharedDirector().winSize(); 36 | } 37 | 38 | @Override 39 | public void update(float time) { 40 | int i; 41 | 42 | for( i = 0; i < gridSize.x; i++ ) { 43 | ccQuad3 coords = originalTile(ccGridSize.ccg(i,0)); 44 | float direction = 1; 45 | 46 | if ( (i % 2 ) == 0 ) 47 | direction = -1; 48 | 49 | coords.bl_y += direction * winSize.height * time; 50 | coords.br_y += direction * winSize.height * time; 51 | coords.tl_y += direction * winSize.height * time; 52 | coords.tr_y += direction * winSize.height * time; 53 | 54 | setTile(ccGridSize.ccg(i,0), coords); 55 | } 56 | } 57 | 58 | } 59 | 60 | -------------------------------------------------------------------------------- /src/org/cocos2d/actions/tile/CCWavesTiles3D.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.actions.tile; 2 | 3 | import org.cocos2d.types.ccGridSize; 4 | import org.cocos2d.types.ccQuad3; 5 | 6 | //////////////////////////////////////////////////////////// 7 | 8 | /** CCWavesTiles3D action. */ 9 | public class CCWavesTiles3D extends CCTiledGrid3DAction { 10 | int waves; 11 | /** waves amplitude */ 12 | float amplitude; 13 | /** waves amplitude rate */ 14 | float amplitudeRate; 15 | 16 | 17 | /** creates the action with a number of waves, the waves amplitude, the grid size and the duration */ 18 | public static CCWavesTiles3D action(int wav, float amp, ccGridSize gridSize, float d) { 19 | return new CCWavesTiles3D(wav, amp, gridSize, d); 20 | } 21 | 22 | /** initializes the action with a number of waves, the waves amplitude, the grid size and the duration */ 23 | public CCWavesTiles3D(int wav, float amp, ccGridSize gridSize, float d) { 24 | super(gridSize, d); 25 | waves = wav; 26 | amplitude = amp; 27 | amplitudeRate = 1.0f; 28 | } 29 | 30 | @Override 31 | public CCWavesTiles3D copy() { 32 | return new CCWavesTiles3D(waves, amplitude, gridSize, duration); 33 | } 34 | 35 | @Override 36 | public void update(float time) { 37 | int i, j; 38 | 39 | for( i = 0; i < gridSize.x; i++ ) { 40 | for( j = 0; j < gridSize.y; j++ ) { 41 | ccQuad3 coords = originalTile(ccGridSize.ccg(i,j)); 42 | 43 | coords.bl_z = (float)(Math.sin(time*Math.PI*waves*2 + (coords.bl_y+coords.bl_x) * .01f) 44 | * amplitude * amplitudeRate ); 45 | coords.br_z = coords.bl_z; 46 | coords.tl_z = coords.bl_z; 47 | coords.tr_z = coords.bl_z; 48 | 49 | setTile(ccGridSize.ccg(i,j), coords); 50 | } 51 | } 52 | } 53 | } 54 | 55 | 56 | -------------------------------------------------------------------------------- /src/org/cocos2d/actions/base/CCSpeed.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.actions.base; 2 | 3 | import org.cocos2d.actions.interval.CCIntervalAction; 4 | import org.cocos2d.nodes.CCNode; 5 | 6 | 7 | /** Changes the speed of an action, making it take longer (speed>1) 8 | or less (speed<1) time. 9 | Useful to simulate 'slow motion' or 'fast forward' effect. 10 | @warning This action can't be Sequenceable because it is not an IntervalAction 11 | */ 12 | public class CCSpeed extends CCAction { 13 | 14 | protected CCIntervalAction other; 15 | /** alter the speed of the inner function in runtime */ 16 | protected float speed; 17 | 18 | public float getSpeed() { 19 | return speed; 20 | } 21 | 22 | public void setSpeed(float speed) { 23 | this.speed = speed; 24 | } 25 | 26 | /** creates the action */ 27 | public static CCSpeed action(CCIntervalAction action, float r) { 28 | return new CCSpeed(action, r); 29 | } 30 | 31 | /** initializes the action */ 32 | protected CCSpeed(CCIntervalAction action, float r) { 33 | other = action; 34 | speed = r; 35 | } 36 | 37 | @Override 38 | public CCSpeed copy() { 39 | return new CCSpeed(other.copy(), speed); 40 | } 41 | 42 | 43 | @Override 44 | public void start(CCNode aTarget) { 45 | super.start(aTarget); 46 | other.start(target); 47 | } 48 | 49 | @Override 50 | public void stop() { 51 | other.stop(); 52 | super.stop(); 53 | } 54 | 55 | @Override 56 | public void step(float dt) { 57 | other.step(dt * speed); 58 | } 59 | 60 | @Override 61 | public boolean isDone() { 62 | return other.isDone(); 63 | } 64 | 65 | public CCSpeed reverse() { 66 | return CCSpeed.action(other.reverse(), speed); 67 | } 68 | 69 | @Override 70 | public void update(float time) { 71 | // TODO Auto-generated method stub 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /src/org/cocos2d/actions/instant/CCCallFunc.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.actions.instant; 2 | 3 | import java.lang.reflect.Method; 4 | 5 | import org.cocos2d.nodes.CCNode; 6 | 7 | // 8 | // CallFunc 9 | // 10 | 11 | /** 12 | * Calls a 'callback' 13 | */ 14 | public class CCCallFunc extends CCInstantAction { 15 | protected Object targetCallback; 16 | protected String selector; 17 | protected Class partypes[]; 18 | 19 | protected Method invocation; 20 | 21 | /** creates the action with the callback */ 22 | public static CCCallFunc action(Object target, String selector) { 23 | return new CCCallFunc(target, selector, null); 24 | } 25 | 26 | /** 27 | * creates an action with a callback 28 | */ 29 | protected CCCallFunc(Object t, String s, Class[] p) { 30 | targetCallback = t; 31 | selector = s; 32 | partypes = p; 33 | 34 | if (partypes == null) 35 | { 36 | try { 37 | Class cls = targetCallback.getClass(); 38 | invocation = cls.getMethod(selector); 39 | } catch (NoSuchMethodException e) { 40 | e.printStackTrace(); 41 | } 42 | } 43 | else 44 | { 45 | try { 46 | Class cls = targetCallback.getClass(); 47 | invocation = cls.getMethod(selector, partypes); 48 | } catch (NoSuchMethodException e) { 49 | e.printStackTrace(); 50 | } 51 | } 52 | } 53 | 54 | public CCCallFunc copy() { 55 | return new CCCallFunc(targetCallback, selector, partypes); 56 | } 57 | 58 | @Override 59 | public void start(CCNode aTarget) { 60 | super.start(aTarget); 61 | execute(); 62 | } 63 | 64 | /** 65 | * executes the callback 66 | */ 67 | public void execute() { 68 | try { 69 | invocation.invoke(targetCallback); 70 | } catch (Exception e) { 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/org/cocos2d/types/ccColor4F.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.types; 2 | 3 | /** RGBA color composed of 4 floats 4 | @since v0.8 5 | */ 6 | public class ccColor4F { 7 | public float r; 8 | public float g; 9 | public float b; 10 | public float a; 11 | 12 | public ccColor4F() { 13 | r = g = b = a = 1.0f; 14 | } 15 | 16 | public ccColor4F(float rr, float gg, float bb, float aa) { 17 | r = rr; 18 | g = gg; 19 | b = bb; 20 | a = aa; 21 | } 22 | 23 | public ccColor4F(ccColor4F c) { 24 | r = c.r; 25 | g = c.g; 26 | b = c.b; 27 | a = c.a; 28 | } 29 | 30 | public ccColor4F(ccColor4B c) 31 | { 32 | r = c.r/0xFF; 33 | g = c.g/0xFF; 34 | b = c.b/0xFF; 35 | a = c.a/0xFF; 36 | } 37 | 38 | public ccColor4F(ccColor3B c) 39 | { 40 | r = c.r/0xFF; 41 | g = c.g/0xFF; 42 | b = c.b/0xFF; 43 | a = 1.0f; 44 | } 45 | 46 | public float[] toFloatArray() { 47 | return new float[]{r, g, b, a}; 48 | } 49 | 50 | /** Returns a ccColor4F from a ccColor3B. Alpha will be 1. 51 | @since v0.99.1 52 | */ 53 | public static ccColor4F ccc4FFromccc3B(ccColor3B c) 54 | { 55 | return new ccColor4F(c.r/255.f, c.g/255.f, c.b/255.f, 1.f); 56 | } 57 | 58 | /** Returns a ccColor4F from a ccColor4B. 59 | @since v0.99.1 60 | */ 61 | public static ccColor4F ccc4FFromccc4B(ccColor4B c) 62 | { 63 | return new ccColor4F(c.r/255.f, c.g/255.f, c.b/255.f, c.a/255.f); 64 | } 65 | 66 | /** returns YES if both ccColor4F are equal. Otherwise it returns NO. 67 | @since v0.99.1 68 | */ 69 | public static boolean ccc4FEqual(ccColor4F a, ccColor4F b) 70 | { 71 | return a.r == b.r && a.g == b.g && a.b == b.b && a.a == b.a; 72 | } 73 | 74 | public String toString() { 75 | return "< r=" + r + ", g=" + g + ", b=" + b + ", a=" + a + " >"; 76 | } 77 | } 78 | 79 | -------------------------------------------------------------------------------- /src/org/cocos2d/actions/interval/CCScaleTo.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.actions.interval; 2 | 3 | import org.cocos2d.nodes.CCNode; 4 | 5 | /** Scales a CCNode object to a zoom factor by modifying it's scale attribute. 6 | @warning This action doesn't support "reverse" 7 | */ 8 | public class CCScaleTo extends CCIntervalAction { 9 | protected float scaleX; 10 | protected float scaleY; 11 | protected float startScaleX; 12 | protected float startScaleY; 13 | protected float endScaleX; 14 | protected float endScaleY; 15 | protected float deltaX; 16 | protected float deltaY; 17 | 18 | /** creates the action with the same scale factor for X and Y */ 19 | public static CCScaleTo action(float t, float s) { 20 | return new CCScaleTo(t, s); 21 | } 22 | 23 | /** creates the action with and X factor and a Y factor */ 24 | public static CCScaleTo action(float t, float sx, float sy) { 25 | return new CCScaleTo(t, sx, sy); 26 | } 27 | 28 | /** initializes the action with the same scale factor for X and Y */ 29 | protected CCScaleTo(float t, float s) { 30 | this(t, s, s); 31 | } 32 | 33 | /** initializes the action with and X factor and a Y factor */ 34 | protected CCScaleTo(float t, float sx, float sy) { 35 | super(t); 36 | endScaleX = sx; 37 | endScaleY = sy; 38 | } 39 | 40 | @Override 41 | public CCScaleTo copy() { 42 | return new CCScaleTo(duration, endScaleX, endScaleY); 43 | } 44 | 45 | @Override 46 | public void start(CCNode aTarget) { 47 | super.start(aTarget); 48 | startScaleX = target.getScaleX(); 49 | startScaleY = target.getScaleY(); 50 | deltaX = endScaleX - startScaleX; 51 | deltaY = endScaleY - startScaleY; 52 | } 53 | 54 | @Override 55 | public void update(float t) { 56 | target.setScaleX(startScaleX + deltaX * t); 57 | target.setScaleY(startScaleY + deltaY * t); 58 | } 59 | } 60 | 61 | -------------------------------------------------------------------------------- /src/org/cocos2d/types/ccColor3B.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.types; 2 | 3 | /** RGB color composed of bytes 3 bytes 4 | @since v0.8 5 | */ 6 | public class ccColor3B { 7 | public static final int size = 3; 8 | 9 | //ccColor3B predefined colors 10 | //! White color (255,255,255) 11 | public static final ccColor3B ccWHITE = ccc3(255,255,255); 12 | //! Yellow color (255,255,0) 13 | public static final ccColor3B ccYELLOW = ccc3(255,255,0); 14 | //! Blue color (0,0,255) 15 | public static final ccColor3B ccBLUE = ccc3(0,0,255); 16 | //! Green Color (0,255,0) 17 | public static final ccColor3B ccGREEN = ccc3(0,255,0); 18 | //! Red Color (255,0,0,) 19 | public static final ccColor3B ccRED = ccc3(255,0,0); 20 | //! Magenta Color (255,0,255) 21 | public static final ccColor3B ccMAGENTA = ccc3(255,0,255); 22 | //! Black Color (0,0,0) 23 | public static final ccColor3B ccBLACK = ccc3(0,0,0); 24 | //! Orange Color (255,127,0) 25 | public static final ccColor3B ccORANGE = ccc3(255,127,0); 26 | //! Gray Color (166,166,166) 27 | public static final ccColor3B ccGRAY = ccc3(166,166,166); 28 | 29 | 30 | public int r; 31 | public int g; 32 | public int b; 33 | 34 | public ccColor3B(ccColor3B c) { 35 | r = c.r; 36 | g = c.g; 37 | b = c.b; 38 | } 39 | 40 | public ccColor3B(int rr, int gg, int bb) { 41 | r = rr; 42 | g = gg; 43 | b = bb; 44 | } 45 | 46 | public void set(ccColor3B color) { 47 | r = color.r; 48 | g = color.g; 49 | b = color.b; 50 | } 51 | 52 | public byte[] toByteArray() { 53 | return new byte[]{(byte) r, (byte) g, (byte) b}; 54 | } 55 | 56 | //! helper macro that creates an ccColor3B type 57 | public static ccColor3B ccc3(final int r, final int g, final int b) 58 | { 59 | return new ccColor3B(r, g, b); 60 | } 61 | 62 | 63 | public String toString() { 64 | return "< r=" + r + ", g=" + g + ", b=" + b + " >"; 65 | } 66 | } 67 | 68 | -------------------------------------------------------------------------------- /src/org/cocos2d/layers/CCMultiplexLayer.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.layers; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Arrays; 5 | 6 | /** CCMultipleLayer is a CCLayer with the ability to multiplex it's children. 7 | Features: 8 | - It supports one or more children 9 | - Only one children will be active a time 10 | */ 11 | public class CCMultiplexLayer extends CCLayer { 12 | private ArrayList layers; 13 | 14 | private int enabledLayer; 15 | 16 | /** creates a CCMultiplexLayer with one or more layers 17 | * using a variable argument list. 18 | */ 19 | public static CCMultiplexLayer node(CCLayer... params) { 20 | return new CCMultiplexLayer(params); 21 | } 22 | 23 | /** initializes a MultiplexLayer with one or more layers 24 | * using a variable argument list. 25 | */ 26 | protected CCMultiplexLayer(CCLayer... params) { 27 | layers = new ArrayList(); 28 | 29 | layers.addAll(Arrays.asList(params)); 30 | 31 | enabledLayer = 0; 32 | addChild(layers.get(enabledLayer)); 33 | } 34 | 35 | /** switches to a certain layer indexed by n. 36 | * The current (old) layer will be removed from it's parent with 'cleanup:YES'. 37 | */ 38 | public void switchTo(int n) { 39 | assert n < layers.size(): "Invalid index passed to MultiplexLayer.switchTo"; 40 | 41 | removeChild(layers.get(enabledLayer), true); 42 | enabledLayer = n; 43 | addChild(layers.get(enabledLayer)); 44 | } 45 | 46 | /** release the current layer and switches to another layer indexed by n. 47 | The current (old) layer will be removed from it's parent with 'cleanup:YES'. 48 | */ 49 | public void switchToAndReleaseMe(int n) { 50 | 51 | assert n < layers.size() : "Invalid index in MultiplexLayer switchTo message" ; 52 | removeChild(layers.get(enabledLayer), true); 53 | layers.add(enabledLayer, null); 54 | enabledLayer = n; 55 | addChild(layers.get(n)); 56 | } 57 | } 58 | 59 | -------------------------------------------------------------------------------- /src/org/cocos2d/actions/grid/CCRipple3D.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.actions.grid; 2 | 3 | import org.cocos2d.types.CCVertex3D; 4 | import org.cocos2d.types.CGPoint; 5 | import org.cocos2d.types.ccGridSize; 6 | 7 | //////////////////////////////////////////////////////////// 8 | 9 | /** CCRipple3D action */ 10 | public class CCRipple3D extends CCGrid3DAction { 11 | /** center position */ 12 | CGPoint position; 13 | 14 | float radius; 15 | int waves; 16 | 17 | /** amplitude */ 18 | float amplitude; 19 | /** amplitude rate */ 20 | float amplitudeRate; 21 | 22 | /** creates the action with radius, number of waves, amplitude, a grid size and duration */ 23 | public static CCRipple3D action(CGPoint pos, float radius, 24 | int wav,float amp, ccGridSize gridSize, float d) { 25 | return new CCRipple3D(pos, radius, wav, amp, gridSize, d); 26 | } 27 | 28 | /** initializes the action with radius, number of waves, amplitude, a grid size and duration */ 29 | public CCRipple3D(CGPoint pos, float r, int wav, float amp, 30 | ccGridSize gSize, float d) { 31 | super(gSize, d); 32 | position = pos; 33 | radius = r; 34 | waves = wav; 35 | amplitude = amp; 36 | amplitudeRate = 1.0f; 37 | } 38 | 39 | @Override 40 | public CCRipple3D copy() { 41 | CCRipple3D copy = new CCRipple3D(position, radius, waves, 42 | amplitude, gridSize, duration); 43 | return copy; 44 | } 45 | 46 | 47 | @Override 48 | public void update(float time) { 49 | int i, j; 50 | 51 | for( i = 0; i < (gridSize.x+1); i++ ) { 52 | for( j = 0; j < (gridSize.y+1); j++ ) { 53 | CCVertex3D v = originalVertex(ccGridSize.ccg(i,j)); 54 | CGPoint vect = CGPoint.ccpSub(position, CGPoint.ccp(v.x,v.y)); 55 | float r = CGPoint.ccpLength(vect); 56 | 57 | if ( r < radius ) { 58 | r = radius - r; 59 | float rate = (float)Math.pow( r / radius, 2); 60 | v.z += (Math.sin( time*Math.PI*waves*2 + r * 0.1f) * amplitude * amplitudeRate * rate ); 61 | } 62 | 63 | setVertex(ccGridSize.ccg(i,j), v); 64 | } 65 | } 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /src/org/cocos2d/actions/grid/CCTwirl.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.actions.grid; 2 | 3 | import org.cocos2d.types.CCVertex3D; 4 | import org.cocos2d.types.CGPoint; 5 | import org.cocos2d.types.ccGridSize; 6 | 7 | /** CCTwirl action */ 8 | public class CCTwirl extends CCGrid3DAction { 9 | /** twirl center */ 10 | CGPoint position; 11 | 12 | int twirls; 13 | /** amplitude */ 14 | float amplitude; 15 | /** amplitude rate */ 16 | float amplitudeRate; 17 | 18 | 19 | /** creates the action with center position, number of twirls, amplitude, a grid size and duration */ 20 | public static CCTwirl action(CGPoint pos, int t, float amp, ccGridSize gridSize, float d) { 21 | return new CCTwirl(pos, t, amp, gridSize, d); 22 | } 23 | 24 | /** initializes the action with center position, number of twirls, amplitude, a grid size and duration */ 25 | public CCTwirl(CGPoint pos, int t, float amp, ccGridSize gSize, float d) { 26 | super(gSize, d); 27 | position = CGPoint.make(pos.x, pos.y); 28 | twirls = t; 29 | amplitude = amp; 30 | amplitudeRate = 1.0f; 31 | } 32 | 33 | @Override 34 | public void update (float time) { 35 | int i, j; 36 | CGPoint c = position; 37 | 38 | CGPoint d = new CGPoint(); 39 | 40 | for( i = 0; i < (gridSize.x+1); i++ ) { 41 | for( j = 0; j < (gridSize.y+1); j++ ) { 42 | CCVertex3D v = originalVertex(ccGridSize.ccg(i,j)); 43 | 44 | CGPoint avg = CGPoint.ccp(i-(gridSize.x/2.0f), j-(gridSize.y/2.0f)); 45 | float r = CGPoint.ccpLength( avg ); 46 | 47 | float amp = 0.1f * amplitude * amplitudeRate; 48 | float a = (float)(r * Math.cos(Math.PI/2.0f + time * Math.PI * twirls * 2 ) * amp); 49 | 50 | 51 | d.x = (float)(Math.sin(a) * (v.y-c.y) + Math.cos(a) * (v.x-c.x)); 52 | d.y = (float)(Math.cos(a) * (v.y-c.y) - Math.sin(a) * (v.x-c.x)); 53 | 54 | v.x = c.x + d.x; 55 | v.y = c.y + d.y; 56 | 57 | setVertex(ccGridSize.ccg(i,j), v); 58 | } 59 | } 60 | } 61 | 62 | @Override 63 | public CCTwirl copy() { 64 | CCTwirl copy = new CCTwirl(position, twirls, amplitude, gridSize, duration); 65 | return copy; 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /src/org/cocos2d/transitions/CCJumpZoomTransition.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.transitions; 2 | 3 | import org.cocos2d.actions.instant.CCCallFunc; 4 | import org.cocos2d.actions.interval.CCDelayTime; 5 | import org.cocos2d.actions.interval.CCIntervalAction; 6 | import org.cocos2d.actions.interval.CCJumpBy; 7 | import org.cocos2d.actions.interval.CCScaleTo; 8 | import org.cocos2d.actions.interval.CCSequence; 9 | import org.cocos2d.layers.CCScene; 10 | import org.cocos2d.nodes.CCDirector; 11 | import org.cocos2d.types.CGPoint; 12 | import org.cocos2d.types.CGSize; 13 | 14 | /** 15 | * JumpZoom Transition. 16 | * Zoom out and jump the outgoing scene, and then jump and zoom in the incoming 17 | */ 18 | public class CCJumpZoomTransition extends CCTransitionScene { 19 | 20 | public static CCJumpZoomTransition transition(float t, CCScene s) { 21 | return new CCJumpZoomTransition(t, s); 22 | } 23 | 24 | public CCJumpZoomTransition(float t, CCScene s) { 25 | super(t, s); 26 | } 27 | 28 | @Override 29 | public void onEnter() { 30 | super.onEnter(); 31 | CGSize size = CCDirector.sharedDirector().winSize(); 32 | 33 | float width = size.width; 34 | // float height = size.getHeight(); 35 | 36 | inScene.setScale(0.5f); 37 | inScene.setPosition(width, 0); 38 | 39 | inScene.setAnchorPoint(0.5f, 0.5f); 40 | outScene.setAnchorPoint(0.5f, 0.5f); 41 | 42 | CCIntervalAction jump = CCJumpBy.action(duration / 4, CGPoint.make(-width, 0), width / 4, 2); 43 | CCIntervalAction scaleIn = CCScaleTo.action(duration / 4, 1.0f); 44 | CCIntervalAction scaleOut = CCScaleTo.action(duration / 4, 0.5f); 45 | 46 | CCIntervalAction jumpZoomOut = CCSequence.actions(scaleOut, jump); 47 | CCIntervalAction jumpZoomIn = CCSequence.actions(jump.copy(), scaleIn); 48 | 49 | CCIntervalAction delay = CCDelayTime.action(duration / 2); 50 | 51 | outScene.runAction(jumpZoomOut); 52 | inScene.runAction(CCSequence.actions(delay, jumpZoomIn, 53 | CCCallFunc.action(this, "finish"))); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/org/cocos2d/transitions/CCFlipXTransition.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.transitions; 2 | 3 | import org.cocos2d.actions.camera.CCOrbitCamera; 4 | import org.cocos2d.actions.instant.CCCallFunc; 5 | import org.cocos2d.actions.instant.CCHide; 6 | import org.cocos2d.actions.instant.CCShow; 7 | import org.cocos2d.actions.interval.CCDelayTime; 8 | import org.cocos2d.actions.interval.CCIntervalAction; 9 | import org.cocos2d.actions.interval.CCSequence; 10 | import org.cocos2d.layers.CCScene; 11 | 12 | /** 13 | * FlipX Transition. 14 | * Flips the screen horizontally. 15 | * The front face is the outgoing scene and the back face is the incoming scene. 16 | */ 17 | public class CCFlipXTransition extends CCOrientedTransitionScene { 18 | 19 | public static CCFlipXTransition transition(float t, CCScene s, int orientation) { 20 | return new CCFlipXTransition(t, s, orientation); 21 | } 22 | 23 | public CCFlipXTransition(float t, CCScene s, int orientation) { 24 | super(t, s, orientation); 25 | } 26 | 27 | public void onEnter() { 28 | super.onEnter(); 29 | 30 | CCIntervalAction inA, outA; 31 | inScene.setVisible(false); 32 | 33 | float inDeltaZ, inAngleZ; 34 | float outDeltaZ, outAngleZ; 35 | 36 | if (orientation == tOrientation.kOrientationRightOver) { 37 | inDeltaZ = 90; 38 | inAngleZ = 270; 39 | outDeltaZ = 90; 40 | outAngleZ = 0; 41 | } else { 42 | inDeltaZ = -90; 43 | inAngleZ = 90; 44 | outDeltaZ = -90; 45 | outAngleZ = 0; 46 | } 47 | 48 | inA = CCSequence.actions(CCDelayTime.action(duration / 2), CCShow.action(), 49 | CCOrbitCamera.action(duration / 2, 1, 0, inAngleZ, inDeltaZ, 0, 0), 50 | CCCallFunc.action(this, "finish")); 51 | outA = CCSequence.actions( 52 | CCOrbitCamera.action(duration / 2, 1, 0, outAngleZ, outDeltaZ, 0, 0), 53 | CCHide.action(), CCDelayTime.action(duration / 2)); 54 | 55 | inScene.runAction(inA); 56 | outScene.runAction(outA); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/org/cocos2d/transitions/CCFlipYTransition.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.transitions; 2 | 3 | import org.cocos2d.actions.camera.CCOrbitCamera; 4 | import org.cocos2d.actions.instant.CCCallFunc; 5 | import org.cocos2d.actions.instant.CCHide; 6 | import org.cocos2d.actions.instant.CCShow; 7 | import org.cocos2d.actions.interval.CCDelayTime; 8 | import org.cocos2d.actions.interval.CCIntervalAction; 9 | import org.cocos2d.actions.interval.CCSequence; 10 | import org.cocos2d.layers.CCScene; 11 | 12 | // TODO 13 | /** 14 | * FlipY Transition. 15 | * Flips the screen vertically. 16 | * The front face is the outgoing scene and the back face is the incoming scene. 17 | */ 18 | public class CCFlipYTransition extends CCOrientedTransitionScene { 19 | 20 | public static CCFlipYTransition transition(float t, CCScene s, int orientation) { 21 | return new CCFlipYTransition(t, s, orientation); 22 | } 23 | 24 | public CCFlipYTransition(float t, CCScene s, int orientation) { 25 | super(t, s, orientation); 26 | } 27 | 28 | public void onEnter() { 29 | super.onEnter(); 30 | 31 | CCIntervalAction inA, outA; 32 | inScene.setVisible(false); 33 | 34 | float inDeltaZ, inAngleZ; 35 | float outDeltaZ, outAngleZ; 36 | 37 | if (orientation == tOrientation.kOrientationUpOver) { 38 | inDeltaZ = 90; 39 | inAngleZ = 270; 40 | outDeltaZ = 90; 41 | outAngleZ = 0; 42 | } else { 43 | inDeltaZ = -90; 44 | inAngleZ = 90; 45 | outDeltaZ = -90; 46 | outAngleZ = 0; 47 | } 48 | 49 | inA = CCSequence.actions(CCDelayTime.action(duration / 2), CCShow.action(), 50 | CCOrbitCamera.action(duration / 2, 1, 0, inAngleZ, inDeltaZ, 90, 0), 51 | CCCallFunc.action(this, "finish")); 52 | 53 | outA = CCSequence.actions(CCOrbitCamera.action(duration / 2, 1, 0, outAngleZ, outDeltaZ, 90, 0), 54 | CCHide.action(), CCDelayTime.action(duration / 2)); 55 | 56 | 57 | inScene.runAction(inA); 58 | outScene.runAction(outA); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/org/cocos2d/transitions/CCFlipAngularTransition.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.transitions; 2 | 3 | import org.cocos2d.actions.camera.CCOrbitCamera; 4 | import org.cocos2d.actions.instant.CCCallFunc; 5 | import org.cocos2d.actions.instant.CCHide; 6 | import org.cocos2d.actions.instant.CCShow; 7 | import org.cocos2d.actions.interval.CCDelayTime; 8 | import org.cocos2d.actions.interval.CCIntervalAction; 9 | import org.cocos2d.actions.interval.CCSequence; 10 | import org.cocos2d.layers.CCScene; 11 | 12 | // TODO 13 | /** 14 | * FlipAngular Transition. 15 | * Flips the screen half horizontally and half vertically. 16 | * The front face is the outgoing scene and the back face is the incoming scene. 17 | */ 18 | public class CCFlipAngularTransition extends CCOrientedTransitionScene { 19 | 20 | public static CCFlipAngularTransition transition(float t, CCScene s, int orientation) { 21 | return new CCFlipAngularTransition(t, s, orientation); 22 | } 23 | 24 | public CCFlipAngularTransition(float t, CCScene s, int orientation) { 25 | super(t, s, orientation); 26 | } 27 | 28 | public void onEnter() { 29 | super.onEnter(); 30 | 31 | CCIntervalAction inA, outA; 32 | inScene.setVisible(false); 33 | 34 | float inDeltaZ, inAngleZ; 35 | float outDeltaZ, outAngleZ; 36 | 37 | if (orientation == tOrientation.kOrientationRightOver) { 38 | inDeltaZ = 90; 39 | inAngleZ = 270; 40 | outDeltaZ = 90; 41 | outAngleZ = 0; 42 | } else { 43 | inDeltaZ = -90; 44 | inAngleZ = 90; 45 | outDeltaZ = -90; 46 | outAngleZ = 0; 47 | } 48 | 49 | inA = CCSequence.actions( 50 | CCDelayTime.action(duration / 2), 51 | CCShow.action(), 52 | CCOrbitCamera.action(duration / 2, 1, 0, inAngleZ, inDeltaZ, -45, 0), 53 | CCCallFunc.action(this, "finish")); 54 | outA = CCSequence.actions( 55 | CCOrbitCamera.action(duration / 2, 1, 0, outAngleZ, outDeltaZ, 45, 0), 56 | CCHide.action(), 57 | CCDelayTime.action(duration / 2)); 58 | 59 | inScene.runAction(inA); 60 | outScene.runAction(outA); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/org/cocos2d/actions/interval/CCSpawn.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.actions.interval; 2 | 3 | import org.cocos2d.actions.base.CCFiniteTimeAction; 4 | import org.cocos2d.nodes.CCNode; 5 | 6 | /** Spawn a new action immediately 7 | */ 8 | // 9 | // Spawn 10 | // 11 | public class CCSpawn extends CCIntervalAction { 12 | 13 | private CCFiniteTimeAction one; 14 | private CCFiniteTimeAction two; 15 | 16 | /** helper constructor to create an array of spawned actions */ 17 | public static CCSpawn actions(CCFiniteTimeAction action1, CCFiniteTimeAction... params) { 18 | CCFiniteTimeAction prev = action1; 19 | 20 | if (action1 != null) { 21 | for (CCFiniteTimeAction now : params) 22 | prev = new CCSpawn(prev, now); 23 | } 24 | return (CCSpawn) prev; 25 | } 26 | 27 | /** initializes the Spawn action with the 2 actions to spawn */ 28 | protected CCSpawn(CCFiniteTimeAction one_, CCFiniteTimeAction two_) { 29 | // assert one != null : "Spawn: argument one must be non-null"; 30 | // assert two != null : "Spawn: argument two must be non-null"; 31 | 32 | super(Math.max(one_.getDuration(), two_.getDuration())); 33 | 34 | float d1 = one_.getDuration(); 35 | float d2 = two_.getDuration(); 36 | 37 | one = one_; 38 | two = two_; 39 | 40 | if (d1 > d2) 41 | two = new CCSequence(two_, new CCDelayTime(d1 - d2)); 42 | else if (d1 < d2) 43 | one = new CCSequence(one_, new CCDelayTime(d2 - d1)); 44 | } 45 | 46 | @Override 47 | public CCIntervalAction copy() { 48 | return new CCSpawn(one.copy(), two.copy()); 49 | } 50 | 51 | 52 | @Override 53 | public void start(CCNode aTarget) { 54 | super.start(aTarget); 55 | one.start(target); 56 | two.start(target); 57 | } 58 | 59 | @Override 60 | public void stop() { 61 | one.stop(); 62 | two.stop(); 63 | super.stop(); 64 | } 65 | 66 | @Override 67 | public void update(float t) { 68 | one.update(t); 69 | two.update(t); 70 | } 71 | 72 | @Override 73 | public CCIntervalAction reverse() { 74 | return new CCSpawn(one.reverse(), two.reverse()); 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/org/cocos2d/actions/grid/CCGridAction.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.actions.grid; 2 | 3 | import org.cocos2d.actions.interval.CCIntervalAction; 4 | import org.cocos2d.actions.interval.CCReverseTime; 5 | import org.cocos2d.grid.CCGridBase; 6 | import org.cocos2d.nodes.CCDirector; 7 | import org.cocos2d.nodes.CCNode; 8 | import org.cocos2d.types.ccGridSize; 9 | 10 | 11 | /** Base class for Grid actions */ 12 | public abstract class CCGridAction extends CCIntervalAction { 13 | /** size of the grid */ 14 | protected ccGridSize gridSize; 15 | 16 | public void setGridSize(ccGridSize gs) { 17 | gridSize = new ccGridSize(gs); 18 | } 19 | 20 | public ccGridSize getGridSize() { 21 | return new ccGridSize(gridSize); 22 | } 23 | 24 | /** initializes the action with size and duration */ 25 | protected CCGridAction(ccGridSize gSize, float d) { 26 | super(d); 27 | gridSize = new ccGridSize(gSize); 28 | } 29 | 30 | @Override 31 | public void start(CCNode aTarget) { 32 | super.start(aTarget); 33 | 34 | CCGridBase newgrid = grid(); 35 | CCGridBase targetGrid = target.getGrid(); 36 | 37 | // Class clazz = newgrid.getClass(); 38 | if (targetGrid != null && targetGrid.reuseGrid() > 0) { 39 | if (targetGrid.isActive() && 40 | targetGrid.getGridWidth() == gridSize.x && 41 | targetGrid.getGridHeight() == gridSize.y && 42 | targetGrid.getClass() == newgrid.getClass()) { 43 | targetGrid.reuse(CCDirector.gl); 44 | } else { 45 | throw new RuntimeException("Cannot reuse grid_"); 46 | } 47 | } else { 48 | if (targetGrid != null && targetGrid.isActive()) 49 | targetGrid.setActive(false); 50 | 51 | target.setGrid(newgrid); 52 | 53 | if (targetGrid != null) 54 | target.getGrid().setActive(true); 55 | } 56 | } 57 | 58 | /** returns the grid */ 59 | public abstract CCGridBase grid(); 60 | 61 | @Override 62 | public abstract CCGridAction copy(); 63 | 64 | @Override 65 | public CCIntervalAction reverse() { 66 | return CCReverseTime.action(this); 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /src/org/cocos2d/actions/tile/CCJumpTiles3D.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.actions.tile; 2 | 3 | import org.cocos2d.types.ccGridSize; 4 | import org.cocos2d.types.ccQuad3; 5 | 6 | 7 | //////////////////////////////////////////////////////////// 8 | 9 | /** CCJumpTiles3D action. 10 | A sin function is executed to move the tiles across the Z axis 11 | */ 12 | public class CCJumpTiles3D extends CCTiledGrid3DAction { 13 | int jumps; 14 | /** amplitude of the sin*/ 15 | float amplitude; 16 | /** amplitude rate */ 17 | float amplitudeRate; 18 | 19 | 20 | /** creates the action with the number of jumps, the sin amplitude, the grid size and the duration */ 21 | public static CCJumpTiles3D action(int j, float amp, ccGridSize gridSize, float d) { 22 | return new CCJumpTiles3D(j, amp, gridSize, d); 23 | } 24 | 25 | /** initializes the action with the number of jumps, the sin amplitude, the grid size and the duration */ 26 | protected CCJumpTiles3D(int j, float amp, ccGridSize gridSize, float d) { 27 | super(gridSize, d); 28 | jumps = j; 29 | amplitude = amp; 30 | amplitudeRate = 1.0f; 31 | } 32 | 33 | @Override 34 | public CCJumpTiles3D copy() { 35 | return new CCJumpTiles3D(jumps, amplitude, gridSize, duration); 36 | } 37 | 38 | 39 | @Override 40 | public void update(float time) { 41 | int i, j; 42 | 43 | float sinz = (float)(Math.sin(Math.PI*time*jumps*2) * amplitude * amplitudeRate ); 44 | float sinz2 = (float)(Math.sin(Math.PI*(time*jumps*2 + 1)) * amplitude * amplitudeRate ); 45 | 46 | for( i = 0; i < gridSize.x; i++ ) { 47 | for( j = 0; j < gridSize.y; j++ ) { 48 | ccQuad3 coords = originalTile(ccGridSize.ccg(i,j)); 49 | 50 | if ( ((i+j) % 2) == 0 ) { 51 | coords.br_z += sinz; 52 | coords.br_z += sinz; 53 | coords.tl_z += sinz; 54 | coords.tr_z += sinz; 55 | } else { 56 | coords.bl_z += sinz2; 57 | coords.br_z += sinz2; 58 | coords.tl_z += sinz2; 59 | coords.tr_z += sinz2; 60 | } 61 | 62 | setTile(ccGridSize.ccg(i,j), coords); 63 | } 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/org/cocos2d/actions/interval/CCBezierTo.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.actions.interval; 2 | 3 | import org.cocos2d.nodes.CCNode; 4 | import org.cocos2d.types.CCBezierConfig; 5 | import org.cocos2d.types.CGPoint; 6 | 7 | /** An action that moves the target with a cubic Bezier curve to a destination point. 8 | @since v0.8.2 9 | */ 10 | public class CCBezierTo extends CCBezierBy { 11 | 12 | /** We need to record the original config. Repeating a bezier movement is continually 13 | * more and more distorted if we continue to subtract the start position. 14 | */ 15 | final CCBezierConfig originalconfig; 16 | 17 | /** creates the action with a duration and a bezier configuration */ 18 | public static CCBezierTo action(float t, CCBezierConfig c) { 19 | return new CCBezierTo(t, c); 20 | } 21 | 22 | /** initializes the action with a duration and a bezier configuration */ 23 | protected CCBezierTo(float t, CCBezierConfig c) { 24 | super(t, c); 25 | originalconfig = new CCBezierConfig(); 26 | originalconfig.controlPoint_1 = CGPoint.ccp(c.controlPoint_1.x, c.controlPoint_1.y); 27 | originalconfig.controlPoint_2 = CGPoint.ccp(c.controlPoint_2.x, c.controlPoint_2.y); 28 | originalconfig.endPosition = CGPoint.ccp(c.endPosition.x, c.endPosition.y); 29 | } 30 | 31 | @Override 32 | public CCBezierTo copy() { 33 | return new CCBezierTo(duration, config); 34 | } 35 | 36 | @Override 37 | public void start(CCNode aTarget) { 38 | super.start(aTarget); 39 | 40 | config.controlPoint_1 = CGPoint.ccpSub(originalconfig.controlPoint_1, startPosition); 41 | config.controlPoint_2 = CGPoint.ccpSub(originalconfig.controlPoint_2, startPosition); 42 | config.endPosition = CGPoint.ccpSub(originalconfig.endPosition, startPosition); 43 | } 44 | 45 | @Override 46 | public CCBezierTo reverse() { 47 | // TODO: reverse it's not working as expected 48 | CCBezierConfig r = new CCBezierConfig(); 49 | r.endPosition = CGPoint.ccpNeg(config.endPosition); 50 | r.controlPoint_1 = CGPoint.ccpAdd(config.controlPoint_2, CGPoint.ccpNeg(config.endPosition)); 51 | r.controlPoint_2 = CGPoint.ccpAdd(config.controlPoint_1, CGPoint.ccpNeg(config.endPosition)); 52 | 53 | return new CCBezierTo(duration, r); 54 | } 55 | } 56 | 57 | -------------------------------------------------------------------------------- /src/org/cocos2d/actions/grid/CCLens3D.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.actions.grid; 2 | 3 | import org.cocos2d.types.CCVertex3D; 4 | import org.cocos2d.types.CGPoint; 5 | import org.cocos2d.types.ccGridSize; 6 | 7 | //////////////////////////////////////////////////////////// 8 | 9 | /** CCLens3D action */ 10 | public class CCLens3D extends CCGrid3DAction { 11 | CGPoint position; 12 | float radius; 13 | 14 | /** lens effect. Defaults to 0.7 - 0 means no effect, 1 is very strong effect */ 15 | float lensEffect; 16 | 17 | /** lens center position */ 18 | CGPoint lastPosition; 19 | 20 | /** creates the action with center position, radius, a grid size and duration */ 21 | public static CCLens3D action(CGPoint pos, float r, ccGridSize gridSize, float d) { 22 | return new CCLens3D(pos, r, gridSize, d); 23 | } 24 | 25 | /** initializes the action with center position, radius, a grid size and duration */ 26 | public CCLens3D(CGPoint pos, float r, ccGridSize gridSize, float d) { 27 | super(gridSize, d); 28 | 29 | position = pos; 30 | radius = r; 31 | lensEffect = 0.7f; 32 | lastPosition = CGPoint.ccp(-1,-1); 33 | } 34 | 35 | @Override 36 | public CCLens3D copy() { 37 | CCLens3D copy = new CCLens3D(position, radius, gridSize, duration); 38 | return copy; 39 | } 40 | 41 | @Override 42 | public void update(float time) { 43 | if ( position.x != lastPosition.x || position.y != lastPosition.y ) { 44 | int i, j; 45 | 46 | for( i = 0; i < gridSize.x+1; i++ ) { 47 | for( j = 0; j < gridSize.y+1; j++ ) { 48 | CCVertex3D v = originalVertex(ccGridSize.ccg(i,j)); 49 | CGPoint vect = CGPoint.ccpSub(position, CGPoint.ccp(v.x,v.y)); 50 | float r = CGPoint.ccpLength(vect); 51 | 52 | if ( r < radius ) { 53 | r = radius - r; 54 | float pre_log = r / radius; 55 | if ( pre_log == 0 ) pre_log = 0.001f; 56 | float l = (float)Math.log(pre_log) * lensEffect; 57 | float new_r = (float)Math.exp( l ) * radius; 58 | 59 | if ( CGPoint.ccpLength(vect) > 0 ) { 60 | vect = CGPoint.ccpNormalize(vect); 61 | CGPoint new_vect = CGPoint.ccpMult(vect, new_r); 62 | v.z += CGPoint.ccpLength(new_vect) * lensEffect; 63 | } 64 | } 65 | 66 | setVertex(ccGridSize.ccg(i,j), v); 67 | } 68 | } 69 | 70 | lastPosition = position; 71 | } 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /src/org/cocos2d/actions/interval/CCBezierBy.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.actions.interval; 2 | 3 | import org.cocos2d.nodes.CCNode; 4 | import org.cocos2d.types.CCBezierConfig; 5 | import org.cocos2d.types.CGPoint; 6 | 7 | 8 | /** 9 | * An action that moves the target with a cubic Bezier curve by a certain distance. 10 | */ 11 | public class CCBezierBy extends CCIntervalAction { 12 | 13 | protected CCBezierConfig config; 14 | protected CGPoint startPosition; 15 | 16 | /** creates the action with a duration and a bezier configuration */ 17 | public static CCBezierBy action(float t, CCBezierConfig c) { 18 | return new CCBezierBy(t, c); 19 | } 20 | 21 | /** initializes the action with a duration and a bezier configuration */ 22 | protected CCBezierBy(float t, CCBezierConfig c) { 23 | super(t); 24 | config = c; 25 | startPosition = CGPoint.make(0, 0); 26 | } 27 | 28 | @Override 29 | public CCIntervalAction copy() { 30 | return new CCBezierBy(duration, config); 31 | } 32 | 33 | @Override 34 | public void start(CCNode aTarget) { 35 | super.start(aTarget); 36 | startPosition = target.getPosition(); 37 | } 38 | 39 | @Override 40 | public void update(float t) { 41 | float xa = 0; 42 | float xb = config.controlPoint_1.x; 43 | float xc = config.controlPoint_2.x; 44 | float xd = config.endPosition.x; 45 | 46 | float ya = 0; 47 | float yb = config.controlPoint_1.y; 48 | float yc = config.controlPoint_2.y; 49 | float yd = config.endPosition.y; 50 | 51 | float x = CCBezierConfig.bezierAt(xa, xb, xc, xd, t); 52 | float y = CCBezierConfig.bezierAt(ya, yb, yc, yd, t); 53 | target.setPosition(CGPoint.make(startPosition.x + x, startPosition.y + y)); 54 | } 55 | 56 | @Override 57 | public CCBezierBy reverse() { 58 | // TODO: reverse it's not working as expected 59 | CCBezierConfig r = new CCBezierConfig(); 60 | r.endPosition = CGPoint.ccpNeg(config.endPosition); 61 | r.controlPoint_1 = CGPoint.ccpAdd(config.controlPoint_2, CGPoint.ccpNeg(config.endPosition)); 62 | r.controlPoint_2 = CGPoint.ccpAdd(config.controlPoint_1, CGPoint.ccpNeg(config.endPosition)); 63 | 64 | return new CCBezierBy(duration, r); 65 | } 66 | 67 | } 68 | 69 | -------------------------------------------------------------------------------- /src/org/cocos2d/actions/grid/CCFlipY3D.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.actions.grid; 2 | 3 | import org.cocos2d.actions.interval.CCIntervalAction; 4 | import org.cocos2d.types.CCVertex3D; 5 | import org.cocos2d.types.ccGridSize; 6 | 7 | //////////////////////////////////////////////////////////// 8 | 9 | /** CCFlipY3D action */ 10 | public class CCFlipY3D extends CCFlipX3D { 11 | public static CCIntervalAction action(float duration) { 12 | return new CCFlipY3D(duration); 13 | } 14 | 15 | public static CCFlipY3D action(ccGridSize gridSize, float duration) { 16 | return new CCFlipY3D(gridSize, duration); 17 | } 18 | 19 | protected CCFlipY3D(float duration) { 20 | this(ccGridSize.ccg(1, 1), duration); 21 | } 22 | 23 | protected CCFlipY3D(ccGridSize gridSize, float duration) { 24 | super(gridSize, duration); 25 | } 26 | 27 | @Override 28 | public void update(float time) { 29 | float angle = (float)Math.PI * time; // 180 degrees 30 | float mz = (float)Math.sin( angle ); 31 | angle = angle / 2.0f; // x calculates degrees from 0 to 90 32 | float my = (float)Math.cos( angle ); 33 | 34 | CCVertex3D v0, v1, v; 35 | CCVertex3D diff = new CCVertex3D(0, 0, 0); 36 | 37 | v0 = originalVertex(ccGridSize.ccg(1,1)); 38 | v1 = originalVertex(ccGridSize.ccg(0,0)); 39 | 40 | float y0 = v0.y; 41 | float y1 = v1.y; 42 | float y; 43 | ccGridSize a, b, c, d; 44 | 45 | if ( y0 > y1 ) { 46 | // Normal Grid 47 | a = ccGridSize.ccg(0,0); 48 | b = ccGridSize.ccg(0,1); 49 | c = ccGridSize.ccg(1,0); 50 | d = ccGridSize.ccg(1,1); 51 | y = y0; 52 | } else { 53 | // Reversed Grid 54 | b = ccGridSize.ccg(0,0); 55 | a = ccGridSize.ccg(0,1); 56 | d = ccGridSize.ccg(1,0); 57 | c = ccGridSize.ccg(1,1); 58 | y = y1; 59 | } 60 | 61 | diff.y = y - y * my; 62 | diff.z = (float)Math.abs( Math.floor( (y * mz) / 4.0f ) ); 63 | 64 | // bottom-left 65 | v = originalVertex(a); 66 | v.y = diff.y; 67 | v.z += diff.z; 68 | setVertex(a, v); 69 | 70 | // upper-left 71 | v = originalVertex(b); 72 | v.y -= diff.y; 73 | v.z -= diff.z; 74 | setVertex(b, v); 75 | 76 | // bottom-right 77 | v = originalVertex(c); 78 | v.y = diff.y; 79 | v.z += diff.z; 80 | setVertex(c, v); 81 | 82 | // upper-right 83 | v = originalVertex(d); 84 | v.y -= diff.y; 85 | v.z -= diff.z; 86 | setVertex(d, v); 87 | } 88 | } 89 | 90 | 91 | -------------------------------------------------------------------------------- /gen/com/example/puzzlegame/R.java: -------------------------------------------------------------------------------- 1 | /* AUTO-GENERATED FILE. DO NOT MODIFY. 2 | * 3 | * This class was automatically generated by the 4 | * aapt tool from the resource data it found. It 5 | * should not be modified by hand. 6 | */ 7 | 8 | package com.example.puzzlegame; 9 | 10 | public final class R { 11 | public static final class attr { 12 | } 13 | public static final class dimen { 14 | /** Default screen margins, per the Android Design guidelines. 15 | 16 | Customize dimensions originally defined in res/values/dimens.xml (such as 17 | screen margins) for sw720dp devices (e.g. 10" tablets) in landscape here. 18 | 19 | */ 20 | public static final int activity_horizontal_margin=0x7f050000; 21 | public static final int activity_vertical_margin=0x7f050001; 22 | } 23 | public static final class drawable { 24 | public static final int ic_launcher=0x7f020000; 25 | } 26 | public static final class id { 27 | public static final int action_settings=0x7f090000; 28 | } 29 | public static final class layout { 30 | public static final int activity_main=0x7f030000; 31 | } 32 | public static final class menu { 33 | public static final int main=0x7f080000; 34 | } 35 | public static final class raw { 36 | public static final int cheer=0x7f040000; 37 | public static final int tileclick=0x7f040001; 38 | } 39 | public static final class string { 40 | public static final int action_settings=0x7f060001; 41 | public static final int app_name=0x7f060000; 42 | public static final int hello_world=0x7f060002; 43 | } 44 | public static final class style { 45 | /** 46 | Base application theme, dependent on API level. This theme is replaced 47 | by AppBaseTheme from res/values-vXX/styles.xml on newer devices. 48 | 49 | 50 | Theme customizations available in newer API levels can go in 51 | res/values-vXX/styles.xml, while customizations related to 52 | backward-compatibility can go here. 53 | 54 | */ 55 | public static final int AppBaseTheme=0x7f070000; 56 | /** Application theme. 57 | All customizations that are NOT specific to a particular API-level can go here. 58 | */ 59 | public static final int AppTheme=0x7f070001; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/org/cocos2d/types/util/CGAffineTransformUtil.java: -------------------------------------------------------------------------------- 1 | package org.cocos2d.types.util; 2 | 3 | import org.cocos2d.types.CGAffineTransform; 4 | 5 | public final class CGAffineTransformUtil { 6 | 7 | public static void copy(CGAffineTransform src, CGAffineTransform dst) { 8 | dst.setTransform(src); 9 | } 10 | 11 | public static void inverse(CGAffineTransform tr) { 12 | double det = tr.getDeterminant(); 13 | if (Math.abs(det) >= CGAffineTransform.ZERO) { 14 | double invDet = 1 / det; 15 | tr.setTransform(tr.m11 * invDet, // m00 16 | -tr.m10 * invDet, // m10 17 | -tr.m01 * invDet, // m01 18 | tr.m00 * invDet, // m11 19 | (tr.m01 * tr.m12 - tr.m11 * tr.m02) * invDet, // m02 20 | (tr.m10 * tr.m02 - tr.m00 * tr.m12) * invDet // m12 21 | ); 22 | } 23 | } 24 | 25 | public static void inverse(CGAffineTransform src, CGAffineTransform dst) { 26 | double det = src.getDeterminant(); 27 | if (Math.abs(det) < CGAffineTransform.ZERO) { 28 | // throw new NoninvertibleTransformException("Determinant is zero"); 29 | dst.setTransform(src); 30 | } else { 31 | double invDet = 1 / det; 32 | dst.setTransform(src.m11 * invDet, // m00 33 | -src.m10 * invDet, // m10 34 | -src.m01 * invDet, // m01 35 | src.m00 * invDet, // m11 36 | (src.m01 * src.m12 - src.m11 * src.m02) * invDet, // m02 37 | (src.m10 * src.m02 - src.m00 * src.m12) * invDet // m12 38 | ); 39 | } 40 | } 41 | 42 | public static void multiply(CGAffineTransform t, CGAffineTransform m) { 43 | t.multiply(m); 44 | } 45 | 46 | /** 47 | * preConcate t1 with t2 48 | * @param t1 in/out 49 | * @param t2 in 50 | */ 51 | public static void preConcate(CGAffineTransform t1, CGAffineTransform t2) { 52 | double m00 = t1.m00 * t2.m00 + t1.m10 * t2.m01; 53 | double m01 = t1.m00 * t2.m10 + t1.m10 * t2.m11; 54 | double m10 = t1.m01 * t2.m00 + t1.m11 * t2.m01; 55 | double m11 = t1.m01 * t2.m10 + t1.m11 * t2.m11; 56 | double m02 = t1.m02 * t2.m00 + t1.m12 * t2.m01 + t2.m02; 57 | double m12 = t1.m02 * t2.m10 + t1.m12 * t2.m11 + t2.m12; 58 | 59 | t1.m00 = m00; 60 | t1.m10 = m10; 61 | t1.m01 = m01; 62 | t1.m11 = m11; 63 | t1.m02 = m02; 64 | t1.m12 = m12; 65 | } 66 | } 67 | --------------------------------------------------------------------------------