mirror of https://github.com/axmolengine/axmol.git
Merge branch 'develop' of https://github.com/cocos2d/cocos2d-x into iss2430-modify_enum
This commit is contained in:
commit
f94a02ac01
|
@ -156,4 +156,104 @@ const int kCCTransitionOrientationDownOver = TransitionScene::ORIENTATION_DOWN_O
|
|||
const int kCCPrioritySystem = Scheduler::PRIORITY_SYSTEM;
|
||||
const int kCCPriorityNonSystemMin = Scheduler::PRIORITY_NON_SYSTEM_MIN;
|
||||
|
||||
void ccDrawInit()
|
||||
{
|
||||
DrawPrimitives::init();
|
||||
}
|
||||
|
||||
void ccDrawFree()
|
||||
{
|
||||
DrawPrimitives::free();
|
||||
}
|
||||
|
||||
void ccDrawPoint( const Point& point )
|
||||
{
|
||||
DrawPrimitives::drawPoint(point);
|
||||
}
|
||||
|
||||
void ccDrawPoints( const Point *points, unsigned int numberOfPoints )
|
||||
{
|
||||
DrawPrimitives::drawPoints(points, numberOfPoints);
|
||||
}
|
||||
|
||||
void ccDrawLine( const Point& origin, const Point& destination )
|
||||
{
|
||||
DrawPrimitives::drawLine(origin, destination);
|
||||
}
|
||||
|
||||
void ccDrawRect( Point origin, Point destination )
|
||||
{
|
||||
DrawPrimitives::drawRect(origin, destination);
|
||||
}
|
||||
|
||||
void ccDrawSolidRect( Point origin, Point destination, Color4F color )
|
||||
{
|
||||
DrawPrimitives::drawSolidRect(origin, destination, color);
|
||||
}
|
||||
|
||||
void ccDrawPoly( const Point *vertices, unsigned int numOfVertices, bool closePolygon )
|
||||
{
|
||||
DrawPrimitives::drawPoly(vertices, numOfVertices, closePolygon);
|
||||
}
|
||||
|
||||
void ccDrawSolidPoly( const Point *poli, unsigned int numberOfPoints, Color4F color )
|
||||
{
|
||||
DrawPrimitives::drawSolidPoly(poli, numberOfPoints, color);
|
||||
}
|
||||
|
||||
void ccDrawCircle( const Point& center, float radius, float angle, unsigned int segments, bool drawLineToCenter, float scaleX, float scaleY)
|
||||
{
|
||||
DrawPrimitives::drawCircle(center, radius, angle, segments, drawLineToCenter, scaleX, scaleY);
|
||||
}
|
||||
|
||||
void ccDrawCircle( const Point& center, float radius, float angle, unsigned int segments, bool drawLineToCenter)
|
||||
{
|
||||
DrawPrimitives::drawCircle(center, radius, angle, segments, drawLineToCenter);
|
||||
}
|
||||
|
||||
void ccDrawSolidCircle( const Point& center, float radius, float angle, unsigned int segments, float scaleX, float scaleY)
|
||||
{
|
||||
DrawPrimitives::drawSolidCircle(center, radius, angle, segments, scaleX, scaleY);
|
||||
}
|
||||
|
||||
void ccDrawSolidCircle( const Point& center, float radius, float angle, unsigned int segments)
|
||||
{
|
||||
DrawPrimitives::drawSolidCircle(center, radius, angle, segments);
|
||||
}
|
||||
|
||||
void ccDrawQuadBezier(const Point& origin, const Point& control, const Point& destination, unsigned int segments)
|
||||
{
|
||||
DrawPrimitives::drawQuadBezier(origin, control, destination, segments);
|
||||
}
|
||||
|
||||
void ccDrawCubicBezier(const Point& origin, const Point& control1, const Point& control2, const Point& destination, unsigned int segments)
|
||||
{
|
||||
DrawPrimitives::drawCubicBezier(origin, control1, control2, destination, segments);
|
||||
}
|
||||
|
||||
void ccDrawCatmullRom( PointArray *arrayOfControlPoints, unsigned int segments )
|
||||
{
|
||||
DrawPrimitives::drawCatmullRom(arrayOfControlPoints, segments);
|
||||
}
|
||||
|
||||
void ccDrawCardinalSpline( PointArray *config, float tension, unsigned int segments )
|
||||
{
|
||||
DrawPrimitives::drawCardinalSpline(config, tension, segments);
|
||||
}
|
||||
|
||||
void ccDrawColor4B( GLubyte r, GLubyte g, GLubyte b, GLubyte a )
|
||||
{
|
||||
DrawPrimitives::drawColor4B(r, g, b, a);
|
||||
}
|
||||
|
||||
void ccDrawColor4F( GLfloat r, GLfloat g, GLfloat b, GLfloat a )
|
||||
{
|
||||
DrawPrimitives::drawColor4F(r, g, b, a);
|
||||
}
|
||||
|
||||
void ccPointSize( GLfloat pointSize )
|
||||
{
|
||||
DrawPrimitives::setPointSize(pointSize);
|
||||
}
|
||||
|
||||
NS_CC_END
|
|
@ -705,7 +705,7 @@ void Director::purgeDirector()
|
|||
LabelBMFont::purgeCachedData();
|
||||
|
||||
// purge all managed caches
|
||||
ccDrawFree();
|
||||
DrawPrimitives::free();
|
||||
AnimationCache::destroyInstance();
|
||||
SpriteFrameCache::destroyInstance();
|
||||
TextureCache::destroyInstance();
|
||||
|
|
|
@ -106,18 +106,18 @@ static void lazy_init( void )
|
|||
}
|
||||
|
||||
// When switching from backround to foreground on android, we want the params to be initialized again
|
||||
void ccDrawInit()
|
||||
void DrawPrimitives::init()
|
||||
{
|
||||
lazy_init();
|
||||
}
|
||||
|
||||
void ccDrawFree()
|
||||
void DrawPrimitives::free()
|
||||
{
|
||||
CC_SAFE_RELEASE_NULL(s_pShader);
|
||||
s_bInitialized = false;
|
||||
}
|
||||
|
||||
void ccDrawPoint( const Point& point )
|
||||
void DrawPrimitives::drawPoint( const Point& point )
|
||||
{
|
||||
lazy_init();
|
||||
|
||||
|
@ -144,7 +144,7 @@ void ccDrawPoint( const Point& point )
|
|||
CC_INCREMENT_GL_DRAWS(1);
|
||||
}
|
||||
|
||||
void ccDrawPoints( const Point *points, unsigned int numberOfPoints )
|
||||
void DrawPrimitives::drawPoints( const Point *points, unsigned int numberOfPoints )
|
||||
{
|
||||
lazy_init();
|
||||
|
||||
|
@ -192,7 +192,7 @@ void ccDrawPoints( const Point *points, unsigned int numberOfPoints )
|
|||
}
|
||||
|
||||
|
||||
void ccDrawLine( const Point& origin, const Point& destination )
|
||||
void DrawPrimitives::drawLine( const Point& origin, const Point& destination )
|
||||
{
|
||||
lazy_init();
|
||||
|
||||
|
@ -217,15 +217,15 @@ void ccDrawLine( const Point& origin, const Point& destination )
|
|||
CC_INCREMENT_GL_DRAWS(1);
|
||||
}
|
||||
|
||||
void ccDrawRect( Point origin, Point destination )
|
||||
void DrawPrimitives::drawRect( Point origin, Point destination )
|
||||
{
|
||||
ccDrawLine(Point(origin.x, origin.y), Point(destination.x, origin.y));
|
||||
ccDrawLine(Point(destination.x, origin.y), Point(destination.x, destination.y));
|
||||
ccDrawLine(Point(destination.x, destination.y), Point(origin.x, destination.y));
|
||||
ccDrawLine(Point(origin.x, destination.y), Point(origin.x, origin.y));
|
||||
DrawPrimitives::drawLine(Point(origin.x, origin.y), Point(destination.x, origin.y));
|
||||
DrawPrimitives::drawLine(Point(destination.x, origin.y), Point(destination.x, destination.y));
|
||||
DrawPrimitives::drawLine(Point(destination.x, destination.y), Point(origin.x, destination.y));
|
||||
DrawPrimitives::drawLine(Point(origin.x, destination.y), Point(origin.x, origin.y));
|
||||
}
|
||||
|
||||
void ccDrawSolidRect( Point origin, Point destination, Color4F color )
|
||||
void DrawPrimitives::drawSolidRect( Point origin, Point destination, Color4F color )
|
||||
{
|
||||
Point vertices[] = {
|
||||
origin,
|
||||
|
@ -234,10 +234,10 @@ void ccDrawSolidRect( Point origin, Point destination, Color4F color )
|
|||
Point(origin.x, destination.y)
|
||||
};
|
||||
|
||||
ccDrawSolidPoly(vertices, 4, color );
|
||||
DrawPrimitives::drawSolidPoly(vertices, 4, color );
|
||||
}
|
||||
|
||||
void ccDrawPoly( const Point *poli, unsigned int numberOfPoints, bool closePolygon )
|
||||
void DrawPrimitives::drawPoly( const Point *poli, unsigned int numberOfPoints, bool closePolygon )
|
||||
{
|
||||
lazy_init();
|
||||
|
||||
|
@ -289,7 +289,7 @@ void ccDrawPoly( const Point *poli, unsigned int numberOfPoints, bool closePolyg
|
|||
CC_INCREMENT_GL_DRAWS(1);
|
||||
}
|
||||
|
||||
void ccDrawSolidPoly( const Point *poli, unsigned int numberOfPoints, Color4F color )
|
||||
void DrawPrimitives::drawSolidPoly( const Point *poli, unsigned int numberOfPoints, Color4F color )
|
||||
{
|
||||
lazy_init();
|
||||
|
||||
|
@ -333,7 +333,7 @@ void ccDrawSolidPoly( const Point *poli, unsigned int numberOfPoints, Color4F co
|
|||
CC_INCREMENT_GL_DRAWS(1);
|
||||
}
|
||||
|
||||
void ccDrawCircle( const Point& center, float radius, float angle, unsigned int segments, bool drawLineToCenter, float scaleX, float scaleY)
|
||||
void DrawPrimitives::drawCircle( const Point& center, float radius, float angle, unsigned int segments, bool drawLineToCenter, float scaleX, float scaleY)
|
||||
{
|
||||
lazy_init();
|
||||
|
||||
|
@ -372,17 +372,17 @@ void ccDrawCircle( const Point& center, float radius, float angle, unsigned int
|
|||
#endif // EMSCRIPTEN
|
||||
glDrawArrays(GL_LINE_STRIP, 0, (GLsizei) segments+additionalSegment);
|
||||
|
||||
free( vertices );
|
||||
::free( vertices );
|
||||
|
||||
CC_INCREMENT_GL_DRAWS(1);
|
||||
}
|
||||
|
||||
void CC_DLL ccDrawCircle( const Point& center, float radius, float angle, unsigned int segments, bool drawLineToCenter)
|
||||
void DrawPrimitives::drawCircle( const Point& center, float radius, float angle, unsigned int segments, bool drawLineToCenter)
|
||||
{
|
||||
ccDrawCircle(center, radius, angle, segments, drawLineToCenter, 1.0f, 1.0f);
|
||||
DrawPrimitives::drawCircle(center, radius, angle, segments, drawLineToCenter, 1.0f, 1.0f);
|
||||
}
|
||||
|
||||
void ccDrawSolidCircle( const Point& center, float radius, float angle, unsigned int segments, float scaleX, float scaleY)
|
||||
void DrawPrimitives::drawSolidCircle( const Point& center, float radius, float angle, unsigned int segments, float scaleX, float scaleY)
|
||||
{
|
||||
lazy_init();
|
||||
|
||||
|
@ -418,17 +418,17 @@ void ccDrawSolidCircle( const Point& center, float radius, float angle, unsigned
|
|||
|
||||
glDrawArrays(GL_TRIANGLE_FAN, 0, (GLsizei) segments+1);
|
||||
|
||||
free( vertices );
|
||||
::free( vertices );
|
||||
|
||||
CC_INCREMENT_GL_DRAWS(1);
|
||||
}
|
||||
|
||||
void CC_DLL ccDrawSolidCircle( const Point& center, float radius, float angle, unsigned int segments)
|
||||
void DrawPrimitives::drawSolidCircle( const Point& center, float radius, float angle, unsigned int segments)
|
||||
{
|
||||
ccDrawSolidCircle(center, radius, angle, segments, 1.0f, 1.0f);
|
||||
DrawPrimitives::drawSolidCircle(center, radius, angle, segments, 1.0f, 1.0f);
|
||||
}
|
||||
|
||||
void ccDrawQuadBezier(const Point& origin, const Point& control, const Point& destination, unsigned int segments)
|
||||
void DrawPrimitives::drawQuadBezier(const Point& origin, const Point& control, const Point& destination, unsigned int segments)
|
||||
{
|
||||
lazy_init();
|
||||
|
||||
|
@ -462,12 +462,12 @@ void ccDrawQuadBezier(const Point& origin, const Point& control, const Point& de
|
|||
CC_INCREMENT_GL_DRAWS(1);
|
||||
}
|
||||
|
||||
void ccDrawCatmullRom( PointArray *points, unsigned int segments )
|
||||
void DrawPrimitives::drawCatmullRom( PointArray *points, unsigned int segments )
|
||||
{
|
||||
ccDrawCardinalSpline( points, 0.5f, segments );
|
||||
DrawPrimitives::drawCardinalSpline( points, 0.5f, segments );
|
||||
}
|
||||
|
||||
void ccDrawCardinalSpline( PointArray *config, float tension, unsigned int segments )
|
||||
void DrawPrimitives::drawCardinalSpline( PointArray *config, float tension, unsigned int segments )
|
||||
{
|
||||
lazy_init();
|
||||
|
||||
|
@ -519,7 +519,7 @@ void ccDrawCardinalSpline( PointArray *config, float tension, unsigned int segm
|
|||
CC_INCREMENT_GL_DRAWS(1);
|
||||
}
|
||||
|
||||
void ccDrawCubicBezier(const Point& origin, const Point& control1, const Point& control2, const Point& destination, unsigned int segments)
|
||||
void DrawPrimitives::drawCubicBezier(const Point& origin, const Point& control1, const Point& control2, const Point& destination, unsigned int segments)
|
||||
{
|
||||
lazy_init();
|
||||
|
||||
|
@ -553,7 +553,7 @@ void ccDrawCubicBezier(const Point& origin, const Point& control1, const Point&
|
|||
CC_INCREMENT_GL_DRAWS(1);
|
||||
}
|
||||
|
||||
void ccDrawColor4F( GLfloat r, GLfloat g, GLfloat b, GLfloat a )
|
||||
void DrawPrimitives::drawColor4F( GLfloat r, GLfloat g, GLfloat b, GLfloat a )
|
||||
{
|
||||
s_tColor.r = r;
|
||||
s_tColor.g = g;
|
||||
|
@ -561,7 +561,7 @@ void ccDrawColor4F( GLfloat r, GLfloat g, GLfloat b, GLfloat a )
|
|||
s_tColor.a = a;
|
||||
}
|
||||
|
||||
void ccPointSize( GLfloat pointSize )
|
||||
void DrawPrimitives::setPointSize( GLfloat pointSize )
|
||||
{
|
||||
s_fPointSize = pointSize * CC_CONTENT_SCALE_FACTOR();
|
||||
|
||||
|
@ -569,7 +569,7 @@ void ccPointSize( GLfloat pointSize )
|
|||
|
||||
}
|
||||
|
||||
void ccDrawColor4B( GLubyte r, GLubyte g, GLubyte b, GLubyte a )
|
||||
void DrawPrimitives::drawColor4B( GLubyte r, GLubyte g, GLubyte b, GLubyte a )
|
||||
{
|
||||
s_tColor.r = r/255.0f;
|
||||
s_tColor.g = g/255.0f;
|
||||
|
|
|
@ -47,18 +47,18 @@ THE SOFTWARE.
|
|||
/**
|
||||
@file
|
||||
Drawing OpenGL ES primitives.
|
||||
- ccDrawPoint, ccDrawPoints
|
||||
- ccDrawLine
|
||||
- ccDrawRect, ccDrawSolidRect
|
||||
- ccDrawPoly, ccDrawSolidPoly
|
||||
- ccDrawCircle
|
||||
- ccDrawQuadBezier
|
||||
- ccDrawCubicBezier
|
||||
- ccDrawCatmullRom
|
||||
- ccDrawCardinalSpline
|
||||
- drawPoint, drawPoints
|
||||
- drawLine
|
||||
- drawRect, drawSolidRect
|
||||
- drawPoly, drawSolidPoly
|
||||
- drawCircle
|
||||
- drawQuadBezier
|
||||
- drawCubicBezier
|
||||
- drawCatmullRom
|
||||
- drawCardinalSpline
|
||||
|
||||
You can change the color, point size, width by calling:
|
||||
- ccDrawColor4B(), ccDrawColor4F()
|
||||
- drawColor4B(), drawColor4F()
|
||||
- ccPointSize()
|
||||
- glLineWidth()
|
||||
|
||||
|
@ -75,86 +75,91 @@ NS_CC_BEGIN
|
|||
|
||||
class PointArray;
|
||||
|
||||
/** Initializes the drawing primitives */
|
||||
void CC_DLL ccDrawInit();
|
||||
class CC_DLL DrawPrimitives
|
||||
{
|
||||
public:
|
||||
/** Initializes the drawing primitives */
|
||||
static void init();
|
||||
|
||||
/** Frees allocated resources by the drawing primitives */
|
||||
void CC_DLL ccDrawFree();
|
||||
/** Frees allocated resources by the drawing primitives */
|
||||
static void free();
|
||||
|
||||
/** draws a point given x and y coordinate measured in points */
|
||||
void CC_DLL ccDrawPoint( const Point& point );
|
||||
/** draws a point given x and y coordinate measured in points */
|
||||
static void drawPoint( const Point& point );
|
||||
|
||||
/** draws an array of points.
|
||||
@since v0.7.2
|
||||
*/
|
||||
void CC_DLL ccDrawPoints( const Point *points, unsigned int numberOfPoints );
|
||||
/** draws an array of points.
|
||||
@since v0.7.2
|
||||
*/
|
||||
static void drawPoints( const Point *points, unsigned int numberOfPoints );
|
||||
|
||||
/** draws a line given the origin and destination point measured in points */
|
||||
void CC_DLL ccDrawLine( const Point& origin, const Point& destination );
|
||||
/** draws a line given the origin and destination point measured in points */
|
||||
static void drawLine( const Point& origin, const Point& destination );
|
||||
|
||||
/** draws a rectangle given the origin and destination point measured in points. */
|
||||
void CC_DLL ccDrawRect( Point origin, Point destination );
|
||||
/** draws a rectangle given the origin and destination point measured in points. */
|
||||
static void drawRect( Point origin, Point destination );
|
||||
|
||||
/** draws a solid rectangle given the origin and destination point measured in points.
|
||||
@since 1.1
|
||||
*/
|
||||
void CC_DLL ccDrawSolidRect( Point origin, Point destination, Color4F color );
|
||||
/** draws a solid rectangle given the origin and destination point measured in points.
|
||||
@since 1.1
|
||||
*/
|
||||
static void drawSolidRect( Point origin, Point destination, Color4F color );
|
||||
|
||||
/** draws a polygon given a pointer to Point coordinates and the number of vertices measured in points.
|
||||
The polygon can be closed or open
|
||||
*/
|
||||
void CC_DLL ccDrawPoly( const Point *vertices, unsigned int numOfVertices, bool closePolygon );
|
||||
/** draws a polygon given a pointer to Point coordinates and the number of vertices measured in points.
|
||||
The polygon can be closed or open
|
||||
*/
|
||||
static void drawPoly( const Point *vertices, unsigned int numOfVertices, bool closePolygon );
|
||||
|
||||
/** draws a solid polygon given a pointer to CGPoint coordinates, the number of vertices measured in points, and a color.
|
||||
*/
|
||||
void CC_DLL ccDrawSolidPoly( const Point *poli, unsigned int numberOfPoints, Color4F color );
|
||||
/** draws a solid polygon given a pointer to CGPoint coordinates, the number of vertices measured in points, and a color.
|
||||
*/
|
||||
static void drawSolidPoly( const Point *poli, unsigned int numberOfPoints, Color4F color );
|
||||
|
||||
/** draws a circle given the center, radius and number of segments. */
|
||||
void CC_DLL ccDrawCircle( const Point& center, float radius, float angle, unsigned int segments, bool drawLineToCenter, float scaleX, float scaleY);
|
||||
void CC_DLL ccDrawCircle( const Point& center, float radius, float angle, unsigned int segments, bool drawLineToCenter);
|
||||
/** draws a circle given the center, radius and number of segments. */
|
||||
static void drawCircle( const Point& center, float radius, float angle, unsigned int segments, bool drawLineToCenter, float scaleX, float scaleY);
|
||||
static void drawCircle( const Point& center, float radius, float angle, unsigned int segments, bool drawLineToCenter);
|
||||
|
||||
/** draws a solid circle given the center, radius and number of segments. */
|
||||
void CC_DLL ccDrawSolidCircle( const Point& center, float radius, float angle, unsigned int segments, float scaleX, float scaleY);
|
||||
void CC_DLL ccDrawSolidCircle( const Point& center, float radius, float angle, unsigned int segments);
|
||||
/** draws a solid circle given the center, radius and number of segments. */
|
||||
static void drawSolidCircle( const Point& center, float radius, float angle, unsigned int segments, float scaleX, float scaleY);
|
||||
static void drawSolidCircle( const Point& center, float radius, float angle, unsigned int segments);
|
||||
|
||||
/** draws a quad bezier path
|
||||
@warning This function could be pretty slow. Use it only for debugging purposes.
|
||||
@since v0.8
|
||||
*/
|
||||
void CC_DLL ccDrawQuadBezier(const Point& origin, const Point& control, const Point& destination, unsigned int segments);
|
||||
/** draws a quad bezier path
|
||||
@warning This function could be pretty slow. Use it only for debugging purposes.
|
||||
@since v0.8
|
||||
*/
|
||||
static void drawQuadBezier(const Point& origin, const Point& control, const Point& destination, unsigned int segments);
|
||||
|
||||
/** draws a cubic bezier path
|
||||
@warning This function could be pretty slow. Use it only for debugging purposes.
|
||||
@since v0.8
|
||||
*/
|
||||
void CC_DLL ccDrawCubicBezier(const Point& origin, const Point& control1, const Point& control2, const Point& destination, unsigned int segments);
|
||||
/** draws a cubic bezier path
|
||||
@warning This function could be pretty slow. Use it only for debugging purposes.
|
||||
@since v0.8
|
||||
*/
|
||||
static void drawCubicBezier(const Point& origin, const Point& control1, const Point& control2, const Point& destination, unsigned int segments);
|
||||
|
||||
/** draws a Catmull Rom path.
|
||||
@warning This function could be pretty slow. Use it only for debugging purposes.
|
||||
@since v2.0
|
||||
*/
|
||||
void CC_DLL ccDrawCatmullRom( PointArray *arrayOfControlPoints, unsigned int segments );
|
||||
/** draws a Catmull Rom path.
|
||||
@warning This function could be pretty slow. Use it only for debugging purposes.
|
||||
@since v2.0
|
||||
*/
|
||||
static void drawCatmullRom( PointArray *arrayOfControlPoints, unsigned int segments );
|
||||
|
||||
/** draws a Cardinal Spline path.
|
||||
@warning This function could be pretty slow. Use it only for debugging purposes.
|
||||
@since v2.0
|
||||
*/
|
||||
void CC_DLL ccDrawCardinalSpline( PointArray *config, float tension, unsigned int segments );
|
||||
/** draws a Cardinal Spline path.
|
||||
@warning This function could be pretty slow. Use it only for debugging purposes.
|
||||
@since v2.0
|
||||
*/
|
||||
static void drawCardinalSpline( PointArray *config, float tension, unsigned int segments );
|
||||
|
||||
/** set the drawing color with 4 unsigned bytes
|
||||
@since v2.0
|
||||
*/
|
||||
void CC_DLL ccDrawColor4B( GLubyte r, GLubyte g, GLubyte b, GLubyte a );
|
||||
/** set the drawing color with 4 unsigned bytes
|
||||
@since v2.0
|
||||
*/
|
||||
static void drawColor4B( GLubyte r, GLubyte g, GLubyte b, GLubyte a );
|
||||
|
||||
/** set the drawing color with 4 floats
|
||||
@since v2.0
|
||||
*/
|
||||
void CC_DLL ccDrawColor4F( GLfloat r, GLfloat g, GLfloat b, GLfloat a );
|
||||
/** set the drawing color with 4 floats
|
||||
@since v2.0
|
||||
*/
|
||||
static void drawColor4F( GLfloat r, GLfloat g, GLfloat b, GLfloat a );
|
||||
|
||||
/** set the point size in points. Default 1.
|
||||
@since v2.0
|
||||
*/
|
||||
void CC_DLL ccPointSize( GLfloat pointSize );
|
||||
/** set the point size in points. Default 1.
|
||||
@since v2.0
|
||||
*/
|
||||
static void setPointSize( GLfloat pointSize );
|
||||
|
||||
};
|
||||
|
||||
// end of global group
|
||||
/// @}
|
||||
|
|
|
@ -940,6 +940,27 @@ CC_DEPRECATED_ATTRIBUTE extern const int kCCPriorityNonSystemMin;
|
|||
/** use log() instead */
|
||||
CC_DEPRECATED_ATTRIBUTE void CC_DLL CCLog(const char * pszFormat, ...) CC_FORMAT_PRINTF(1, 2);
|
||||
|
||||
CC_DEPRECATED_ATTRIBUTE void CC_DLL ccDrawInit();
|
||||
CC_DEPRECATED_ATTRIBUTE void CC_DLL ccDrawFree();
|
||||
CC_DEPRECATED_ATTRIBUTE void CC_DLL ccDrawPoint( const Point& point );
|
||||
CC_DEPRECATED_ATTRIBUTE void CC_DLL ccDrawPoints( const Point *points, unsigned int numberOfPoints );
|
||||
CC_DEPRECATED_ATTRIBUTE void CC_DLL ccDrawLine( const Point& origin, const Point& destination );
|
||||
CC_DEPRECATED_ATTRIBUTE void CC_DLL ccDrawRect( Point origin, Point destination );
|
||||
CC_DEPRECATED_ATTRIBUTE void CC_DLL ccDrawSolidRect( Point origin, Point destination, Color4F color );
|
||||
CC_DEPRECATED_ATTRIBUTE void CC_DLL ccDrawPoly( const Point *vertices, unsigned int numOfVertices, bool closePolygon );
|
||||
CC_DEPRECATED_ATTRIBUTE void CC_DLL ccDrawSolidPoly( const Point *poli, unsigned int numberOfPoints, Color4F color );
|
||||
CC_DEPRECATED_ATTRIBUTE void CC_DLL ccDrawCircle( const Point& center, float radius, float angle, unsigned int segments, bool drawLineToCenter, float scaleX, float scaleY);
|
||||
CC_DEPRECATED_ATTRIBUTE void CC_DLL ccDrawCircle( const Point& center, float radius, float angle, unsigned int segments, bool drawLineToCenter);
|
||||
CC_DEPRECATED_ATTRIBUTE void CC_DLL ccDrawSolidCircle( const Point& center, float radius, float angle, unsigned int segments, float scaleX, float scaleY);
|
||||
CC_DEPRECATED_ATTRIBUTE void CC_DLL ccDrawSolidCircle( const Point& center, float radius, float angle, unsigned int segments);
|
||||
CC_DEPRECATED_ATTRIBUTE void CC_DLL ccDrawQuadBezier(const Point& origin, const Point& control, const Point& destination, unsigned int segments);
|
||||
CC_DEPRECATED_ATTRIBUTE void CC_DLL ccDrawCubicBezier(const Point& origin, const Point& control1, const Point& control2, const Point& destination, unsigned int segments);
|
||||
CC_DEPRECATED_ATTRIBUTE void CC_DLL ccDrawCatmullRom( PointArray *arrayOfControlPoints, unsigned int segments );
|
||||
CC_DEPRECATED_ATTRIBUTE void CC_DLL ccDrawCardinalSpline( PointArray *config, float tension, unsigned int segments );
|
||||
CC_DEPRECATED_ATTRIBUTE void CC_DLL ccDrawColor4B( GLubyte r, GLubyte g, GLubyte b, GLubyte a );
|
||||
CC_DEPRECATED_ATTRIBUTE void CC_DLL ccDrawColor4F( GLfloat r, GLfloat g, GLfloat b, GLfloat a );
|
||||
CC_DEPRECATED_ATTRIBUTE void CC_DLL ccPointSize( GLfloat pointSize );
|
||||
|
||||
// end of data_structures group
|
||||
/// @}
|
||||
|
||||
|
|
|
@ -151,7 +151,7 @@ void ClippingNode::drawFullScreenQuadClearStencil()
|
|||
kmGLPushMatrix();
|
||||
kmGLLoadIdentity();
|
||||
|
||||
ccDrawSolidRect(Point(-1,-1), Point(1,1), Color4F(1, 1, 1, 1));
|
||||
DrawPrimitives::drawSolidRect(Point(-1,-1), Point(1,1), Color4F(1, 1, 1, 1));
|
||||
|
||||
kmGLMatrixMode(KM_GL_PROJECTION);
|
||||
kmGLPopMatrix();
|
||||
|
|
|
@ -1,52 +0,0 @@
|
|||
@echo off
|
||||
:: This script is used to create an android project.
|
||||
:: You should modify _ANDROIDTOOLS _CYGBIN _NDKROOT to work under your environment.
|
||||
:: Don't change it until you know what you do.
|
||||
|
||||
setlocal
|
||||
|
||||
:: Check if it was run under cocos2d-x root
|
||||
if not exist "%cd%\create-android-project.bat" echo Error!!! You should run it under cocos2dx root & pause & exit 2
|
||||
|
||||
if not exist "%~dpn0.sh" echo Script "%~dpn0.sh" not found & pause & exit 3
|
||||
|
||||
:: modify it to work under your environment
|
||||
set _CYGBIN=e:\cygwin\bin
|
||||
if not exist "%_CYGBIN%" echo Couldn't find Cygwin at "%_CYGBIN%" & pause & exit 4
|
||||
|
||||
:: modify it to work under your environment
|
||||
set _ANDROIDTOOLS=e:\android\android-sdk\tools
|
||||
if not exist "%_ANDROIDTOOLS%" echo Couldn't find android sdk tools at "%_ANDROIDTOOLS%" & pause & exit 5
|
||||
|
||||
:: modify it to work under your environment
|
||||
set _NDKROOT=e:\android\android-ndk-r8
|
||||
if not exist "%_NDKROOT%" echo Couldn't find ndk at "%_NDKROOT%" & pause & exit 6
|
||||
|
||||
:: create android project
|
||||
set /P _PACKAGEPATH=Please enter your package path. For example: org.cocos2dx.example:
|
||||
set /P _PROJECTNAME=Please enter your project name:
|
||||
if exist "%CD%\%_PROJECTNAME%" echo "%_PROJECTNAME%" exists, please use another name & pause & exit 7
|
||||
echo "Now cocos2d-x suppurts Android 2.1-update1, 2.2, 2.3 & 3.0"
|
||||
echo "Other versions have not tested."
|
||||
call "%_ANDROIDTOOLS%\android.bat" list targets
|
||||
set /P _TARGETID=Please input target id:
|
||||
set _PROJECTDIR=%CD%\%_PROJECTNAME%
|
||||
|
||||
echo Create android project
|
||||
mkdir %_PROJECTDIR%
|
||||
echo Create Android project inside proj.android
|
||||
call "%_ANDROIDTOOLS%\android.bat" create project -n %_PROJECTNAME% -t %_TARGETID% -k %_PACKAGEPATH% -a %_PROJECTNAME% -p %_PROJECTDIR%\proj.android
|
||||
call "%_ANDROIDTOOLS%\android.bat" update project -l ../../cocos2dx/platform/android/java -p %_PROJECTDIR%\proj.android
|
||||
:: Resolve ___.sh to /cygdrive based *nix path and store in %_CYGSCRIPT%
|
||||
for /f "delims=" %%A in ('%_CYGBIN%\cygpath.exe "%~dpn0.sh"') do set _CYGSCRIPT=%%A
|
||||
|
||||
:: Resolve current dir to cygwin path
|
||||
for /f "delims=" %%A in ('%_CYGBIN%\cygpath.exe "%cd%"') do set _CURRENTDIR=%%A
|
||||
|
||||
:: Resolve ndk dir to cygwin path
|
||||
for /f "delims=" %%A in ('%_CYGBIN%\cygpath.exe "%_NDKROOT%"') do set _NDKROOT=%%A
|
||||
|
||||
:: Throw away temporary env vars and invoke script, passing any args that were passed to us
|
||||
endlocal & %_CYGBIN%\bash --login "%_CYGSCRIPT%" %_CURRENTDIR% %_PROJECTNAME% %_NDKROOT% %_PACKAGEPATH% "windows"
|
||||
|
||||
pause
|
|
@ -1,140 +0,0 @@
|
|||
#!/bin/bash
|
||||
# parameters passed to script
|
||||
# This script should be called by create-android-project.bat
|
||||
# or should be runned in linux shell. It can not be runned under cygwin.
|
||||
# Don't modify the script until you know what you do.
|
||||
PARAMS=$@
|
||||
|
||||
# you can set the environment here and uncomment them if you haven't set them in .bashrc
|
||||
#export NDK_ROOT=
|
||||
#export ANDROID_SDK_ROOT=
|
||||
#export COCOS2DX_ROOT=
|
||||
|
||||
# set environment paramters
|
||||
if [ "x${NDK_ROOT}" == "x" ] ; then
|
||||
NDK_ROOT="/opt/android-ndk"
|
||||
fi
|
||||
|
||||
if [ "x${ANDROID_SDK_ROOT}" == "x" ] ; then
|
||||
ANDROID_SDK_ROOT="/opt/android-sdk-update-manager"
|
||||
fi
|
||||
ANDROID_CMD="${ANDROID_SDK_ROOT}/tools/android"
|
||||
|
||||
if [ "x${COCOS2DX_ROOT}" == "x" ] ; then
|
||||
COCOS2DX_ROOT="${HOME}/cocos2d-x"
|
||||
if [ ! -d $COCOS2DX_ROOT ] ; then
|
||||
COCOS2DX_ROOT=`pwd`
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ ! -d ${NDK_ROOT} -o ! -d ${ANDROID_SDK_ROOT} -o ! -x ${ANDROID_CMD} ] ; then
|
||||
echo "Please set the environment at first"
|
||||
fi
|
||||
|
||||
USE_BOX2D=false
|
||||
USE_CHIPMUNK=false
|
||||
USE_LUA=false
|
||||
|
||||
print_usage(){
|
||||
echo "usage:"
|
||||
echo "$0 [-b|--box2d] [-c|--chipmunk] [-l|--lua]"
|
||||
}
|
||||
|
||||
check_param(){
|
||||
for param in ${PARAMS[@]}
|
||||
do
|
||||
case $param in
|
||||
-b | --box2d)
|
||||
echo using box2d
|
||||
USE_BOX2D=true
|
||||
;;
|
||||
-c | --chipmunk)
|
||||
echo using chipmunk
|
||||
USE_CHIPMUNK=true
|
||||
;;
|
||||
-l | --lua)
|
||||
echo using lua
|
||||
USE_LUA=true
|
||||
;;
|
||||
-linux)
|
||||
// skip it
|
||||
;;
|
||||
*)
|
||||
print_usage
|
||||
exit 1
|
||||
esac
|
||||
done
|
||||
|
||||
if [ $USE_BOX2D == "true" -a $USE_CHIPMUNK == "true" ] ; then
|
||||
echo '[WARN] Using box2d and chipmunk together!'
|
||||
fi
|
||||
}
|
||||
|
||||
# check if it was called by .bat file
|
||||
if [ $# -ge 5 -a "x$5" == "xwindows" ] ; then
|
||||
# should be called by .bat file
|
||||
length=`expr $# - 5`
|
||||
PARAMS=${@:6:$length}
|
||||
check_param
|
||||
ANDROID_SDK_ROOT=$ANDROID_SDK_ROOT COCOS2DX_ROOT=$COCOS2DX_ROOT sh $COCOS2DX_ROOT/template/android/copy_files.sh $1 $2 $3 $4 $USE_BOX2D $USE_CHIPMUNK $USE_LUA
|
||||
exit
|
||||
fi
|
||||
|
||||
# the bash file should not be called by cygwin
|
||||
KERNEL_NAME=`uname -s | grep "CYGWIN*"`
|
||||
if [ "x$KERNEL_NAME" != "x" ] ; then
|
||||
echo "[ERROR] Don't run in cygwin. You should run .bat file"
|
||||
exit
|
||||
fi
|
||||
|
||||
# ok, it was run under linux
|
||||
|
||||
create_android_project(){
|
||||
DEFAULT_PACKAGE_PATH='org.cocos2dx.demo'
|
||||
DEFAULT_TARGET_ID='1'
|
||||
DEFAULT_PROJECT_NAME="Hello"
|
||||
|
||||
echo -n "Input package path [${DEFAULT_PACKAGE_PATH}]:"
|
||||
read PACKAGE_PATH
|
||||
if [ "x${PACKAGE_PATH}" == "x" ] ; then
|
||||
PACKAGE_PATH=${DEFAULT_PACKAGE_PATH}
|
||||
fi
|
||||
|
||||
${ANDROID_CMD} list targets
|
||||
echo -n "Input target id [${DEFAULT_TARGET_ID}]:"
|
||||
read TARGET_ID
|
||||
if [ "x${TARGET_ID}" == "x" ] ; then
|
||||
TARGET_ID=${DEFAULT_TARGET_ID}
|
||||
fi
|
||||
|
||||
echo -n "Input your project name [${DEFAULT_PROJECT_NAME}]:"
|
||||
read PROJECT_NAME
|
||||
if [ "x${PROJECT_NAME}" == "x" ] ; then
|
||||
PROJECT_NAME=${DEFAULT_PROJECT_NAME}
|
||||
fi
|
||||
PROJECT_DIR=`pwd`/${PROJECT_NAME}
|
||||
|
||||
# check if PROJECT_DIR is exist
|
||||
if [ -d $PROJECT_DIR ] ; then
|
||||
echo "$PROJECT_DIR already exist, please use another name"
|
||||
exit
|
||||
fi
|
||||
|
||||
# Make project directory
|
||||
mkdir $PROJECT_DIR
|
||||
# Create Android project inside proj.android
|
||||
$ANDROID_CMD create project -n $PROJECT_NAME -t $TARGET_ID -k $PACKAGE_PATH -a $PROJECT_NAME -p $PROJECT_DIR/proj.android
|
||||
$ANDROID_CMD update project -l ${COCOS2DX_ROOT}/cocos2dx/platform/android/java -p $PROJECT_DIR/proj.android
|
||||
}
|
||||
|
||||
check_param
|
||||
create_android_project
|
||||
|
||||
if [ $0 = "linux" ]; then
|
||||
# invoked by create-linux-android-project.sh
|
||||
ANDROID_SDK_ROOT=$ANDROID_SDK_ROOT COCOS2DX_ROOT=$COCOS2DX_ROOT sh $COCOS2DX_ROOT/template/linux/mycopy_files.sh $COCOS2DX_ROOT $PROJECT_NAME $NDK_ROOT $PACKAGE_PATH $USE_BOX2D $USE_CHIPMUNK $USE_LUA
|
||||
else
|
||||
# invoke template/android/copy_files.sh
|
||||
ANDROID_SDK_ROOT=$ANDROID_SDK_ROOT COCOS2DX_ROOT=$COCOS2DX_ROOT sh $COCOS2DX_ROOT/template/android/copy_files.sh $COCOS2DX_ROOT $PROJECT_DIR $PACKAGE_PATH $USE_BOX2D $USE_CHIPMUNK $USE_LUA
|
||||
fi
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
#! /usr/bin/evn python
|
||||
# filename = create-multi-platform-projects.py
|
||||
|
||||
import os
|
||||
from tools.project_creator import create_project
|
||||
|
||||
if __name__ == '__main__':
|
||||
os.chdir(os.getcwd()+'/tools/project_creator/')
|
||||
create_project.createPlatformProjects()
|
|
@ -94,11 +94,11 @@ bool Tween::init(Bone *bone)
|
|||
}
|
||||
|
||||
|
||||
void Tween::play(MovementBoneData *_movementBoneData, int _durationTo, int _durationTween, int _loop, int _tweenEasing)
|
||||
void Tween::play(MovementBoneData *movementBoneData, int durationTo, int durationTween, int loop, int tweenEasing)
|
||||
{
|
||||
ProcessBase::play(NULL, _durationTo, _durationTween, _loop, _tweenEasing);
|
||||
ProcessBase::play(NULL, durationTo, durationTween, loop, tweenEasing);
|
||||
|
||||
_loopType = (AnimationType)_loop;
|
||||
_loopType = (AnimationType)loop;
|
||||
|
||||
_currentKeyFrame = NULL;
|
||||
_isTweenKeyFrame = false;
|
||||
|
@ -107,14 +107,14 @@ void Tween::play(MovementBoneData *_movementBoneData, int _durationTo, int _dura
|
|||
betweenDuration = 0;
|
||||
_toIndex = 0;
|
||||
|
||||
setMovementBoneData(_movementBoneData);
|
||||
setMovementBoneData(movementBoneData);
|
||||
|
||||
|
||||
if (_movementBoneData->frameList.count() == 1)
|
||||
{
|
||||
_loopType = SINGLE_FRAME;
|
||||
FrameData *_nextKeyFrame = _movementBoneData->getFrameData(0);
|
||||
if(_durationTo == 0)
|
||||
if(durationTo == 0)
|
||||
{
|
||||
setBetween(_nextKeyFrame, _nextKeyFrame);
|
||||
}
|
||||
|
@ -130,7 +130,7 @@ void Tween::play(MovementBoneData *_movementBoneData, int _durationTo, int _dura
|
|||
}
|
||||
else if (_movementBoneData->frameList.count() > 1)
|
||||
{
|
||||
if (_loop)
|
||||
if (loop)
|
||||
{
|
||||
_loopType = ANIMATION_TO_LOOP_BACK;
|
||||
_rawDuration = _movementBoneData->duration;
|
||||
|
@ -141,9 +141,9 @@ void Tween::play(MovementBoneData *_movementBoneData, int _durationTo, int _dura
|
|||
_rawDuration = _movementBoneData->duration - 1;
|
||||
}
|
||||
|
||||
_durationTween = _durationTween * _movementBoneData->scale;
|
||||
_durationTween = durationTween * _movementBoneData->scale;
|
||||
|
||||
if (_loop && _movementBoneData->delay != 0)
|
||||
if (loop && _movementBoneData->delay != 0)
|
||||
{
|
||||
setBetween(_tweenData, tweenNodeTo(updateFrameData(1 - _movementBoneData->delay), _between));
|
||||
|
||||
|
@ -333,6 +333,7 @@ void Tween::arriveKeyFrame(FrameData *keyFrameData)
|
|||
|
||||
FrameData *Tween::tweenNodeTo(float percent, FrameData *node)
|
||||
{
|
||||
|
||||
node = node == NULL ? _tweenData : node;
|
||||
|
||||
node->x = _from->x + percent * _between->x;
|
||||
|
|
|
@ -1,251 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
echo 'cocos2d-x template installer'
|
||||
|
||||
COCOS2D_VER='2.1rc0-x-2.1.4'
|
||||
BASE_TEMPLATE_DIR="/Library/Application Support/Developer/Shared/Xcode"
|
||||
BASE_TEMPLATE_USER_DIR="$HOME/Library/Application Support/Developer/Shared/Xcode"
|
||||
|
||||
force=
|
||||
user_dir=
|
||||
|
||||
usage(){
|
||||
cat << EOF
|
||||
usage: $0 [options]
|
||||
|
||||
Install / update templates for ${COCOS2D_VER}
|
||||
|
||||
OPTIONS:
|
||||
-f force overwrite if directories exist
|
||||
-h this help
|
||||
-u install in user's Library directory instead of global directory
|
||||
EOF
|
||||
}
|
||||
|
||||
while getopts "fhu" OPTION; do
|
||||
case "$OPTION" in
|
||||
f)
|
||||
force=1
|
||||
;;
|
||||
h)
|
||||
usage
|
||||
exit 0
|
||||
;;
|
||||
u)
|
||||
user_dir=1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
# Make sure only root can run our script
|
||||
if [[ ! $user_dir && "$(id -u)" != "0" ]]; then
|
||||
echo ""
|
||||
echo "Error: This script must be run as root in order to copy templates to ${BASE_TEMPLATE_DIR}" 1>&2
|
||||
echo ""
|
||||
echo "Try running it with 'sudo', or with '-u' to install it only you:" 1>&2
|
||||
echo " sudo $0" 1>&2
|
||||
echo "or:" 1>&2
|
||||
echo " $0 -u" 1>&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Make sure root and user_dir is not executed at the same time
|
||||
if [[ $user_dir && "$(id -u)" == "0" ]]; then
|
||||
echo ""
|
||||
echo "Error: Do not run this script as root with the '-u' option." 1>&2
|
||||
echo ""
|
||||
echo "Either use the '-u' option or run it as root, but not both options at the same time." 1>&2
|
||||
echo ""
|
||||
echo "RECOMMENDED WAY:" 1>&2
|
||||
echo " $0 -u -f" 1>&2
|
||||
echo ""
|
||||
exit 1
|
||||
fi
|
||||
|
||||
copy_files(){
|
||||
# SRC_DIR="${SCRIPT_DIR}/${1}"
|
||||
rsync -r --exclude=.svn "$1" "$2"
|
||||
}
|
||||
|
||||
check_dst_dir(){
|
||||
if [[ -d $DST_DIR ]]; then
|
||||
if [[ $force ]]; then
|
||||
echo "removing old libraries: ${DST_DIR}"
|
||||
rm -rf "${DST_DIR}"
|
||||
else
|
||||
echo "templates already installed. To force a re-install use the '-f' parameter"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
echo ...creating destination directory: $DST_DIR
|
||||
mkdir -p "$DST_DIR"
|
||||
}
|
||||
|
||||
# copy_base_mac_files(){
|
||||
# echo ...copying cocos2dx files
|
||||
# copy_files cocos2dx "$LIBS_DIR"
|
||||
|
||||
# echo ...copying CocosDenshion files
|
||||
# copy_files CocosDenshion "$LIBS_DIR"
|
||||
# }
|
||||
|
||||
copy_base_files(){
|
||||
echo ...copying cocos2dx files
|
||||
copy_files cocos2dx "$LIBS_DIR"
|
||||
|
||||
|
||||
echo ...copying CocosDenshion files
|
||||
copy_files CocosDenshion "$LIBS_DIR"
|
||||
}
|
||||
|
||||
copy_cocos2d_files(){
|
||||
echo ...copying cocos2d files
|
||||
copy_files cocos2dx "$LIBS_DIR"
|
||||
copy_files licenses/LICENSE_cocos2d-x.txt "$LIBS_DIR"
|
||||
}
|
||||
|
||||
copy_cocosdenshion_files(){
|
||||
echo ...copying CocosDenshion files
|
||||
copy_files CocosDenshion "$LIBS_DIR"
|
||||
# copy_files licenses/LICENSE_CocosDenshion.txt "$LIBS_DIR"
|
||||
}
|
||||
|
||||
copy_extensions_files(){
|
||||
echo ...copying extension files
|
||||
copy_files extensions "$LIBS_DIR"
|
||||
}
|
||||
|
||||
# copy_cocosdenshionextras_files(){
|
||||
# echo ...copying CocosDenshionExtras files
|
||||
# copy_files CocosDenshion/CocosDenshionExtras "$LIBS_DIR"
|
||||
# }
|
||||
|
||||
# copy_fontlabel_files(){
|
||||
# echo ...copying FontLabel files
|
||||
# copy_files external/FontLabel "$LIBS_DIR"
|
||||
# copy_files licenses/LICENSE_FontLabel.txt "$LIBS_DIR"
|
||||
# }
|
||||
|
||||
# copy_cocoslive_files(){
|
||||
# echo ...copying cocoslive files
|
||||
# copy_files cocoslive "$LIBS_DIR"
|
||||
|
||||
# echo ...copying TouchJSON files
|
||||
# copy_files external/TouchJSON "$LIBS_DIR"
|
||||
# copy_files licenses/LICENSE_TouchJSON.txt "$LIBS_DIR"
|
||||
# }
|
||||
|
||||
print_template_banner(){
|
||||
echo ''
|
||||
echo ''
|
||||
echo ''
|
||||
echo "$1"
|
||||
echo '----------------------------------------------------'
|
||||
echo ''
|
||||
}
|
||||
|
||||
# Xcode4 templates
|
||||
copy_xcode4_project_templates(){
|
||||
TEMPLATE_DIR="$HOME/Library/Developer/Xcode/Templates/cocos2d-x/"
|
||||
|
||||
print_template_banner "Installing Xcode 4 cocos2d-x iOS template"
|
||||
|
||||
DST_DIR="$TEMPLATE_DIR"
|
||||
check_dst_dir
|
||||
|
||||
LIBS_DIR="$DST_DIR""lib_cocos2dx.xctemplate/libs/"
|
||||
mkdir -p "$LIBS_DIR"
|
||||
copy_cocos2d_files
|
||||
|
||||
LIBS_DIR="$DST_DIR""lib_cocosdenshion.xctemplate/libs/"
|
||||
mkdir -p "$LIBS_DIR"
|
||||
copy_cocosdenshion_files
|
||||
|
||||
echo ...copying websockets files
|
||||
LIBS_DIR="$DST_DIR""lib_websockets.xctemplate/libs/libwebsockets"
|
||||
mkdir -p "$LIBS_DIR"
|
||||
copy_files external/libwebsockets/ios "$LIBS_DIR"
|
||||
|
||||
LIBS_DIR="$DST_DIR""lib_extensions.xctemplate/libs/"
|
||||
mkdir -p "$LIBS_DIR"
|
||||
copy_extensions_files
|
||||
|
||||
echo ...copying template files
|
||||
copy_files template/xcode4/ "$DST_DIR"
|
||||
|
||||
echo done!
|
||||
|
||||
print_template_banner "Installing Xcode 4 Chipmunk iOS template"
|
||||
|
||||
|
||||
LIBS_DIR="$DST_DIR""lib_chipmunk.xctemplate/libs/"
|
||||
mkdir -p "$LIBS_DIR"
|
||||
|
||||
echo ...copying Chipmunk files
|
||||
copy_files external/chipmunk "$LIBS_DIR"
|
||||
copy_files licenses/LICENSE_chipmunk.txt "$LIBS_DIR"
|
||||
|
||||
echo done!
|
||||
|
||||
print_template_banner "Installing Xcode 4 Box2d iOS template"
|
||||
|
||||
|
||||
LIBS_DIR="$DST_DIR""lib_box2d.xctemplate/libs/"
|
||||
mkdir -p "$LIBS_DIR"
|
||||
|
||||
echo ...copying Box2D files
|
||||
copy_files external/Box2D "$LIBS_DIR"
|
||||
copy_files licenses/LICENSE_box2d.txt "$LIBS_DIR"
|
||||
|
||||
echo done!
|
||||
|
||||
|
||||
print_template_banner "Installing Xcode 4 lua iOS template"
|
||||
|
||||
|
||||
LIBS_DIR="$DST_DIR""lib_lua.xctemplate/libs/"
|
||||
mkdir -p "$LIBS_DIR"
|
||||
|
||||
echo ...copying lua files
|
||||
copy_files scripting/lua "$LIBS_DIR"
|
||||
copy_files licenses/LICENSE_lua.txt "$LIBS_DIR"
|
||||
copy_files licenses/LICENSE_tolua++.txt "$LIBS_DIR"
|
||||
|
||||
echo done!
|
||||
|
||||
print_template_banner "Installing Xcode 4 JS iOS template"
|
||||
|
||||
LIBS_DIR="$DST_DIR""lib_js.xctemplate/libs/javascript"
|
||||
mkdir -p "$LIBS_DIR"
|
||||
|
||||
echo ...copying js files
|
||||
copy_files scripting/javascript/bindings "$LIBS_DIR"
|
||||
copy_files licenses/LICENSE_js.txt "$LIBS_DIR"
|
||||
|
||||
echo done!
|
||||
|
||||
|
||||
echo ...copying spidermonkey files
|
||||
|
||||
LIBS_DIR="$DST_DIR""lib_spidermonkey.xctemplate/libs/javascript"
|
||||
mkdir -p "$LIBS_DIR"
|
||||
copy_files scripting/javascript/spidermonkey-ios "$LIBS_DIR"
|
||||
|
||||
echo done!
|
||||
|
||||
# Move File Templates to correct position
|
||||
# DST_DIR="$HOME/Library/Developer/Xcode/Templates/File Templates/cocos2d/"
|
||||
# OLD_DIR="$HOME/Library/Developer/Xcode/Templates/cocos2d/"
|
||||
|
||||
# print_template_banner "Installing Xcode 4 CCNode file templates..."
|
||||
|
||||
# check_dst_dir
|
||||
|
||||
# mv -f "$OLD_DIR""/CCNode class.xctemplate" "$DST_DIR"
|
||||
|
||||
echo done!
|
||||
|
||||
}
|
||||
|
||||
copy_xcode4_project_templates
|
|
@ -7,6 +7,8 @@ using namespace pluginx;
|
|||
#include "ProtocolIAP.h"
|
||||
#include "ProtocolAds.h"
|
||||
#include "ProtocolShare.h"
|
||||
#include "ProtocolSocial.h"
|
||||
#include "ProtocolUser.h"
|
||||
|
||||
template<class T>
|
||||
static JSBool dummy_constructor(JSContext *cx, uint32_t argc, jsval *vp) {
|
||||
|
@ -732,48 +734,6 @@ void js_register_pluginx_protocols_ProtocolIAP(JSContext *cx, JSObject *global)
|
|||
JSClass *jsb_ProtocolAds_class;
|
||||
JSObject *jsb_ProtocolAds_prototype;
|
||||
|
||||
JSBool js_pluginx_protocols_ProtocolAds_showAds(JSContext *cx, uint32_t argc, jsval *vp)
|
||||
{
|
||||
jsval *argv = JS_ARGV(cx, vp);
|
||||
JSBool ok = JS_TRUE;
|
||||
JSObject *obj = JS_THIS_OBJECT(cx, vp);
|
||||
js_proxy_t *proxy = jsb_get_js_proxy(obj);
|
||||
cocos2d::plugin::ProtocolAds* cobj = (cocos2d::plugin::ProtocolAds *)(proxy ? proxy->ptr : NULL);
|
||||
JSB_PRECONDITION2( cobj, cx, JS_FALSE, "Invalid Native Object");
|
||||
if (argc == 1) {
|
||||
cocos2d::plugin::ProtocolAds::AdsType arg0;
|
||||
ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0);
|
||||
JSB_PRECONDITION2(ok, cx, JS_FALSE, "Error processing arguments");
|
||||
cobj->showAds(arg0);
|
||||
JS_SET_RVAL(cx, vp, JSVAL_VOID);
|
||||
return JS_TRUE;
|
||||
}
|
||||
if (argc == 2) {
|
||||
cocos2d::plugin::ProtocolAds::AdsType arg0;
|
||||
int arg1;
|
||||
ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0);
|
||||
ok &= jsval_to_int32(cx, argv[1], (int32_t *)&arg1);
|
||||
JSB_PRECONDITION2(ok, cx, JS_FALSE, "Error processing arguments");
|
||||
cobj->showAds(arg0, arg1);
|
||||
JS_SET_RVAL(cx, vp, JSVAL_VOID);
|
||||
return JS_TRUE;
|
||||
}
|
||||
if (argc == 3) {
|
||||
cocos2d::plugin::ProtocolAds::AdsType arg0;
|
||||
int arg1;
|
||||
cocos2d::plugin::ProtocolAds::AdsPos arg2;
|
||||
ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0);
|
||||
ok &= jsval_to_int32(cx, argv[1], (int32_t *)&arg1);
|
||||
ok &= jsval_to_int32(cx, argv[2], (int32_t *)&arg2);
|
||||
JSB_PRECONDITION2(ok, cx, JS_FALSE, "Error processing arguments");
|
||||
cobj->showAds(arg0, arg1, arg2);
|
||||
JS_SET_RVAL(cx, vp, JSVAL_VOID);
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 1);
|
||||
return JS_FALSE;
|
||||
}
|
||||
JSBool js_pluginx_protocols_ProtocolAds_hideAds(JSContext *cx, uint32_t argc, jsval *vp)
|
||||
{
|
||||
jsval *argv = JS_ARGV(cx, vp);
|
||||
|
@ -929,7 +889,6 @@ void js_register_pluginx_protocols_ProtocolAds(JSContext *cx, JSObject *global)
|
|||
};
|
||||
|
||||
static JSFunctionSpec funcs[] = {
|
||||
JS_FN("showAds", js_pluginx_protocols_ProtocolAds_showAds, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
||||
JS_FN("hideAds", js_pluginx_protocols_ProtocolAds_hideAds, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
||||
JS_FN("queryPoints", js_pluginx_protocols_ProtocolAds_queryPoints, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
||||
JS_FN("onAdsResult", js_pluginx_protocols_ProtocolAds_onAdsResult, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
||||
|
@ -1109,6 +1068,347 @@ void js_register_pluginx_protocols_ProtocolShare(JSContext *cx, JSObject *global
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
JSClass *jsb_ProtocolSocial_class;
|
||||
JSObject *jsb_ProtocolSocial_prototype;
|
||||
|
||||
JSBool js_pluginx_protocols_ProtocolSocial_showLeaderboard(JSContext *cx, uint32_t argc, jsval *vp)
|
||||
{
|
||||
jsval *argv = JS_ARGV(cx, vp);
|
||||
JSBool ok = JS_TRUE;
|
||||
JSObject *obj = JS_THIS_OBJECT(cx, vp);
|
||||
js_proxy_t *proxy = jsb_get_js_proxy(obj);
|
||||
cocos2d::plugin::ProtocolSocial* cobj = (cocos2d::plugin::ProtocolSocial *)(proxy ? proxy->ptr : NULL);
|
||||
JSB_PRECONDITION2( cobj, cx, JS_FALSE, "Invalid Native Object");
|
||||
if (argc == 1) {
|
||||
const char* arg0;
|
||||
std::string arg0_tmp; ok &= jsval_to_std_string(cx, argv[0], &arg0_tmp); arg0 = arg0_tmp.c_str();
|
||||
JSB_PRECONDITION2(ok, cx, JS_FALSE, "Error processing arguments");
|
||||
cobj->showLeaderboard(arg0);
|
||||
JS_SET_RVAL(cx, vp, JSVAL_VOID);
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 1);
|
||||
return JS_FALSE;
|
||||
}
|
||||
JSBool js_pluginx_protocols_ProtocolSocial_showAchievements(JSContext *cx, uint32_t argc, jsval *vp)
|
||||
{
|
||||
JSObject *obj = JS_THIS_OBJECT(cx, vp);
|
||||
js_proxy_t *proxy = jsb_get_js_proxy(obj);
|
||||
cocos2d::plugin::ProtocolSocial* cobj = (cocos2d::plugin::ProtocolSocial *)(proxy ? proxy->ptr : NULL);
|
||||
JSB_PRECONDITION2( cobj, cx, JS_FALSE, "Invalid Native Object");
|
||||
if (argc == 0) {
|
||||
cobj->showAchievements();
|
||||
JS_SET_RVAL(cx, vp, JSVAL_VOID);
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 0);
|
||||
return JS_FALSE;
|
||||
}
|
||||
JSBool js_pluginx_protocols_ProtocolSocial_submitScore(JSContext *cx, uint32_t argc, jsval *vp)
|
||||
{
|
||||
jsval *argv = JS_ARGV(cx, vp);
|
||||
JSBool ok = JS_TRUE;
|
||||
JSObject *obj = JS_THIS_OBJECT(cx, vp);
|
||||
js_proxy_t *proxy = jsb_get_js_proxy(obj);
|
||||
cocos2d::plugin::ProtocolSocial* cobj = (cocos2d::plugin::ProtocolSocial *)(proxy ? proxy->ptr : NULL);
|
||||
JSB_PRECONDITION2( cobj, cx, JS_FALSE, "Invalid Native Object");
|
||||
if (argc == 2) {
|
||||
const char* arg0;
|
||||
long arg1;
|
||||
std::string arg0_tmp; ok &= jsval_to_std_string(cx, argv[0], &arg0_tmp); arg0 = arg0_tmp.c_str();
|
||||
ok &= jsval_to_long(cx, argv[1], (long *)&arg1);
|
||||
JSB_PRECONDITION2(ok, cx, JS_FALSE, "Error processing arguments");
|
||||
cobj->submitScore(arg0, arg1);
|
||||
JS_SET_RVAL(cx, vp, JSVAL_VOID);
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 2);
|
||||
return JS_FALSE;
|
||||
}
|
||||
JSBool js_pluginx_protocols_ProtocolSocial_configDeveloperInfo(JSContext *cx, uint32_t argc, jsval *vp)
|
||||
{
|
||||
jsval *argv = JS_ARGV(cx, vp);
|
||||
JSBool ok = JS_TRUE;
|
||||
JSObject *obj = JS_THIS_OBJECT(cx, vp);
|
||||
js_proxy_t *proxy = jsb_get_js_proxy(obj);
|
||||
cocos2d::plugin::ProtocolSocial* cobj = (cocos2d::plugin::ProtocolSocial *)(proxy ? proxy->ptr : NULL);
|
||||
JSB_PRECONDITION2( cobj, cx, JS_FALSE, "Invalid Native Object");
|
||||
if (argc == 1) {
|
||||
TSocialDeveloperInfo arg0;
|
||||
#pragma warning NO CONVERSION TO NATIVE FOR TSocialDeveloperInfo;
|
||||
JSB_PRECONDITION2(ok, cx, JS_FALSE, "Error processing arguments");
|
||||
cobj->configDeveloperInfo(arg0);
|
||||
JS_SET_RVAL(cx, vp, JSVAL_VOID);
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 1);
|
||||
return JS_FALSE;
|
||||
}
|
||||
JSBool js_pluginx_protocols_ProtocolSocial_unlockAchievement(JSContext *cx, uint32_t argc, jsval *vp)
|
||||
{
|
||||
jsval *argv = JS_ARGV(cx, vp);
|
||||
JSBool ok = JS_TRUE;
|
||||
JSObject *obj = JS_THIS_OBJECT(cx, vp);
|
||||
js_proxy_t *proxy = jsb_get_js_proxy(obj);
|
||||
cocos2d::plugin::ProtocolSocial* cobj = (cocos2d::plugin::ProtocolSocial *)(proxy ? proxy->ptr : NULL);
|
||||
JSB_PRECONDITION2( cobj, cx, JS_FALSE, "Invalid Native Object");
|
||||
if (argc == 1) {
|
||||
TAchievementInfo arg0;
|
||||
#pragma warning NO CONVERSION TO NATIVE FOR TAchievementInfo;
|
||||
JSB_PRECONDITION2(ok, cx, JS_FALSE, "Error processing arguments");
|
||||
cobj->unlockAchievement(arg0);
|
||||
JS_SET_RVAL(cx, vp, JSVAL_VOID);
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 1);
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
|
||||
extern JSObject *jsb_PluginProtocol_prototype;
|
||||
|
||||
void js_pluginx_protocols_ProtocolSocial_finalize(JSFreeOp *fop, JSObject *obj) {
|
||||
CCLOGINFO("jsbindings: finalizing JS object %p (ProtocolSocial)", obj);
|
||||
js_proxy_t* nproxy;
|
||||
js_proxy_t* jsproxy;
|
||||
jsproxy = jsb_get_js_proxy(obj);
|
||||
if (jsproxy) {
|
||||
nproxy = jsb_get_native_proxy(jsproxy->ptr);
|
||||
|
||||
// cocos2d::plugin::ProtocolSocial *nobj = static_cast<cocos2d::plugin::ProtocolSocial *>(nproxy->ptr);
|
||||
// if (nobj)
|
||||
// delete nobj;
|
||||
|
||||
jsb_remove_proxy(nproxy, jsproxy);
|
||||
}
|
||||
}
|
||||
|
||||
void js_register_pluginx_protocols_ProtocolSocial(JSContext *cx, JSObject *global) {
|
||||
jsb_ProtocolSocial_class = (JSClass *)calloc(1, sizeof(JSClass));
|
||||
jsb_ProtocolSocial_class->name = "ProtocolSocial";
|
||||
jsb_ProtocolSocial_class->addProperty = JS_PropertyStub;
|
||||
jsb_ProtocolSocial_class->delProperty = JS_PropertyStub;
|
||||
jsb_ProtocolSocial_class->getProperty = JS_PropertyStub;
|
||||
jsb_ProtocolSocial_class->setProperty = JS_StrictPropertyStub;
|
||||
jsb_ProtocolSocial_class->enumerate = JS_EnumerateStub;
|
||||
jsb_ProtocolSocial_class->resolve = JS_ResolveStub;
|
||||
jsb_ProtocolSocial_class->convert = JS_ConvertStub;
|
||||
jsb_ProtocolSocial_class->finalize = js_pluginx_protocols_ProtocolSocial_finalize;
|
||||
jsb_ProtocolSocial_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2);
|
||||
|
||||
static JSPropertySpec properties[] = {
|
||||
{0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER}
|
||||
};
|
||||
|
||||
static JSFunctionSpec funcs[] = {
|
||||
JS_FN("showLeaderboard", js_pluginx_protocols_ProtocolSocial_showLeaderboard, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
||||
JS_FN("showAchievements", js_pluginx_protocols_ProtocolSocial_showAchievements, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
||||
JS_FN("submitScore", js_pluginx_protocols_ProtocolSocial_submitScore, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
||||
JS_FN("configDeveloperInfo", js_pluginx_protocols_ProtocolSocial_configDeveloperInfo, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
||||
JS_FN("unlockAchievement", js_pluginx_protocols_ProtocolSocial_unlockAchievement, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
||||
JS_FS_END
|
||||
};
|
||||
|
||||
JSFunctionSpec *st_funcs = NULL;
|
||||
|
||||
jsb_ProtocolSocial_prototype = JS_InitClass(
|
||||
cx, global,
|
||||
jsb_PluginProtocol_prototype,
|
||||
jsb_ProtocolSocial_class,
|
||||
empty_constructor, 0,
|
||||
properties,
|
||||
funcs,
|
||||
NULL, // no static properties
|
||||
st_funcs);
|
||||
// make the class enumerable in the registered namespace
|
||||
JSBool found;
|
||||
JS_SetPropertyAttributes(cx, global, "ProtocolSocial", JSPROP_ENUMERATE | JSPROP_READONLY, &found);
|
||||
|
||||
// add the proto and JSClass to the type->js info hash table
|
||||
TypeTest<cocos2d::plugin::ProtocolSocial> t;
|
||||
js_type_class_t *p;
|
||||
uint32_t typeId = t.s_id();
|
||||
HASH_FIND_INT(_js_global_type_ht, &typeId, p);
|
||||
if (!p) {
|
||||
p = (js_type_class_t *)malloc(sizeof(js_type_class_t));
|
||||
p->type = typeId;
|
||||
p->jsclass = jsb_ProtocolSocial_class;
|
||||
p->proto = jsb_ProtocolSocial_prototype;
|
||||
p->parentProto = jsb_PluginProtocol_prototype;
|
||||
HASH_ADD_INT(_js_global_type_ht, type, p);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
JSClass *jsb_ProtocolUser_class;
|
||||
JSObject *jsb_ProtocolUser_prototype;
|
||||
|
||||
JSBool js_pluginx_protocols_ProtocolUser_isLogined(JSContext *cx, uint32_t argc, jsval *vp)
|
||||
{
|
||||
JSObject *obj = JS_THIS_OBJECT(cx, vp);
|
||||
js_proxy_t *proxy = jsb_get_js_proxy(obj);
|
||||
cocos2d::plugin::ProtocolUser* cobj = (cocos2d::plugin::ProtocolUser *)(proxy ? proxy->ptr : NULL);
|
||||
JSB_PRECONDITION2( cobj, cx, JS_FALSE, "Invalid Native Object");
|
||||
if (argc == 0) {
|
||||
bool ret = cobj->isLogined();
|
||||
jsval jsret;
|
||||
jsret = BOOLEAN_TO_JSVAL(ret);
|
||||
JS_SET_RVAL(cx, vp, jsret);
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 0);
|
||||
return JS_FALSE;
|
||||
}
|
||||
JSBool js_pluginx_protocols_ProtocolUser_logout(JSContext *cx, uint32_t argc, jsval *vp)
|
||||
{
|
||||
JSObject *obj = JS_THIS_OBJECT(cx, vp);
|
||||
js_proxy_t *proxy = jsb_get_js_proxy(obj);
|
||||
cocos2d::plugin::ProtocolUser* cobj = (cocos2d::plugin::ProtocolUser *)(proxy ? proxy->ptr : NULL);
|
||||
JSB_PRECONDITION2( cobj, cx, JS_FALSE, "Invalid Native Object");
|
||||
if (argc == 0) {
|
||||
cobj->logout();
|
||||
JS_SET_RVAL(cx, vp, JSVAL_VOID);
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 0);
|
||||
return JS_FALSE;
|
||||
}
|
||||
JSBool js_pluginx_protocols_ProtocolUser_configDeveloperInfo(JSContext *cx, uint32_t argc, jsval *vp)
|
||||
{
|
||||
jsval *argv = JS_ARGV(cx, vp);
|
||||
JSBool ok = JS_TRUE;
|
||||
JSObject *obj = JS_THIS_OBJECT(cx, vp);
|
||||
js_proxy_t *proxy = jsb_get_js_proxy(obj);
|
||||
cocos2d::plugin::ProtocolUser* cobj = (cocos2d::plugin::ProtocolUser *)(proxy ? proxy->ptr : NULL);
|
||||
JSB_PRECONDITION2( cobj, cx, JS_FALSE, "Invalid Native Object");
|
||||
if (argc == 1) {
|
||||
TUserDeveloperInfo arg0;
|
||||
#pragma warning NO CONVERSION TO NATIVE FOR TUserDeveloperInfo;
|
||||
JSB_PRECONDITION2(ok, cx, JS_FALSE, "Error processing arguments");
|
||||
cobj->configDeveloperInfo(arg0);
|
||||
JS_SET_RVAL(cx, vp, JSVAL_VOID);
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 1);
|
||||
return JS_FALSE;
|
||||
}
|
||||
JSBool js_pluginx_protocols_ProtocolUser_login(JSContext *cx, uint32_t argc, jsval *vp)
|
||||
{
|
||||
JSObject *obj = JS_THIS_OBJECT(cx, vp);
|
||||
js_proxy_t *proxy = jsb_get_js_proxy(obj);
|
||||
cocos2d::plugin::ProtocolUser* cobj = (cocos2d::plugin::ProtocolUser *)(proxy ? proxy->ptr : NULL);
|
||||
JSB_PRECONDITION2( cobj, cx, JS_FALSE, "Invalid Native Object");
|
||||
if (argc == 0) {
|
||||
cobj->login();
|
||||
JS_SET_RVAL(cx, vp, JSVAL_VOID);
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 0);
|
||||
return JS_FALSE;
|
||||
}
|
||||
JSBool js_pluginx_protocols_ProtocolUser_getSessionID(JSContext *cx, uint32_t argc, jsval *vp)
|
||||
{
|
||||
JSObject *obj = JS_THIS_OBJECT(cx, vp);
|
||||
js_proxy_t *proxy = jsb_get_js_proxy(obj);
|
||||
cocos2d::plugin::ProtocolUser* cobj = (cocos2d::plugin::ProtocolUser *)(proxy ? proxy->ptr : NULL);
|
||||
JSB_PRECONDITION2( cobj, cx, JS_FALSE, "Invalid Native Object");
|
||||
if (argc == 0) {
|
||||
std::string ret = cobj->getSessionID();
|
||||
jsval jsret;
|
||||
jsret = std_string_to_jsval(cx, ret);
|
||||
JS_SET_RVAL(cx, vp, jsret);
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 0);
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
|
||||
extern JSObject *jsb_PluginProtocol_prototype;
|
||||
|
||||
void js_pluginx_protocols_ProtocolUser_finalize(JSFreeOp *fop, JSObject *obj) {
|
||||
CCLOGINFO("jsbindings: finalizing JS object %p (ProtocolUser)", obj);
|
||||
js_proxy_t* nproxy;
|
||||
js_proxy_t* jsproxy;
|
||||
jsproxy = jsb_get_js_proxy(obj);
|
||||
if (jsproxy) {
|
||||
nproxy = jsb_get_native_proxy(jsproxy->ptr);
|
||||
|
||||
// cocos2d::plugin::ProtocolUser *nobj = static_cast<cocos2d::plugin::ProtocolUser *>(nproxy->ptr);
|
||||
// if (nobj)
|
||||
// delete nobj;
|
||||
|
||||
jsb_remove_proxy(nproxy, jsproxy);
|
||||
}
|
||||
}
|
||||
|
||||
void js_register_pluginx_protocols_ProtocolUser(JSContext *cx, JSObject *global) {
|
||||
jsb_ProtocolUser_class = (JSClass *)calloc(1, sizeof(JSClass));
|
||||
jsb_ProtocolUser_class->name = "ProtocolUser";
|
||||
jsb_ProtocolUser_class->addProperty = JS_PropertyStub;
|
||||
jsb_ProtocolUser_class->delProperty = JS_PropertyStub;
|
||||
jsb_ProtocolUser_class->getProperty = JS_PropertyStub;
|
||||
jsb_ProtocolUser_class->setProperty = JS_StrictPropertyStub;
|
||||
jsb_ProtocolUser_class->enumerate = JS_EnumerateStub;
|
||||
jsb_ProtocolUser_class->resolve = JS_ResolveStub;
|
||||
jsb_ProtocolUser_class->convert = JS_ConvertStub;
|
||||
jsb_ProtocolUser_class->finalize = js_pluginx_protocols_ProtocolUser_finalize;
|
||||
jsb_ProtocolUser_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2);
|
||||
|
||||
static JSPropertySpec properties[] = {
|
||||
{0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER}
|
||||
};
|
||||
|
||||
static JSFunctionSpec funcs[] = {
|
||||
JS_FN("isLogined", js_pluginx_protocols_ProtocolUser_isLogined, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
||||
JS_FN("logout", js_pluginx_protocols_ProtocolUser_logout, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
||||
JS_FN("configDeveloperInfo", js_pluginx_protocols_ProtocolUser_configDeveloperInfo, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
||||
JS_FN("login", js_pluginx_protocols_ProtocolUser_login, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
||||
JS_FN("getSessionID", js_pluginx_protocols_ProtocolUser_getSessionID, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
||||
JS_FS_END
|
||||
};
|
||||
|
||||
JSFunctionSpec *st_funcs = NULL;
|
||||
|
||||
jsb_ProtocolUser_prototype = JS_InitClass(
|
||||
cx, global,
|
||||
jsb_PluginProtocol_prototype,
|
||||
jsb_ProtocolUser_class,
|
||||
empty_constructor, 0,
|
||||
properties,
|
||||
funcs,
|
||||
NULL, // no static properties
|
||||
st_funcs);
|
||||
// make the class enumerable in the registered namespace
|
||||
JSBool found;
|
||||
JS_SetPropertyAttributes(cx, global, "ProtocolUser", JSPROP_ENUMERATE | JSPROP_READONLY, &found);
|
||||
|
||||
// add the proto and JSClass to the type->js info hash table
|
||||
TypeTest<cocos2d::plugin::ProtocolUser> t;
|
||||
js_type_class_t *p;
|
||||
uint32_t typeId = t.s_id();
|
||||
HASH_FIND_INT(_js_global_type_ht, &typeId, p);
|
||||
if (!p) {
|
||||
p = (js_type_class_t *)malloc(sizeof(js_type_class_t));
|
||||
p->type = typeId;
|
||||
p->jsclass = jsb_ProtocolUser_class;
|
||||
p->proto = jsb_ProtocolUser_prototype;
|
||||
p->parentProto = jsb_PluginProtocol_prototype;
|
||||
HASH_ADD_INT(_js_global_type_ht, type, p);
|
||||
}
|
||||
}
|
||||
|
||||
void register_all_pluginx_protocols(JSContext* cx, JSObject* obj) {
|
||||
// first, try to get the ns
|
||||
jsval nsval;
|
||||
|
@ -1124,8 +1424,10 @@ void register_all_pluginx_protocols(JSContext* cx, JSObject* obj) {
|
|||
obj = ns;
|
||||
|
||||
js_register_pluginx_protocols_PluginProtocol(cx, obj);
|
||||
js_register_pluginx_protocols_ProtocolUser(cx, obj);
|
||||
js_register_pluginx_protocols_ProtocolShare(cx, obj);
|
||||
js_register_pluginx_protocols_ProtocolIAP(cx, obj);
|
||||
js_register_pluginx_protocols_ProtocolSocial(cx, obj);
|
||||
js_register_pluginx_protocols_ProtocolAnalytics(cx, obj);
|
||||
js_register_pluginx_protocols_ProtocolAds(cx, obj);
|
||||
js_register_pluginx_protocols_PluginManager(cx, obj);
|
||||
|
|
|
@ -63,7 +63,6 @@ JSBool js_pluginx_protocols_ProtocolAds_constructor(JSContext *cx, uint32_t argc
|
|||
void js_pluginx_protocols_ProtocolAds_finalize(JSContext *cx, JSObject *obj);
|
||||
void js_register_pluginx_protocols_ProtocolAds(JSContext *cx, JSObject *global);
|
||||
void register_all_pluginx_protocols(JSContext* cx, JSObject* obj);
|
||||
JSBool js_pluginx_protocols_ProtocolAds_showAds(JSContext *cx, uint32_t argc, jsval *vp);
|
||||
JSBool js_pluginx_protocols_ProtocolAds_hideAds(JSContext *cx, uint32_t argc, jsval *vp);
|
||||
JSBool js_pluginx_protocols_ProtocolAds_queryPoints(JSContext *cx, uint32_t argc, jsval *vp);
|
||||
JSBool js_pluginx_protocols_ProtocolAds_onAdsResult(JSContext *cx, uint32_t argc, jsval *vp);
|
||||
|
@ -81,5 +80,31 @@ void register_all_pluginx_protocols(JSContext* cx, JSObject* obj);
|
|||
JSBool js_pluginx_protocols_ProtocolShare_onShareResult(JSContext *cx, uint32_t argc, jsval *vp);
|
||||
JSBool js_pluginx_protocols_ProtocolShare_share(JSContext *cx, uint32_t argc, jsval *vp);
|
||||
JSBool js_pluginx_protocols_ProtocolShare_configDeveloperInfo(JSContext *cx, uint32_t argc, jsval *vp);
|
||||
|
||||
extern JSClass *jsb_ProtocolSocial_class;
|
||||
extern JSObject *jsb_ProtocolSocial_prototype;
|
||||
|
||||
JSBool js_pluginx_protocols_ProtocolSocial_constructor(JSContext *cx, uint32_t argc, jsval *vp);
|
||||
void js_pluginx_protocols_ProtocolSocial_finalize(JSContext *cx, JSObject *obj);
|
||||
void js_register_pluginx_protocols_ProtocolSocial(JSContext *cx, JSObject *global);
|
||||
void register_all_pluginx_protocols(JSContext* cx, JSObject* obj);
|
||||
JSBool js_pluginx_protocols_ProtocolSocial_showLeaderboard(JSContext *cx, uint32_t argc, jsval *vp);
|
||||
JSBool js_pluginx_protocols_ProtocolSocial_showAchievements(JSContext *cx, uint32_t argc, jsval *vp);
|
||||
JSBool js_pluginx_protocols_ProtocolSocial_submitScore(JSContext *cx, uint32_t argc, jsval *vp);
|
||||
JSBool js_pluginx_protocols_ProtocolSocial_configDeveloperInfo(JSContext *cx, uint32_t argc, jsval *vp);
|
||||
JSBool js_pluginx_protocols_ProtocolSocial_unlockAchievement(JSContext *cx, uint32_t argc, jsval *vp);
|
||||
|
||||
extern JSClass *jsb_ProtocolUser_class;
|
||||
extern JSObject *jsb_ProtocolUser_prototype;
|
||||
|
||||
JSBool js_pluginx_protocols_ProtocolUser_constructor(JSContext *cx, uint32_t argc, jsval *vp);
|
||||
void js_pluginx_protocols_ProtocolUser_finalize(JSContext *cx, JSObject *obj);
|
||||
void js_register_pluginx_protocols_ProtocolUser(JSContext *cx, JSObject *global);
|
||||
void register_all_pluginx_protocols(JSContext* cx, JSObject* obj);
|
||||
JSBool js_pluginx_protocols_ProtocolUser_isLogined(JSContext *cx, uint32_t argc, jsval *vp);
|
||||
JSBool js_pluginx_protocols_ProtocolUser_logout(JSContext *cx, uint32_t argc, jsval *vp);
|
||||
JSBool js_pluginx_protocols_ProtocolUser_configDeveloperInfo(JSContext *cx, uint32_t argc, jsval *vp);
|
||||
JSBool js_pluginx_protocols_ProtocolUser_login(JSContext *cx, uint32_t argc, jsval *vp);
|
||||
JSBool js_pluginx_protocols_ProtocolUser_getSessionID(JSContext *cx, uint32_t argc, jsval *vp);
|
||||
#endif
|
||||
|
||||
|
|
|
@ -152,14 +152,6 @@ configDeveloperInfo : function () {},
|
|||
*/
|
||||
plugin.ProtocolAds = {
|
||||
|
||||
/**
|
||||
* @method showAds
|
||||
* @param {cocos2d::plugin::ProtocolAds::AdsType}
|
||||
* @param {int}
|
||||
* @param {cocos2d::plugin::ProtocolAds::AdsPos}
|
||||
*/
|
||||
showAds : function () {},
|
||||
|
||||
/**
|
||||
* @method hideAds
|
||||
* @param {cocos2d::plugin::ProtocolAds::AdsType}
|
||||
|
@ -223,3 +215,75 @@ share : function () {},
|
|||
configDeveloperInfo : function () {},
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* @class ProtocolSocial
|
||||
*/
|
||||
plugin.ProtocolSocial = {
|
||||
|
||||
/**
|
||||
* @method showLeaderboard
|
||||
* @param {const char*}
|
||||
*/
|
||||
showLeaderboard : function () {},
|
||||
|
||||
/**
|
||||
* @method showAchievements
|
||||
*/
|
||||
showAchievements : function () {},
|
||||
|
||||
/**
|
||||
* @method submitScore
|
||||
* @param {const char*}
|
||||
* @param {long}
|
||||
*/
|
||||
submitScore : function () {},
|
||||
|
||||
/**
|
||||
* @method configDeveloperInfo
|
||||
* @param {TSocialDeveloperInfo}
|
||||
*/
|
||||
configDeveloperInfo : function () {},
|
||||
|
||||
/**
|
||||
* @method unlockAchievement
|
||||
* @param {TAchievementInfo}
|
||||
*/
|
||||
unlockAchievement : function () {},
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* @class ProtocolUser
|
||||
*/
|
||||
plugin.ProtocolUser = {
|
||||
|
||||
/**
|
||||
* @method isLogined
|
||||
* @return A value converted from C/C++ "bool"
|
||||
*/
|
||||
isLogined : function () {},
|
||||
|
||||
/**
|
||||
* @method logout
|
||||
*/
|
||||
logout : function () {},
|
||||
|
||||
/**
|
||||
* @method configDeveloperInfo
|
||||
* @param {TUserDeveloperInfo}
|
||||
*/
|
||||
configDeveloperInfo : function () {},
|
||||
|
||||
/**
|
||||
* @method login
|
||||
*/
|
||||
login : function () {},
|
||||
|
||||
/**
|
||||
* @method getSessionID
|
||||
* @return A value converted from C/C++ "std::string"
|
||||
*/
|
||||
getSessionID : function () {},
|
||||
|
||||
};
|
||||
|
|
|
@ -42,3 +42,14 @@ plugin.ProtocolShare.ShareResultCode.ShareFail = 1;
|
|||
plugin.ProtocolShare.ShareResultCode.ShareCancel = 2;
|
||||
plugin.ProtocolShare.ShareResultCode.ShareTimeOut = 3;
|
||||
|
||||
plugin.ProtocolSocial.SocialRetCode = {};
|
||||
plugin.ProtocolSocial.SocialRetCode.ScoreSubmitSuccess = 1;
|
||||
plugin.ProtocolSocial.SocialRetCode.ScoreSubmitFailed = 2;
|
||||
plugin.ProtocolSocial.SocialRetCode.AchUnlockSuccess = 3;
|
||||
plugin.ProtocolSocial.SocialRetCode.AchUnlockFailed = 4;
|
||||
|
||||
plugin.ProtocolUser.UserActionResultCode = {};
|
||||
plugin.ProtocolUser.UserActionResultCode.LoginSucceed = 0;
|
||||
plugin.ProtocolUser.UserActionResultCode.LoginFailed = 1;
|
||||
plugin.ProtocolUser.UserActionResultCode.LogoutSucceed = 2;
|
||||
|
||||
|
|
|
@ -221,6 +221,21 @@ JSBool jsval_to_TPaymentInfo(JSContext *cx, jsval v, std::map<std::string, std::
|
|||
return jsval_to_TProductInfo(cx, v, ret);
|
||||
}
|
||||
|
||||
JSBool jsval_to_TSocialDeveloperInfo(JSContext *cx, jsval v, TSocialDeveloperInfo* ret)
|
||||
{
|
||||
return jsval_to_TProductInfo(cx, v, ret);
|
||||
}
|
||||
|
||||
JSBool jsval_to_TAchievementInfo(JSContext *cx, jsval v, TAchievementInfo* ret)
|
||||
{
|
||||
return jsval_to_TProductInfo(cx, v, ret);
|
||||
}
|
||||
|
||||
JSBool jsval_to_TUserDeveloperInfo(JSContext *cx, jsval v, TUserDeveloperInfo* ret)
|
||||
{
|
||||
return jsval_to_TProductInfo(cx, v, ret);
|
||||
}
|
||||
|
||||
JSBool jsval_to_LogEventParamMap(JSContext *cx, jsval v, LogEventParamMap** ret)
|
||||
{
|
||||
JSBool jsret = JS_FALSE;
|
||||
|
|
|
@ -8,6 +8,8 @@
|
|||
#include "ProtocolAnalytics.h"
|
||||
#include "ProtocolAds.h"
|
||||
#include "ProtocolShare.h"
|
||||
#include "ProtocolSocial.h"
|
||||
#include "ProtocolUser.h"
|
||||
|
||||
#ifndef CCLOGINFO
|
||||
#define CCLOGINFO(...)
|
||||
|
@ -29,7 +31,10 @@ JSBool jsval_to_TIAPDeveloperInfo(JSContext *cx, jsval v, TIAPDeveloperInfo* ret
|
|||
JSBool jsval_to_TAdsDeveloperInfo(JSContext *cx, jsval v, TAdsDeveloperInfo* ret);
|
||||
JSBool jsval_to_TShareDeveloperInfo(JSContext *cx, jsval v, TShareDeveloperInfo* ret);
|
||||
JSBool jsval_to_TShareInfo(JSContext *cx, jsval v, TShareInfo* ret);
|
||||
JSBool jsval_to_TSocialDeveloperInfo(JSContext *cx, jsval v, TSocialDeveloperInfo* ret);
|
||||
JSBool jsval_to_TAchievementInfo(JSContext *cx, jsval v, TAchievementInfo* ret);
|
||||
JSBool jsval_to_TPaymentInfo(JSContext *cx, jsval v, std::map<std::string, std::string>* ret);
|
||||
JSBool jsval_to_TUserDeveloperInfo(JSContext *cx, jsval v, TUserDeveloperInfo* ret);
|
||||
JSBool jsval_to_LogEventParamMap(JSContext *cx, jsval v, LogEventParamMap** ret);
|
||||
JSBool jsval_to_StringMap(JSContext *cx, jsval v, StringMap* ret);
|
||||
|
||||
|
|
|
@ -14,6 +14,8 @@ extern JSObject *jsb_ProtocolIAP_prototype;
|
|||
extern JSObject *jsb_ProtocolAds_prototype;
|
||||
extern JSObject *jsb_ProtocolShare_prototype;
|
||||
extern JSObject *jsb_PluginProtocol_prototype;
|
||||
extern JSObject *jsb_ProtocolSocial_prototype;
|
||||
extern JSObject *jsb_ProtocolUser_prototype;
|
||||
|
||||
void register_pluginx_js_extensions(JSContext* cx, JSObject* global)
|
||||
{
|
||||
|
@ -31,7 +33,10 @@ void register_pluginx_js_extensions(JSContext* cx, JSObject* global)
|
|||
|
||||
JS_DefineFunction(cx, jsb_ProtocolIAP_prototype, "setResultListener", js_pluginx_ProtocolIAP_setResultListener, 1, JSPROP_READONLY | JSPROP_PERMANENT);
|
||||
JS_DefineFunction(cx, jsb_ProtocolAds_prototype, "setAdsListener", js_pluginx_ProtocolAds_setAdsListener, 1, JSPROP_READONLY | JSPROP_PERMANENT);
|
||||
JS_DefineFunction(cx, jsb_ProtocolAds_prototype, "showAds", js_pluginx_ProtocolAds_showAds, 1, JSPROP_READONLY | JSPROP_PERMANENT);
|
||||
JS_DefineFunction(cx, jsb_ProtocolShare_prototype, "setResultListener", js_pluginx_ProtocolShare_setResultListener, 1, JSPROP_READONLY | JSPROP_PERMANENT);
|
||||
JS_DefineFunction(cx, jsb_ProtocolSocial_prototype, "setListener", js_pluginx_ProtocolSocial_setListener, 1, JSPROP_READONLY | JSPROP_PERMANENT);
|
||||
JS_DefineFunction(cx, jsb_ProtocolUser_prototype, "setActionListener", js_pluginx_ProtocolUser_setActionListener, 1, JSPROP_READONLY | JSPROP_PERMANENT);
|
||||
JS_DefineFunction(cx, jsb_PluginProtocol_prototype, "callFuncWithParam", js_pluginx_PluginProtocol_callFuncWithParam, 1, JSPROP_READONLY | JSPROP_PERMANENT);
|
||||
JS_DefineFunction(cx, jsb_PluginProtocol_prototype, "callStringFuncWithParam", js_pluginx_PluginProtocol_callStringFuncWithParam, 1, JSPROP_READONLY | JSPROP_PERMANENT);
|
||||
JS_DefineFunction(cx, jsb_PluginProtocol_prototype, "callIntFuncWithParam", js_pluginx_PluginProtocol_callIntFuncWithParam, 1, JSPROP_READONLY | JSPROP_PERMANENT);
|
||||
|
|
|
@ -173,6 +173,47 @@ JSBool js_pluginx_ProtocolAds_setAdsListener(JSContext *cx, uint32_t argc, jsval
|
|||
return JS_FALSE;
|
||||
}
|
||||
|
||||
JSBool js_pluginx_ProtocolAds_showAds(JSContext *cx, uint32_t argc, jsval *vp)
|
||||
{
|
||||
jsval *argv = JS_ARGV(cx, vp);
|
||||
JSBool ok = JS_TRUE;
|
||||
JSObject *obj = JS_THIS_OBJECT(cx, vp);
|
||||
js_proxy_t *proxy = jsb_get_js_proxy(obj);
|
||||
cocos2d::plugin::ProtocolAds* cobj = (cocos2d::plugin::ProtocolAds *)(proxy ? proxy->ptr : NULL);
|
||||
JSB_PRECONDITION2( cobj, cx, JS_FALSE, "Invalid Native Object");
|
||||
if (argc == 1) {
|
||||
jsval params = argv[0];
|
||||
JSObject* tmp = JSVAL_TO_OBJECT(params);
|
||||
JSB_PRECONDITION2(tmp, cx, JS_FALSE, "Error processing arguments");
|
||||
|
||||
jsval tempVal;
|
||||
cocos2d::plugin::ProtocolAds::AdsType arg0;
|
||||
ok &= JS_GetProperty(cx, tmp, "AdsType", &tempVal);
|
||||
JSB_PRECONDITION2(ok, cx, JS_FALSE, "It should be contains 'AdsType' in parameter.");
|
||||
ok &= jsval_to_int32(cx, tempVal, (int32_t *) &arg0);
|
||||
JSB_PRECONDITION2(ok, cx, JS_FALSE, "Value of 'AdsType' must be int");
|
||||
|
||||
int sizeEnum = 0;
|
||||
if (JS_GetProperty(cx, tmp, "SizeEnum", &tempVal)) {
|
||||
ok &= jsval_to_int32(cx, tempVal, (int32_t *) &sizeEnum);
|
||||
JSB_PRECONDITION2(ok, cx, JS_FALSE, "Value of 'SizeEnum' should be int");
|
||||
}
|
||||
|
||||
cocos2d::plugin::ProtocolAds::AdsPos pos;
|
||||
if (JS_GetProperty(cx, tmp, "AdsPos", &tempVal)) {
|
||||
ok &= jsval_to_int32(cx, tempVal, (int32_t *) &pos);
|
||||
JSB_PRECONDITION2(ok, cx, JS_FALSE, "Value of 'AdsPos' should be int");
|
||||
}
|
||||
|
||||
cobj->showAds(arg0, sizeEnum, pos);
|
||||
JS_SET_RVAL(cx, vp, JSVAL_VOID);
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 1);
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
class Pluginx_ShareResult : public cocos2d::plugin::ShareResultListener
|
||||
{
|
||||
public:
|
||||
|
@ -235,3 +276,137 @@ JSBool js_pluginx_ProtocolShare_setResultListener(JSContext *cx, uint32_t argc,
|
|||
JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 1);
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
class Pluginx_SocialResult : public cocos2d::plugin::SocialListener
|
||||
{
|
||||
public:
|
||||
virtual void onSocialResult(cocos2d::plugin::SocialRetCode ret, const char* msg)
|
||||
{
|
||||
JSContext* cx = s_cx;
|
||||
|
||||
JSBool hasAction;
|
||||
jsval retval;
|
||||
jsval temp_retval;
|
||||
jsval dataVal[2];
|
||||
dataVal[0] = INT_TO_JSVAL(ret);
|
||||
std::string strMsgInfo = msg;
|
||||
dataVal[1] = std_string_to_jsval(cx, strMsgInfo);
|
||||
|
||||
JSObject* obj = _JSDelegate;
|
||||
|
||||
if (JS_HasProperty(cx, obj, "onSocialResult", &hasAction) && hasAction) {
|
||||
if(!JS_GetProperty(cx, obj, "onSocialResult", &temp_retval)) {
|
||||
return;
|
||||
}
|
||||
if(temp_retval == JSVAL_VOID) {
|
||||
return;
|
||||
}
|
||||
JSAutoCompartment ac(cx, obj);
|
||||
JS_CallFunctionName(cx, obj, "onSocialResult",
|
||||
2, dataVal, &retval);
|
||||
}
|
||||
}
|
||||
|
||||
void setJSDelegate(JSObject* pJSDelegate)
|
||||
{
|
||||
_JSDelegate = pJSDelegate;
|
||||
}
|
||||
|
||||
private:
|
||||
JSObject* _JSDelegate;
|
||||
};
|
||||
|
||||
JSBool js_pluginx_ProtocolSocial_setListener(JSContext *cx, uint32_t argc, jsval *vp)
|
||||
{
|
||||
s_cx = cx;
|
||||
jsval *argv = JS_ARGV(cx, vp);
|
||||
JSObject *obj = JS_THIS_OBJECT(cx, vp);
|
||||
js_proxy_t *proxy; JS_GET_NATIVE_PROXY(proxy, obj);
|
||||
cocos2d::plugin::ProtocolSocial* cobj = (cocos2d::plugin::ProtocolSocial *)(proxy ? proxy->ptr : NULL);
|
||||
JSBool ok = JS_TRUE;
|
||||
|
||||
if (argc == 1) {
|
||||
// save the delegate
|
||||
JSObject *jsDelegate = JSVAL_TO_OBJECT(argv[0]);
|
||||
Pluginx_SocialResult* nativeDelegate = new Pluginx_SocialResult();
|
||||
nativeDelegate->setJSDelegate(jsDelegate);
|
||||
cobj->setListener(nativeDelegate);
|
||||
|
||||
JS_SET_RVAL(cx, vp, JSVAL_VOID);
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 1);
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
class Pluginx_UserActionListener : public cocos2d::plugin::UserActionListener
|
||||
{
|
||||
public:
|
||||
virtual void onActionResult(ProtocolUser* userPlugin, cocos2d::plugin::UserActionResultCode ret, const char* msg)
|
||||
{
|
||||
JSContext* cx = s_cx;
|
||||
|
||||
JSBool hasAction;
|
||||
jsval retval;
|
||||
jsval temp_retval;
|
||||
|
||||
js_proxy_t * p;
|
||||
JS_GET_PROXY(p, userPlugin);
|
||||
|
||||
if (! p) return;
|
||||
jsval dataVal[3];
|
||||
jsval arg1 = OBJECT_TO_JSVAL(p->obj);
|
||||
dataVal[0] = arg1;
|
||||
dataVal[1] = INT_TO_JSVAL(ret);
|
||||
std::string strMsgInfo = msg;
|
||||
dataVal[2] = std_string_to_jsval(cx, strMsgInfo);
|
||||
|
||||
JSObject* obj = _JSDelegate;
|
||||
|
||||
if (JS_HasProperty(cx, obj, "onActionResult", &hasAction) && hasAction) {
|
||||
if(!JS_GetProperty(cx, obj, "onActionResult", &temp_retval)) {
|
||||
return;
|
||||
}
|
||||
if(temp_retval == JSVAL_VOID) {
|
||||
return;
|
||||
}
|
||||
JSAutoCompartment ac(cx, obj);
|
||||
JS_CallFunctionName(cx, obj, "onActionResult",
|
||||
3, dataVal, &retval);
|
||||
}
|
||||
}
|
||||
|
||||
void setJSDelegate(JSObject* pJSDelegate)
|
||||
{
|
||||
_JSDelegate = pJSDelegate;
|
||||
}
|
||||
|
||||
private:
|
||||
JSObject* _JSDelegate;
|
||||
};
|
||||
|
||||
JSBool js_pluginx_ProtocolUser_setActionListener(JSContext *cx, uint32_t argc, jsval *vp)
|
||||
{
|
||||
s_cx = cx;
|
||||
jsval *argv = JS_ARGV(cx, vp);
|
||||
JSObject *obj = JS_THIS_OBJECT(cx, vp);
|
||||
js_proxy_t *proxy; JS_GET_NATIVE_PROXY(proxy, obj);
|
||||
cocos2d::plugin::ProtocolUser* cobj = (cocos2d::plugin::ProtocolUser *)(proxy ? proxy->ptr : NULL);
|
||||
JSBool ok = JS_TRUE;
|
||||
|
||||
if (argc == 1) {
|
||||
// save the delegate
|
||||
JSObject *jsDelegate = JSVAL_TO_OBJECT(argv[0]);
|
||||
Pluginx_UserActionListener* nativeDelegate = new Pluginx_UserActionListener();
|
||||
nativeDelegate->setJSDelegate(jsDelegate);
|
||||
cobj->setActionListener(nativeDelegate);
|
||||
|
||||
JS_SET_RVAL(cx, vp, JSVAL_VOID);
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 1);
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
|
|
|
@ -6,6 +6,9 @@
|
|||
|
||||
JSBool js_pluginx_ProtocolIAP_setResultListener(JSContext *cx, uint32_t argc, jsval *vp);
|
||||
JSBool js_pluginx_ProtocolAds_setAdsListener(JSContext *cx, uint32_t argc, jsval *vp);
|
||||
JSBool js_pluginx_ProtocolAds_showAds(JSContext *cx, uint32_t argc, jsval *vp);
|
||||
JSBool js_pluginx_ProtocolShare_setResultListener(JSContext *cx, uint32_t argc, jsval *vp);
|
||||
JSBool js_pluginx_ProtocolSocial_setListener(JSContext *cx, uint32_t argc, jsval *vp);
|
||||
JSBool js_pluginx_ProtocolUser_setActionListener(JSContext *cx, uint32_t argc, jsval *vp);
|
||||
|
||||
#endif /* __JS_MANUAL_CALLBACK_H__ */
|
||||
|
|
|
@ -23,11 +23,11 @@ cxxgenerator_headers = -I%(cxxgeneratordir)s/targets/spidermonkey/common
|
|||
extra_arguments = %(android_headers)s %(clang_headers)s %(cxxgenerator_headers)s %(cocos_headers)s %(android_flags)s %(clang_flags)s %(cocos_flags)s
|
||||
|
||||
# what headers to parse
|
||||
headers = %(pluginxdir)s/protocols/include/PluginManager.h %(pluginxdir)s/protocols/include/ProtocolAnalytics.h %(pluginxdir)s/protocols/include/ProtocolIAP.h %(pluginxdir)s/protocols/include/ProtocolAds.h %(pluginxdir)s/protocols/include/ProtocolShare.h
|
||||
headers = %(pluginxdir)s/protocols/include/PluginManager.h %(pluginxdir)s/protocols/include/ProtocolAnalytics.h %(pluginxdir)s/protocols/include/ProtocolIAP.h %(pluginxdir)s/protocols/include/ProtocolAds.h %(pluginxdir)s/protocols/include/ProtocolShare.h %(pluginxdir)s/protocols/include/ProtocolSocial.h %(pluginxdir)s/protocols/include/ProtocolUser.h
|
||||
|
||||
# what classes to produce code for. You can use regular expressions here. When testing the regular
|
||||
# expression, it will be enclosed in "^$", like this: "^CCMenu*$".
|
||||
classes = PluginProtocol PluginManager ProtocolIAP ProtocolAnalytics ProtocolAds ProtocolShare
|
||||
classes = PluginProtocol PluginManager ProtocolIAP ProtocolAnalytics ProtocolAds ProtocolShare ProtocolSocial ProtocolUser
|
||||
|
||||
# what should we skip? in the format ClassName::[function function]
|
||||
# ClassName is a regular expression, but will be used like this: "^ClassName$" functions are also
|
||||
|
@ -37,8 +37,10 @@ classes = PluginProtocol PluginManager ProtocolIAP ProtocolAnalytics ProtocolAds
|
|||
# functions from all classes.
|
||||
|
||||
skip = ProtocolIAP::[setResultListener],
|
||||
ProtocolAds::[setAdsListener],
|
||||
ProtocolAds::[setAdsListener showAds],
|
||||
ProtocolShare::[setResultListener],
|
||||
ProtocolSocial::[setListener getListener],
|
||||
ProtocolUser::[setActionListener getActionListener],
|
||||
PluginProtocol::[callFuncWithParam callStringFuncWithParam callIntFuncWithParam callBoolFuncWithParam callFloatFuncWithParam]
|
||||
|
||||
rename_functions =
|
||||
|
@ -56,7 +58,7 @@ base_classes_to_skip =
|
|||
|
||||
# classes that create no constructor
|
||||
# CCSet is special and we will use a hand-written constructor
|
||||
abstract_classes = PluginProtocol ProtocolIAP ProtocolAnalytics PluginManager ProtocolAds ProtocolShare
|
||||
abstract_classes = PluginProtocol ProtocolIAP ProtocolAnalytics PluginManager ProtocolAds ProtocolShare ProtocolUser ProtocolSocial
|
||||
|
||||
# Determining whether to use script object(js object) to control the lifecycle of native(cpp) object or the other way around. Supported values are 'yes' or 'no'.
|
||||
script_control_cpp = yes
|
||||
|
|
|
@ -36,7 +36,7 @@ void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thi
|
|||
{
|
||||
ccGLInvalidateStateCache();
|
||||
ShaderCache::getInstance()->reloadDefaultShaders();
|
||||
ccDrawInit();
|
||||
DrawPrimitives::init();
|
||||
TextureCache::reloadAllTextures();
|
||||
NotificationCenter::getInstance()->postNotification(EVNET_COME_TO_FOREGROUND, NULL);
|
||||
Director::getInstance()->setGLDefaultValues();
|
||||
|
|
|
@ -36,7 +36,7 @@ void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thi
|
|||
{
|
||||
ccGLInvalidateStateCache();
|
||||
ShaderCache::getInstance()->reloadDefaultShaders();
|
||||
ccDrawInit();
|
||||
DrawPrimitives::init();
|
||||
TextureCache::reloadAllTextures();
|
||||
NotificationCenter::getInstance()->postNotification(EVNET_COME_TO_FOREGROUND, NULL);
|
||||
Director::getInstance()->setGLDefaultValues();
|
||||
|
|
|
@ -35,7 +35,7 @@ void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thi
|
|||
{
|
||||
ccGLInvalidateStateCache();
|
||||
ShaderCache::getInstance()->reloadDefaultShaders();
|
||||
ccDrawInit();
|
||||
DrawPrimitives::init();
|
||||
TextureCache::reloadAllTextures();
|
||||
NotificationCenter::getInstance()->postNotification(EVNET_COME_TO_FOREGROUND, NULL);
|
||||
Director::getInstance()->setGLDefaultValues();
|
||||
|
|
|
@ -32,7 +32,7 @@ void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thi
|
|||
{
|
||||
ccGLInvalidateStateCache();
|
||||
ShaderCache::getInstance()->reloadDefaultShaders();
|
||||
ccDrawInit();
|
||||
DrawPrimitives::init();
|
||||
TextureCache::reloadAllTextures();
|
||||
NotificationCenter::getInstance()->postNotification(EVNET_COME_TO_FOREGROUND, NULL);
|
||||
Director::getInstance()->setGLDefaultValues();
|
||||
|
|
|
@ -34,7 +34,7 @@ void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thi
|
|||
{
|
||||
ccGLInvalidateStateCache();
|
||||
ShaderCache::getInstance()->reloadDefaultShaders();
|
||||
ccDrawInit();
|
||||
DrawPrimitives::init();
|
||||
TextureCache::reloadAllTextures();
|
||||
NotificationCenter::getInstance()->postNotification(EVNET_COME_TO_FOREGROUND, NULL);
|
||||
Director::getInstance()->setGLDefaultValues();
|
||||
|
|
|
@ -34,7 +34,7 @@ void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thi
|
|||
{
|
||||
ccGLInvalidateStateCache();
|
||||
ShaderCache::getInstance()->reloadDefaultShaders();
|
||||
ccDrawInit();
|
||||
DrawPrimitives::init();
|
||||
TextureCache::reloadAllTextures();
|
||||
NotificationCenter::getInstance()->postNotification(EVNET_COME_TO_FOREGROUND, NULL);
|
||||
Director::getInstance()->setGLDefaultValues();
|
||||
|
|
|
@ -34,7 +34,7 @@ void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thi
|
|||
{
|
||||
ccGLInvalidateStateCache();
|
||||
ShaderCache::getInstance()->reloadDefaultShaders();
|
||||
ccDrawInit();
|
||||
DrawPrimitives::init();
|
||||
TextureCache::reloadAllTextures();
|
||||
NotificationCenter::getInstance()->postNotification(EVNET_COME_TO_FOREGROUND, NULL);
|
||||
Director::getInstance()->setGLDefaultValues();
|
||||
|
|
|
@ -34,7 +34,7 @@ void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thi
|
|||
{
|
||||
ccGLInvalidateStateCache();
|
||||
ShaderCache::getInstance()->reloadDefaultShaders();
|
||||
ccDrawInit();
|
||||
DrawPrimitives::init();
|
||||
TextureCache::reloadAllTextures();
|
||||
NotificationCenter::getInstance()->postNotification(EVNET_COME_TO_FOREGROUND, NULL);
|
||||
Director::getInstance()->setGLDefaultValues();
|
||||
|
|
|
@ -34,7 +34,7 @@ void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thi
|
|||
{
|
||||
ccGLInvalidateStateCache();
|
||||
ShaderCache::getInstance()->reloadDefaultShaders();
|
||||
ccDrawInit();
|
||||
DrawPrimitives::init();
|
||||
TextureCache::reloadAllTextures();
|
||||
NotificationCenter::getInstance()->postNotification(EVNET_COME_TO_FOREGROUND, NULL);
|
||||
Director::getInstance()->setGLDefaultValues();
|
||||
|
|
|
@ -34,7 +34,7 @@ void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thi
|
|||
{
|
||||
ccGLInvalidateStateCache();
|
||||
ShaderCache::getInstance()->reloadDefaultShaders();
|
||||
ccDrawInit();
|
||||
DrawPrimitives::init();
|
||||
TextureCache::reloadAllTextures();
|
||||
NotificationCenter::getInstance()->postNotification(EVNET_COME_TO_FOREGROUND, NULL);
|
||||
Director::getInstance()->setGLDefaultValues();
|
||||
|
|
|
@ -34,7 +34,7 @@ void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thi
|
|||
{
|
||||
ccGLInvalidateStateCache();
|
||||
ShaderCache::getInstance()->reloadDefaultShaders();
|
||||
ccDrawInit();
|
||||
DrawPrimitives::init();
|
||||
TextureCache::reloadAllTextures();
|
||||
NotificationCenter::getInstance()->postNotification(EVNET_COME_TO_FOREGROUND, NULL);
|
||||
Director::getInstance()->setGLDefaultValues();
|
||||
|
|
|
@ -34,7 +34,7 @@ void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thi
|
|||
{
|
||||
ccGLInvalidateStateCache();
|
||||
ShaderCache::getInstance()->reloadDefaultShaders();
|
||||
ccDrawInit();
|
||||
DrawPrimitives::init();
|
||||
TextureCache::reloadAllTextures();
|
||||
NotificationCenter::getInstance()->postNotification(EVNET_COME_TO_FOREGROUND, NULL);
|
||||
Director::getInstance()->setGLDefaultValues();
|
||||
|
|
|
@ -33,7 +33,7 @@ void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thi
|
|||
{
|
||||
ccGLInvalidateStateCache();
|
||||
ShaderCache::getInstance()->reloadDefaultShaders();
|
||||
ccDrawInit();
|
||||
DrawPrimitives::init();
|
||||
TextureCache::reloadAllTextures();
|
||||
NotificationCenter::getInstance()->postNotification(EVNET_COME_TO_FOREGROUND, NULL);
|
||||
Director::getInstance()->setGLDefaultValues();
|
||||
|
|
|
@ -34,7 +34,7 @@ void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thi
|
|||
{
|
||||
ccGLInvalidateStateCache();
|
||||
ShaderCache::getInstance()->reloadDefaultShaders();
|
||||
ccDrawInit();
|
||||
DrawPrimitives::init();
|
||||
TextureCache::reloadAllTextures();
|
||||
NotificationCenter::getInstance()->postNotification(EVNET_COME_TO_FOREGROUND, NULL);
|
||||
Director::getInstance()->setGLDefaultValues();
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 9e0e803fae5a696052746ce05516919318f1daab
|
||||
Subproject commit 1705f55d99e6fb19371d558a24bd5a2fac0e1ee9
|
|
@ -1,8 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="src" path="gen"/>
|
||||
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
|
||||
<classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
|
||||
<classpathentry kind="output" path="bin/classes"/>
|
||||
</classpath>
|
|
@ -1,133 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>HelloCpp</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.ui.externaltools.ExternalToolBuilder</name>
|
||||
<triggers>full,incremental,</triggers>
|
||||
<arguments>
|
||||
<dictionary>
|
||||
<key>LaunchConfigHandle</key>
|
||||
<value><project>/.externalToolBuilders/Javah_jni_builder.launch</value>
|
||||
</dictionary>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
|
||||
<triggers>clean,full,incremental,</triggers>
|
||||
<arguments>
|
||||
<dictionary>
|
||||
<key>?name?</key>
|
||||
<value></value>
|
||||
</dictionary>
|
||||
<dictionary>
|
||||
<key>org.eclipse.cdt.make.core.append_environment</key>
|
||||
<value>true</value>
|
||||
</dictionary>
|
||||
<dictionary>
|
||||
<key>org.eclipse.cdt.make.core.autoBuildTarget</key>
|
||||
<value>all</value>
|
||||
</dictionary>
|
||||
<dictionary>
|
||||
<key>org.eclipse.cdt.make.core.buildArguments</key>
|
||||
<value>-C ${ProjDirPath} NDK_MODULE_PATH=${COCOS2DX_ROOT}:${COCOS2DX_ROOT}/cocos2dx/platform/third_party/android/prebuilt -j2</value>
|
||||
</dictionary>
|
||||
<dictionary>
|
||||
<key>org.eclipse.cdt.make.core.buildCommand</key>
|
||||
<value>${ProjDirPath}/ANDROID_NDK/ndk-build</value>
|
||||
</dictionary>
|
||||
<dictionary>
|
||||
<key>org.eclipse.cdt.make.core.cleanBuildTarget</key>
|
||||
<value>clean</value>
|
||||
</dictionary>
|
||||
<dictionary>
|
||||
<key>org.eclipse.cdt.make.core.contents</key>
|
||||
<value>org.eclipse.cdt.make.core.activeConfigSettings</value>
|
||||
</dictionary>
|
||||
<dictionary>
|
||||
<key>org.eclipse.cdt.make.core.enableAutoBuild</key>
|
||||
<value>false</value>
|
||||
</dictionary>
|
||||
<dictionary>
|
||||
<key>org.eclipse.cdt.make.core.enableCleanBuild</key>
|
||||
<value>true</value>
|
||||
</dictionary>
|
||||
<dictionary>
|
||||
<key>org.eclipse.cdt.make.core.enableFullBuild</key>
|
||||
<value>true</value>
|
||||
</dictionary>
|
||||
<dictionary>
|
||||
<key>org.eclipse.cdt.make.core.fullBuildTarget</key>
|
||||
<value>all</value>
|
||||
</dictionary>
|
||||
<dictionary>
|
||||
<key>org.eclipse.cdt.make.core.stopOnError</key>
|
||||
<value>true</value>
|
||||
</dictionary>
|
||||
<dictionary>
|
||||
<key>org.eclipse.cdt.make.core.useDefaultBuildCmd</key>
|
||||
<value>false</value>
|
||||
</dictionary>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>com.android.ide.eclipse.adt.ApkBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
|
||||
<triggers>full,incremental,</triggers>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
<nature>org.eclipse.cdt.core.cnature</nature>
|
||||
<nature>org.eclipse.cdt.core.ccnature</nature>
|
||||
<nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
|
||||
<nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
|
||||
</natures>
|
||||
<linkedResources>
|
||||
<link>
|
||||
<name>Classes</name>
|
||||
<type>2</type>
|
||||
<location>COCOS2DX/samples/Cpp/HelloCpp/Classes</location>
|
||||
</link>
|
||||
<link>
|
||||
<name>cocos2dx</name>
|
||||
<type>2</type>
|
||||
<locationURI>COCOS2DX/cocos2dx</locationURI>
|
||||
</link>
|
||||
<link>
|
||||
<name>extensions</name>
|
||||
<type>2</type>
|
||||
<location>COCOS2DX/extensions</location>
|
||||
</link>
|
||||
<link>
|
||||
<name>scripting</name>
|
||||
<type>2</type>
|
||||
<locationURI>COCOS2DX/scripting</locationURI>
|
||||
</link>
|
||||
</linkedResources>
|
||||
</projectDescription>
|
|
@ -1,54 +0,0 @@
|
|||
#include "AppDelegate.h"
|
||||
|
||||
#include "cocos2d.h"
|
||||
#include "HelloWorldScene.h"
|
||||
|
||||
USING_NS_CC;
|
||||
|
||||
AppDelegate::AppDelegate()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
AppDelegate::~AppDelegate()
|
||||
{
|
||||
}
|
||||
|
||||
bool AppDelegate::applicationDidFinishLaunching()
|
||||
{
|
||||
// initialize director
|
||||
Director *pDirector = Director::getInstance();
|
||||
pDirector->setOpenGLView(EGLView::getInstance());
|
||||
|
||||
// turn on display FPS
|
||||
pDirector->setDisplayStats(true);
|
||||
|
||||
// set FPS. the default value is 1.0/60 if you don't call this
|
||||
pDirector->setAnimationInterval(1.0 / 60);
|
||||
|
||||
// create a scene. it's an autorelease object
|
||||
Scene *pScene = HelloWorld::scene();
|
||||
|
||||
// run
|
||||
pDirector->runWithScene(pScene);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// This function will be called when the app is inactive. When comes a phone call,it's be invoked too
|
||||
void AppDelegate::applicationDidEnterBackground()
|
||||
{
|
||||
Director::getInstance()->pause();
|
||||
|
||||
// if you use SimpleAudioEngine, it must be pause
|
||||
// SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic();
|
||||
}
|
||||
|
||||
// this function will be called when the app is active again
|
||||
void AppDelegate::applicationWillEnterForeground()
|
||||
{
|
||||
Director::getInstance()->resume();
|
||||
|
||||
// if you use SimpleAudioEngine, it must resume here
|
||||
// SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic();
|
||||
}
|
|
@ -1,38 +0,0 @@
|
|||
#ifndef _APP_DELEGATE_H_
|
||||
#define _APP_DELEGATE_H_
|
||||
|
||||
#include "CCApplication.h"
|
||||
|
||||
/**
|
||||
@brief The cocos2d Application.
|
||||
|
||||
The reason for implement as private inheritance is to hide some interface call by Director.
|
||||
*/
|
||||
class AppDelegate : private cocos2d::Application
|
||||
{
|
||||
public:
|
||||
AppDelegate();
|
||||
virtual ~AppDelegate();
|
||||
|
||||
/**
|
||||
@brief Implement Director and Scene init code here.
|
||||
@return true Initialize success, app continue.
|
||||
@return false Initialize failed, app terminate.
|
||||
*/
|
||||
virtual bool applicationDidFinishLaunching();
|
||||
|
||||
/**
|
||||
@brief The function be called when the application enter background
|
||||
@param the pointer of the application
|
||||
*/
|
||||
virtual void applicationDidEnterBackground();
|
||||
|
||||
/**
|
||||
@brief The function be called when the application enter foreground
|
||||
@param the pointer of the application
|
||||
*/
|
||||
virtual void applicationWillEnterForeground();
|
||||
};
|
||||
|
||||
#endif // _APP_DELEGATE_H_
|
||||
|
|
@ -1,84 +0,0 @@
|
|||
#include "HelloWorldScene.h"
|
||||
#include "SimpleAudioEngine.h"
|
||||
|
||||
using namespace cocos2d;
|
||||
using namespace CocosDenshion;
|
||||
|
||||
Scene* HelloWorld::scene()
|
||||
{
|
||||
// 'scene' is an autorelease object
|
||||
Scene *scene = Scene::create();
|
||||
|
||||
// 'layer' is an autorelease object
|
||||
HelloWorld *layer = HelloWorld::create();
|
||||
|
||||
// add layer as a child to scene
|
||||
scene->addChild(layer);
|
||||
|
||||
// return the scene
|
||||
return scene;
|
||||
}
|
||||
|
||||
// on "init" you need to initialize your instance
|
||||
bool HelloWorld::init()
|
||||
{
|
||||
//////////////////////////////
|
||||
// 1. super init first
|
||||
if ( !Layer::init() )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/////////////////////////////
|
||||
// 2. add a menu item with "X" image, which is clicked to quit the program
|
||||
// you may modify it.
|
||||
|
||||
// add a "close" icon to exit the progress. it's an autorelease object
|
||||
MenuItemImage *pCloseItem = MenuItemImage::create(
|
||||
"CloseNormal.png",
|
||||
"CloseSelected.png",
|
||||
this,
|
||||
menu_selector(HelloWorld::menuCloseCallback) );
|
||||
pCloseItem->setPosition( ccp(Director::getInstance()->getWinSize().width - 20, 20) );
|
||||
|
||||
// create menu, it's an autorelease object
|
||||
Menu* pMenu = Menu::create(pCloseItem, NULL);
|
||||
pMenu->setPosition( PointZero );
|
||||
this->addChild(pMenu, 1);
|
||||
|
||||
/////////////////////////////
|
||||
// 3. add your codes below...
|
||||
|
||||
// add a label shows "Hello World"
|
||||
// create and initialize a label
|
||||
LabelTTF* pLabel = LabelTTF::create("Hello World", "Thonburi", 34);
|
||||
|
||||
// ask director the window size
|
||||
Size size = Director::getInstance()->getWinSize();
|
||||
|
||||
// position the label on the center of the screen
|
||||
pLabel->setPosition( ccp(size.width / 2, size.height - 20) );
|
||||
|
||||
// add the label as a child to this layer
|
||||
this->addChild(pLabel, 1);
|
||||
|
||||
// add "HelloWorld" splash screen"
|
||||
Sprite* pSprite = Sprite::create("HelloWorld.png");
|
||||
|
||||
// position the sprite on the center of the screen
|
||||
pSprite->setPosition( ccp(size.width/2, size.height/2) );
|
||||
|
||||
// add the sprite as a child to this layer
|
||||
this->addChild(pSprite, 0);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void HelloWorld::menuCloseCallback(Object* pSender)
|
||||
{
|
||||
Director::getInstance()->end();
|
||||
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
|
||||
exit(0);
|
||||
#endif
|
||||
}
|
|
@ -1,22 +0,0 @@
|
|||
#ifndef __HELLOWORLD_SCENE_H__
|
||||
#define __HELLOWORLD_SCENE_H__
|
||||
|
||||
#include "cocos2d.h"
|
||||
|
||||
class HelloWorld : public cocos2d::Layer
|
||||
{
|
||||
public:
|
||||
// Here's a difference. Method 'init' in cocos2d-x returns bool, instead of returning 'id' in cocos2d-iphone
|
||||
virtual bool init();
|
||||
|
||||
// there's no 'id' in cpp, so we recommand to return the exactly class pointer
|
||||
static cocos2d::Scene* scene();
|
||||
|
||||
// a selector callback
|
||||
void menuCloseCallback(Object* pSender);
|
||||
|
||||
// implement the "static node()" method manually
|
||||
CREATE_FUNC(HelloWorld);
|
||||
};
|
||||
|
||||
#endif // __HELLOWORLD_SCENE_H__
|
|
@ -1,80 +0,0 @@
|
|||
#!/bin/sh
|
||||
PROJECT_PATH=${PWD}
|
||||
APPNAME="__projectname__"
|
||||
COCOS2DX_ROOT="__cocos2dxroot__"
|
||||
NDK_ROOT="__ndkroot__"
|
||||
DIR=$(cd `dirname $0`;pwd)
|
||||
APP_ROOT=$(cd $DIR/..;pwd)
|
||||
|
||||
# options
|
||||
|
||||
buildexternalsfromsource=
|
||||
|
||||
usage(){
|
||||
cat << EOF
|
||||
usage: $0 [options]
|
||||
|
||||
Build C/C++ code for $APPNAME using Android NDK
|
||||
|
||||
OPTIONS:
|
||||
-s Build externals from source
|
||||
-h this help
|
||||
EOF
|
||||
}
|
||||
|
||||
while getopts "sh" OPTION ; do
|
||||
case "$OPTION" in
|
||||
s)
|
||||
buildexternalsfromsource=1
|
||||
;;
|
||||
h)
|
||||
usage
|
||||
exit 0
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
# paths
|
||||
|
||||
# ... use paths relative to current directory
|
||||
APP_ANDROID_ROOT="$DIR"
|
||||
|
||||
#echo "NDK_ROOT = $NDK_ROOT"
|
||||
#echo "COCOS2DX_ROOT = $COCOS2DX_ROOT"
|
||||
#echo "APP_ROOT = $APP_ROOT"
|
||||
#echo "APP_ANDROID_ROOT = $APP_ANDROID_ROOT"
|
||||
|
||||
# make sure assets is exist
|
||||
if [ -d "$APP_ANDROID_ROOT"/assets ]; then
|
||||
rm -rf "$APP_ANDROID_ROOT"/assets
|
||||
fi
|
||||
|
||||
mkdir "$APP_ANDROID_ROOT"/assets
|
||||
|
||||
# copy resources
|
||||
cp -rf "$APP_ROOT"/Resources/* "$APP_ANDROID_ROOT"/assets
|
||||
|
||||
# copy icons (if they exist)
|
||||
file="$APP_ANDROID_ROOT"/assets/Icon-72.png
|
||||
if [ -f "$file" ]; then
|
||||
cp "$file" "$APP_ANDROID_ROOT"/res/drawable-hdpi/icon.png
|
||||
fi
|
||||
file="$APP_ANDROID_ROOT"/assets/Icon-48.png
|
||||
if [ -f "$file" ]; then
|
||||
cp "$file" "$APP_ANDROID_ROOT"/res/drawable-mdpi/icon.png
|
||||
fi
|
||||
file="$APP_ANDROID_ROOT"/assets/Icon-32.png
|
||||
if [ -f "$file" ]; then
|
||||
cp "$file" "$APP_ANDROID_ROOT"/res/drawable-ldpi/icon.png
|
||||
fi
|
||||
|
||||
|
||||
if [[ "$buildexternalsfromsource" ]]; then
|
||||
echo "Building external dependencies from source"
|
||||
"$NDK_ROOT"/ndk-build -C "$APP_ANDROID_ROOT" $* \
|
||||
"NDK_MODULE_PATH=${COCOS2DX_ROOT}:${COCOS2DX_ROOT}/cocos2dx/platform/third_party/android/source"
|
||||
else
|
||||
echo "Using prebuilt externals"
|
||||
"$NDK_ROOT"/ndk-build -C "$APP_ANDROID_ROOT" $* \
|
||||
"NDK_MODULE_PATH=${COCOS2DX_ROOT}:${COCOS2DX_ROOT}/cocos2dx/platform/third_party/android/prebuilt"
|
||||
fi
|
|
@ -1,103 +0,0 @@
|
|||
#!/bin/bash
|
||||
# check the args
|
||||
# $1: root of cocos2dx $2: app path $3: pakcage path
|
||||
|
||||
COCOS2DX_ROOT=$1
|
||||
APP_DIR=$2
|
||||
PACKAGE_PATH=$3
|
||||
USE_BOX2D=$4
|
||||
USE_CHIPMUNK=$5
|
||||
USE_LUA=$6
|
||||
|
||||
APP_NAME=`basename ${APP_DIR}`
|
||||
HELLOWORLD_ROOT=$COCOS2DX_ROOT/samples/Cpp/HelloCpp
|
||||
COCOSJAVALIB_ROOT=$COCOS2DX_ROOT/cocos2dx/platform/android/java
|
||||
|
||||
# xxx.yyy.zzz -> xxx/yyy/zzz
|
||||
convert_package_path_to_dir(){
|
||||
PACKAGE_PATH_DIR=`echo $1 | sed -e "s/\./\//g"`
|
||||
}
|
||||
|
||||
copy_cpp_h() {
|
||||
mkdir $APP_DIR/Classes
|
||||
cp $COCOS2DX_ROOT/template/android/Classes/* $APP_DIR/Classes
|
||||
}
|
||||
|
||||
# copy resources
|
||||
copy_resouces() {
|
||||
mkdir $APP_DIR/Resources
|
||||
cp -rf $HELLOWORLD_ROOT/Resources/iphone/* $APP_DIR/Resources
|
||||
}
|
||||
|
||||
# from HelloWorld copy src and jni to APP_DIR
|
||||
copy_src_and_jni() {
|
||||
cp -rf $HELLOWORLD_ROOT/proj.android/{jni,src} $APP_DIR/proj.android
|
||||
|
||||
# replace Android.mk
|
||||
sh $COCOS2DX_ROOT/template/android/gamemk.sh $APP_DIR/proj.android/jni/Android.mk $USE_BOX2D $USE_CHIPMUNK $USE_LUA
|
||||
|
||||
if [ $USE_LUA = "true" ]; then
|
||||
# copy lua script
|
||||
cp "$COCOS2DX_ROOT"/scripting/lua/script/* "$APP_DIR"/Resources
|
||||
fi
|
||||
}
|
||||
|
||||
# copy build_native.sh and replace something
|
||||
copy_build_native() {
|
||||
# here should use # instead of /, why??
|
||||
sed "s#__cocos2dxroot__#$COCOS2DX_ROOT#;s#__ndkroot__#$NDK_ROOT#;s#__projectname__#$APP_NAME#" $COCOS2DX_ROOT/template/android/build_native.sh > $APP_DIR/proj.android/build_native.sh
|
||||
chmod u+x $APP_DIR/proj.android/build_native.sh
|
||||
}
|
||||
|
||||
# copy debugger script and replace templated parameters
|
||||
copy_ndkgdb() {
|
||||
sed "s#__projectname__#$APP_NAME#;s#__packagename__#$PACKAGE_PATH#;s#__androidsdk__#$ANDROID_SDK_ROOT#;s#__ndkroot__#$NDK_ROOT#;s#__cocos2dxroot__#$COCOS2DX_ROOT#" $COCOS2DX_ROOT/template/android/ndkgdb.sh > $APP_DIR/proj.android/ndkgdb.sh
|
||||
chmod u+x $APP_DIR/proj.android/ndkgdb.sh
|
||||
}
|
||||
|
||||
# copy .project and .classpath and replace project name
|
||||
modify_project_classpath(){
|
||||
sed "s/HelloCpp/$APP_NAME/" $COCOS2DX_ROOT/template/android/.project > $APP_DIR/proj.android/.project
|
||||
cp -f $COCOS2DX_ROOT/template/android/.classpath $APP_DIR/proj.android
|
||||
}
|
||||
|
||||
# replace AndroidManifext.xml and change the activity name
|
||||
# use sed to replace the specified line
|
||||
modify_androidmanifest(){
|
||||
sed "s/HelloCpp/$APP_NAME/;s/org\.cocos2dx\.hellocpp/$PACKAGE_PATH/" $HELLOWORLD_ROOT/proj.android/AndroidManifest.xml > $APP_DIR/proj.android/AndroidManifest.xml
|
||||
}
|
||||
|
||||
# modify HelloCpp.java
|
||||
modify_applicationdemo() {
|
||||
convert_package_path_to_dir $PACKAGE_PATH
|
||||
|
||||
# rename APP_DIR/android/src/org/cocos2dx/hellocpp/HelloCpp.java to
|
||||
# APP_DIR/android/src/org/cocos2dx/hellocpp/$APP_NAME.java, change hellocpp to game
|
||||
sed "s/HelloCpp/$APP_NAME/;s/org\.cocos2dx\.hellocpp/$PACKAGE_PATH/;s/hellocpp/game/" $APP_DIR/proj.android/src/org/cocos2dx/hellocpp/HelloCpp.java > $APP_DIR/proj.android/src/$PACKAGE_PATH_DIR/$APP_NAME.java
|
||||
rm -fr $APP_DIR/proj.android/src/org/cocos2dx/hellocpp
|
||||
}
|
||||
|
||||
modify_layout() {
|
||||
rm -f $APP_DIR/proj.android/res/layout/main.xml
|
||||
}
|
||||
|
||||
# android.bat of android 4.0 don't create res/drawable-hdpi res/drawable-ldpi and res/drawable-mdpi.
|
||||
# These work are done in ADT
|
||||
copy_icon() {
|
||||
if [ ! -d $APP_DIR/proj.android/res/drawable-hdpi ]; then
|
||||
cp -r $HELLOWORLD_ROOT/proj.android/res/drawable-hdpi $APP_DIR/proj.android/res
|
||||
cp -r $HELLOWORLD_ROOT/proj.android/res/drawable-ldpi $APP_DIR/proj.android/res
|
||||
cp -r $HELLOWORLD_ROOT/proj.android/res/drawable-mdpi $APP_DIR/proj.android/res
|
||||
fi
|
||||
}
|
||||
|
||||
copy_cpp_h
|
||||
copy_resouces
|
||||
copy_src_and_jni
|
||||
copy_build_native
|
||||
copy_ndkgdb
|
||||
#modify_project_classpath
|
||||
modify_androidmanifest
|
||||
modify_applicationdemo
|
||||
modify_layout
|
||||
copy_icon
|
|
@ -1,50 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
FILE=$1
|
||||
USE_BOX2D=$2
|
||||
USE_CHIPMUNK=$3
|
||||
USE_LUA=$4
|
||||
|
||||
LOCAL_STATIC_LIBRARIES="LOCAL_WHOLE_STATIC_LIBRARIES := cocos2dx_static cocosdenshion_static cocos_extension_static"
|
||||
MODULES_TO_CALL="\$(call import-module,CocosDenshion/android) \\
|
||||
\$(call import-module,cocos2dx) \\
|
||||
\$(call import-module,extensions)"
|
||||
|
||||
LOCAL_SRC_FILES="LOCAL_SRC_FILES := hellocpp/main.cpp \\
|
||||
../../Classes/AppDelegate.cpp \\
|
||||
../../Classes/HelloWorldScene.cpp"
|
||||
|
||||
if [ $USE_BOX2D = "true" ];then
|
||||
LOCAL_STATIC_LIBRARIES=$LOCAL_STATIC_LIBRARIES" box2d_static"
|
||||
MODULES_TO_CALL=$MODULES_TO_CALL" \$(call import-module,external/Box2D)"
|
||||
fi
|
||||
|
||||
if [ $USE_CHIPMUNK = "true" ]; then
|
||||
LOCAL_STATIC_LIBRARIES=$LOCAL_STATIC_LIBRARIES" chipmunk_static"
|
||||
MODULES_TO_CALL=$MODULES_TO_CALL" \$(call import-module,external/chipmunk)"
|
||||
fi
|
||||
|
||||
if [ $USE_LUA = "true" ]; then
|
||||
LOCAL_STATIC_LIBRARIES=$LOCAL_STATIC_LIBRARIES" cocos_lua_static"
|
||||
MODULES_TO_CALL=$MODULES_TO_CALL" \$(call import-module,scripting/lua/proj.android)"
|
||||
fi
|
||||
|
||||
cat > $FILE << EOF
|
||||
LOCAL_PATH := \$(call my-dir)
|
||||
|
||||
include \$(CLEAR_VARS)
|
||||
|
||||
LOCAL_MODULE := game_shared
|
||||
|
||||
LOCAL_MODULE_FILENAME := libgame
|
||||
|
||||
$LOCAL_SRC_FILES
|
||||
|
||||
LOCAL_C_INCLUDES := \$(LOCAL_PATH)/../../Classes
|
||||
|
||||
$LOCAL_STATIC_LIBRARIES
|
||||
|
||||
include \$(BUILD_SHARED_LIBRARY)
|
||||
|
||||
$MODULES_TO_CALL
|
||||
EOF
|
|
@ -1,30 +0,0 @@
|
|||
APPNAME="__projectname__"
|
||||
APP_ANDROID_NAME="__packagename__"
|
||||
ANDROID_SDK_ROOT="__androidsdk__"
|
||||
NDK_ROOT="__ndkroot__"
|
||||
COCOS2DX_ROOT="__cocos2dxroot__"
|
||||
|
||||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
APP_ROOT="$DIR/.."
|
||||
APP_ANDROID_ROOT="$COCOS2DX_ROOT/$APPNAME/proj.android"
|
||||
|
||||
echo "NDK_ROOT = $NDK_ROOT"
|
||||
echo "ANDROID_SDK_ROOT = $ANDROID_SDK_ROOT"
|
||||
echo "COCOS2DX_ROOT = $COCOS2DX_ROOT"
|
||||
echo "APP_ROOT = $APP_ROOT"
|
||||
echo "APP_ANDROID_ROOT = $APP_ANDROID_ROOT"
|
||||
echo "APP_ANDROID_NAME = $APP_ANDROID_NAME"
|
||||
|
||||
echo
|
||||
echo "Killing and restarting ${APP_ANDROID_NAME}"
|
||||
echo
|
||||
|
||||
#set -x
|
||||
"${ANDROID_SDK_ROOT}"/platform-tools/adb shell am force-stop "${APP_ANDROID_NAME}"
|
||||
|
||||
NDK_MODULE_PATH="${COCOS2DX_ROOT}":"${COCOS2DX_ROOT}"/cocos2dx/platform/third_party/android/prebuilt \
|
||||
"${NDK_ROOT}"/ndk-gdb \
|
||||
--adb="${ANDROID_SDK_ROOT}"/platform-tools/adb \
|
||||
--verbose \
|
||||
--start \
|
||||
--force
|
|
@ -34,7 +34,7 @@ void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thi
|
|||
{
|
||||
ccGLInvalidateStateCache();
|
||||
ShaderCache::getInstance()->reloadDefaultShaders();
|
||||
ccDrawInit();
|
||||
DrawPrimitives::init();
|
||||
TextureCache::reloadAllTextures();
|
||||
NotificationCenter::getInstance()->postNotification(EVNET_COME_TO_FOREGROUND, NULL);
|
||||
Director::getInstance()->setGLDefaultValues();
|
||||
|
|
|
@ -34,7 +34,7 @@ void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thi
|
|||
{
|
||||
ccGLInvalidateStateCache();
|
||||
ShaderCache::getInstance()->reloadDefaultShaders();
|
||||
ccDrawInit();
|
||||
DrawPrimitives::init();
|
||||
TextureCache::reloadAllTextures();
|
||||
NotificationCenter::getInstance()->postNotification(EVNET_COME_TO_FOREGROUND, NULL);
|
||||
Director::getInstance()->setGLDefaultValues();
|
||||
|
|
|
@ -34,7 +34,7 @@ void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thi
|
|||
{
|
||||
ccGLInvalidateStateCache();
|
||||
ShaderCache::getInstance()->reloadDefaultShaders();
|
||||
ccDrawInit();
|
||||
DrawPrimitives::init();
|
||||
TextureCache::reloadAllTextures();
|
||||
NotificationCenter::getInstance()->postNotification(EVNET_COME_TO_FOREGROUND, NULL);
|
||||
Director::getInstance()->setGLDefaultValues();
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
5fe89fb5bd58cedf13b0363f97b20e3ea7ff255d
|
Binary file not shown.
Before Width: | Height: | Size: 60 KiB |
|
@ -1,20 +0,0 @@
|
|||
//
|
||||
// ___PROJECTNAMEASIDENTIFIER___AppController.h
|
||||
// ___PROJECTNAME___
|
||||
//
|
||||
// Created by ___FULLUSERNAME___ on ___DATE___.
|
||||
// Copyright ___ORGANIZATIONNAME___ ___YEAR___. All rights reserved.
|
||||
//
|
||||
|
||||
@class RootViewController;
|
||||
|
||||
@interface AppController : NSObject <UIAccelerometerDelegate, UIAlertViewDelegate, UITextFieldDelegate,UIApplicationDelegate> {
|
||||
UIWindow *window;
|
||||
RootViewController *viewController;
|
||||
}
|
||||
|
||||
@property (nonatomic, retain) UIWindow *window;
|
||||
@property (nonatomic, retain) RootViewController *viewController;
|
||||
|
||||
@end
|
||||
|
|
@ -1,122 +0,0 @@
|
|||
//
|
||||
// ___PROJECTNAMEASIDENTIFIER___AppController.mm
|
||||
// ___PROJECTNAME___
|
||||
//
|
||||
// Created by ___FULLUSERNAME___ on ___DATE___.
|
||||
// Copyright ___ORGANIZATIONNAME___ ___YEAR___. All rights reserved.
|
||||
//
|
||||
#import <UIKit/UIKit.h>
|
||||
#import "AppController.h"
|
||||
#import "cocos2d.h"
|
||||
#import "EAGLView.h"
|
||||
#import "AppDelegate.h"
|
||||
|
||||
#import "RootViewController.h"
|
||||
|
||||
@implementation AppController
|
||||
|
||||
@synthesize window;
|
||||
@synthesize viewController;
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark Application lifecycle
|
||||
|
||||
// cocos2d application instance
|
||||
static AppDelegate s_sharedApplication;
|
||||
|
||||
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
|
||||
|
||||
// Override point for customization after application launch.
|
||||
|
||||
// Add the view controller's view to the window and display.
|
||||
window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]];
|
||||
CCEAGLView *__glView = [CCEAGLView viewWithFrame: [window bounds]
|
||||
pixelFormat: kEAGLColorFormatRGBA8
|
||||
depthFormat: GL_DEPTH_COMPONENT16
|
||||
preserveBackbuffer: NO
|
||||
sharegroup: nil
|
||||
multiSampling: NO
|
||||
numberOfSamples:0 ];
|
||||
|
||||
// Use RootViewController manage CCEAGLView
|
||||
viewController = [[RootViewController alloc] initWithNibName:nil bundle:nil];
|
||||
viewController.wantsFullScreenLayout = YES;
|
||||
viewController.view = __glView;
|
||||
|
||||
// Set RootViewController to window
|
||||
if ( [[UIDevice currentDevice].systemVersion floatValue] < 6.0)
|
||||
{
|
||||
// warning: addSubView doesn't work on iOS6
|
||||
[window addSubview: viewController.view];
|
||||
}
|
||||
else
|
||||
{
|
||||
// use this method on ios6
|
||||
[window setRootViewController:viewController];
|
||||
}
|
||||
|
||||
[window makeKeyAndVisible];
|
||||
|
||||
[[UIApplication sharedApplication] setStatusBarHidden: YES];
|
||||
|
||||
cocos2d::Application::getInstance()->run();
|
||||
return YES;
|
||||
}
|
||||
|
||||
|
||||
- (void)applicationWillResignActive:(UIApplication *)application {
|
||||
/*
|
||||
Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
|
||||
Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
|
||||
*/
|
||||
cocos2d::Director::getInstance()->pause();
|
||||
}
|
||||
|
||||
- (void)applicationDidBecomeActive:(UIApplication *)application {
|
||||
/*
|
||||
Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
|
||||
*/
|
||||
cocos2d::Director::getInstance()->resume();
|
||||
}
|
||||
|
||||
- (void)applicationDidEnterBackground:(UIApplication *)application {
|
||||
/*
|
||||
Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
|
||||
If your application supports background execution, called instead of applicationWillTerminate: when the user quits.
|
||||
*/
|
||||
cocos2d::Application::getInstance()->applicationDidEnterBackground();
|
||||
}
|
||||
|
||||
- (void)applicationWillEnterForeground:(UIApplication *)application {
|
||||
/*
|
||||
Called as part of transition from the background to the inactive state: here you can undo many of the changes made on entering the background.
|
||||
*/
|
||||
cocos2d::Application::getInstance()->applicationWillEnterForeground();
|
||||
}
|
||||
|
||||
- (void)applicationWillTerminate:(UIApplication *)application {
|
||||
/*
|
||||
Called when the application is about to terminate.
|
||||
See also applicationDidEnterBackground:.
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark Memory management
|
||||
|
||||
- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {
|
||||
/*
|
||||
Free up as much memory as possible by purging cached data objects that can be recreated (or reloaded from disk) later.
|
||||
*/
|
||||
cocos2d::Director::getInstance()->purgeCachedData();
|
||||
}
|
||||
|
||||
|
||||
- (void)dealloc {
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
//
|
||||
// ___PROJECTNAMEASIDENTIFIER___AppController.h
|
||||
// ___PROJECTNAME___
|
||||
//
|
||||
// Created by ___FULLUSERNAME___ on ___DATE___.
|
||||
// Copyright ___ORGANIZATIONNAME___ ___YEAR___. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
|
||||
@interface RootViewController : UIViewController {
|
||||
|
||||
}
|
||||
|
||||
@end
|
|
@ -1,73 +0,0 @@
|
|||
//
|
||||
// ___PROJECTNAMEASIDENTIFIER___AppController.h
|
||||
// ___PROJECTNAME___
|
||||
//
|
||||
// Created by ___FULLUSERNAME___ on ___DATE___.
|
||||
// Copyright ___ORGANIZATIONNAME___ ___YEAR___. All rights reserved.
|
||||
//
|
||||
|
||||
#import "RootViewController.h"
|
||||
|
||||
|
||||
@implementation RootViewController
|
||||
|
||||
/*
|
||||
// The designated initializer. Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
|
||||
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
|
||||
if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
|
||||
// Custom initialization
|
||||
}
|
||||
return self;
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
// Implement loadView to create a view hierarchy programmatically, without using a nib.
|
||||
- (void)loadView {
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
|
||||
- (void)viewDidLoad {
|
||||
[super viewDidLoad];
|
||||
}
|
||||
|
||||
*/
|
||||
// Override to allow orientations other than the default portrait orientation.
|
||||
// This method is deprecated on ios6
|
||||
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
|
||||
return UIInterfaceOrientationIsLandscape( interfaceOrientation );
|
||||
}
|
||||
|
||||
// For ios6, use supportedInterfaceOrientations & shouldAutorotate instead
|
||||
- (NSUInteger) supportedInterfaceOrientations{
|
||||
#ifdef __IPHONE_6_0
|
||||
return UIInterfaceOrientationMaskLandscape;
|
||||
#endif
|
||||
}
|
||||
|
||||
- (BOOL) shouldAutorotate {
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (void)didReceiveMemoryWarning {
|
||||
// Releases the view if it doesn't have a superview.
|
||||
[super didReceiveMemoryWarning];
|
||||
|
||||
// Release any cached data, images, etc that aren't in use.
|
||||
}
|
||||
|
||||
- (void)viewDidUnload {
|
||||
[super viewDidUnload];
|
||||
// Release any retained subviews of the main view.
|
||||
// e.g. self.myOutlet = nil;
|
||||
}
|
||||
|
||||
|
||||
- (void)dealloc {
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
|
||||
@end
|
|
@ -1,17 +0,0 @@
|
|||
//
|
||||
// main.m
|
||||
// ___PROJECTNAME___
|
||||
//
|
||||
// Created by ___FULLUSERNAME___ on ___DATE___.
|
||||
// Copyright ___ORGANIZATIONNAME___ ___YEAR___. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
|
||||
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
|
||||
int retVal = UIApplicationMain(argc, argv, nil, @"AppController");
|
||||
[pool release];
|
||||
return retVal;
|
||||
}
|
|
@ -1,62 +0,0 @@
|
|||
//
|
||||
// ___PROJECTNAMEASIDENTIFIER___AppDelegate.cpp
|
||||
// ___PROJECTNAME___
|
||||
//
|
||||
// Created by ___FULLUSERNAME___ on ___DATE___.
|
||||
// Copyright ___ORGANIZATIONNAME___ ___YEAR___. All rights reserved.
|
||||
//
|
||||
|
||||
#include "AppDelegate.h"
|
||||
|
||||
#include "cocos2d.h"
|
||||
#include "SimpleAudioEngine.h"
|
||||
#include "HelloWorldScene.h"
|
||||
|
||||
USING_NS_CC;
|
||||
using namespace CocosDenshion;
|
||||
|
||||
AppDelegate::AppDelegate()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
AppDelegate::~AppDelegate()
|
||||
{
|
||||
}
|
||||
|
||||
bool AppDelegate::applicationDidFinishLaunching()
|
||||
{
|
||||
// initialize director
|
||||
Director *pDirector = Director::getInstance();
|
||||
pDirector->setOpenGLView(EGLView::getInstance());
|
||||
|
||||
// turn on display FPS
|
||||
pDirector->setDisplayStats(true);
|
||||
|
||||
// set FPS. the default value is 1.0/60 if you don't call this
|
||||
pDirector->setAnimationInterval(1.0 / 60);
|
||||
|
||||
// create a scene. it's an autorelease object
|
||||
Scene *pScene = HelloWorld::scene();
|
||||
|
||||
// run
|
||||
pDirector->runWithScene(pScene);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// This function will be called when the app is inactive. When comes a phone call,it's be invoked too
|
||||
void AppDelegate::applicationDidEnterBackground()
|
||||
{
|
||||
Director::getInstance()->stopAnimation();
|
||||
SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic();
|
||||
SimpleAudioEngine::sharedEngine()->pauseAllEffects();
|
||||
}
|
||||
|
||||
// this function will be called when the app is active again
|
||||
void AppDelegate::applicationWillEnterForeground()
|
||||
{
|
||||
Director::getInstance()->startAnimation();
|
||||
SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic();
|
||||
SimpleAudioEngine::sharedEngine()->resumeAllEffects();
|
||||
}
|
|
@ -1,46 +0,0 @@
|
|||
//
|
||||
// ___PROJECTNAMEASIDENTIFIER___AppDelegate.h
|
||||
// ___PROJECTNAME___
|
||||
//
|
||||
// Created by ___FULLUSERNAME___ on ___DATE___.
|
||||
// Copyright ___ORGANIZATIONNAME___ ___YEAR___. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef _APP_DELEGATE_H_
|
||||
#define _APP_DELEGATE_H_
|
||||
|
||||
#include "CCApplication.h"
|
||||
|
||||
/**
|
||||
@brief The cocos2d Application.
|
||||
|
||||
The reason to implement with private inheritance is to hide some interface details of Director.
|
||||
*/
|
||||
class AppDelegate : private cocos2d::Application
|
||||
{
|
||||
public:
|
||||
AppDelegate();
|
||||
virtual ~AppDelegate();
|
||||
|
||||
/**
|
||||
@brief Implement Director and Scene init code here.
|
||||
@return true Initialize success, app continue.
|
||||
@return false Initialize failed, app terminate.
|
||||
*/
|
||||
virtual bool applicationDidFinishLaunching();
|
||||
|
||||
/**
|
||||
@brief The function is called when the application enters the background
|
||||
@param the pointer of the application instance
|
||||
*/
|
||||
virtual void applicationDidEnterBackground();
|
||||
|
||||
/**
|
||||
@brief The function is called when the application enters the foreground
|
||||
@param the pointer of the application instance
|
||||
*/
|
||||
virtual void applicationWillEnterForeground();
|
||||
};
|
||||
|
||||
#endif // _APP_DELEGATE_H_
|
||||
|
|
@ -1,84 +0,0 @@
|
|||
#include "HelloWorldScene.h"
|
||||
#include "SimpleAudioEngine.h"
|
||||
|
||||
using namespace cocos2d;
|
||||
using namespace CocosDenshion;
|
||||
|
||||
Scene* HelloWorld::scene()
|
||||
{
|
||||
// 'scene' is an autorelease object
|
||||
Scene *scene = Scene::create();
|
||||
|
||||
// 'layer' is an autorelease object
|
||||
HelloWorld *layer = HelloWorld::create();
|
||||
|
||||
// add layer as a child to scene
|
||||
scene->addChild(layer);
|
||||
|
||||
// return the scene
|
||||
return scene;
|
||||
}
|
||||
|
||||
// on "init" you need to initialize your instance
|
||||
bool HelloWorld::init()
|
||||
{
|
||||
//////////////////////////////
|
||||
// 1. super init first
|
||||
if ( !Layer::init() )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/////////////////////////////
|
||||
// 2. add a menu item with "X" image, which is clicked to quit the program
|
||||
// you may modify it.
|
||||
|
||||
// add a "close" icon to exit the progress. it's an autorelease object
|
||||
MenuItemImage *pCloseItem = MenuItemImage::create(
|
||||
"CloseNormal.png",
|
||||
"CloseSelected.png",
|
||||
this,
|
||||
menu_selector(HelloWorld::menuCloseCallback) );
|
||||
pCloseItem->setPosition( ccp(Director::getInstance()->getWinSize().width - 20, 20) );
|
||||
|
||||
// create menu, it's an autorelease object
|
||||
Menu* pMenu = Menu::create(pCloseItem, NULL);
|
||||
pMenu->setPosition( PointZero );
|
||||
this->addChild(pMenu, 1);
|
||||
|
||||
/////////////////////////////
|
||||
// 3. add your codes below...
|
||||
|
||||
// add a label shows "Hello World"
|
||||
// create and initialize a label
|
||||
LabelTTF* pLabel = LabelTTF::create("Hello World", "Thonburi", 34);
|
||||
|
||||
// ask director the window size
|
||||
Size size = Director::getInstance()->getWinSize();
|
||||
|
||||
// position the label on the center of the screen
|
||||
pLabel->setPosition( ccp(size.width / 2, size.height - 20) );
|
||||
|
||||
// add the label as a child to this layer
|
||||
this->addChild(pLabel, 1);
|
||||
|
||||
// add "HelloWorld" splash screen"
|
||||
Sprite* pSprite = Sprite::create("HelloWorld.png");
|
||||
|
||||
// position the sprite on the center of the screen
|
||||
pSprite->setPosition( ccp(size.width/2, size.height/2) );
|
||||
|
||||
// add the sprite as a child to this layer
|
||||
this->addChild(pSprite, 0);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void HelloWorld::menuCloseCallback(Object* pSender)
|
||||
{
|
||||
Director::getInstance()->end();
|
||||
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
|
||||
exit(0);
|
||||
#endif
|
||||
}
|
|
@ -1,22 +0,0 @@
|
|||
#ifndef __HELLOWORLD_SCENE_H__
|
||||
#define __HELLOWORLD_SCENE_H__
|
||||
|
||||
#include "cocos2d.h"
|
||||
|
||||
class HelloWorld : public cocos2d::Layer
|
||||
{
|
||||
public:
|
||||
// Method 'init' in cocos2d-x returns bool, instead of 'id' in cocos2d-iphone (an object pointer)
|
||||
virtual bool init();
|
||||
|
||||
// there's no 'id' in cpp, so we recommend to return the class instance pointer
|
||||
static cocos2d::Scene* scene();
|
||||
|
||||
// a selector callback
|
||||
void menuCloseCallback(Object* pSender);
|
||||
|
||||
// preprocessor macro for "static create()" constructor ( node() deprecated )
|
||||
CREATE_FUNC(HelloWorld);
|
||||
};
|
||||
|
||||
#endif // __HELLOWORLD_SCENE_H__
|
|
@ -1,8 +0,0 @@
|
|||
//
|
||||
// Prefix header for all source files of the '___PROJECTNAME___' target in the '___PROJECTNAME___' project
|
||||
//
|
||||
|
||||
#ifdef __OBJC__
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <UIKit/UIKit.h>
|
||||
#endif
|
Binary file not shown.
|
@ -1,62 +0,0 @@
|
|||
//
|
||||
// ___PROJECTNAMEASIDENTIFIER___AppDelegate.cpp
|
||||
// ___PROJECTNAME___
|
||||
//
|
||||
// Created by ___FULLUSERNAME___ on ___DATE___.
|
||||
// Copyright ___ORGANIZATIONNAME___ ___YEAR___. All rights reserved.
|
||||
//
|
||||
|
||||
#include "AppDelegate.h"
|
||||
|
||||
#include "cocos2d.h"
|
||||
#include "SimpleAudioEngine.h"
|
||||
#include "HelloWorldScene.h"
|
||||
|
||||
USING_NS_CC;
|
||||
using namespace CocosDenshion;
|
||||
|
||||
AppDelegate::AppDelegate()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
AppDelegate::~AppDelegate()
|
||||
{
|
||||
}
|
||||
|
||||
bool AppDelegate::applicationDidFinishLaunching()
|
||||
{
|
||||
// initialize director
|
||||
Director *pDirector = Director::getInstance();
|
||||
pDirector->setOpenGLView(EGLView::getInstance());
|
||||
|
||||
// turn on display FPS
|
||||
pDirector->setDisplayStats(true);
|
||||
|
||||
// set FPS. the default value is 1.0/60 if you don't call this
|
||||
pDirector->setAnimationInterval(1.0 / 60);
|
||||
|
||||
// create a scene. it's an autorelease object
|
||||
Scene *pScene = HelloWorld::scene();
|
||||
|
||||
// run
|
||||
pDirector->runWithScene(pScene);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// This function will be called when the app is inactive. When comes a phone call,it's be invoked too
|
||||
void AppDelegate::applicationDidEnterBackground()
|
||||
{
|
||||
Director::getInstance()->stopAnimation();
|
||||
SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic();
|
||||
SimpleAudioEngine::sharedEngine()->pauseAllEffects();
|
||||
}
|
||||
|
||||
// this function will be called when the app is active again
|
||||
void AppDelegate::applicationWillEnterForeground()
|
||||
{
|
||||
Director::getInstance()->startAnimation();
|
||||
SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic();
|
||||
SimpleAudioEngine::sharedEngine()->resumeAllEffects();
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
//
|
||||
// ___PROJECTNAMEASIDENTIFIER___AppDelegate.h
|
||||
// ___PROJECTNAME___
|
||||
//
|
||||
// Created by ___FULLUSERNAME___ on ___DATE___.
|
||||
// Copyright ___ORGANIZATIONNAME___ ___YEAR___. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef _APP_DELEGATE_H_
|
||||
#define _APP_DELEGATE_H_
|
||||
|
||||
#include "CCApplication.h"
|
||||
|
||||
/**
|
||||
@brief The cocos2d Application.
|
||||
|
||||
The reason for implement as private inheritance is to hide some interface call by Director.
|
||||
*/
|
||||
class AppDelegate : private cocos2d::Application
|
||||
{
|
||||
public:
|
||||
AppDelegate();
|
||||
virtual ~AppDelegate();
|
||||
|
||||
|
||||
/**
|
||||
@brief Implement Director and Scene init code here.
|
||||
@return true Initialize success, app continue.
|
||||
@return false Initialize failed, app terminate.
|
||||
*/
|
||||
virtual bool applicationDidFinishLaunching();
|
||||
|
||||
/**
|
||||
@brief The function be called when the application enter background
|
||||
@param the pointer of the application
|
||||
*/
|
||||
virtual void applicationDidEnterBackground();
|
||||
|
||||
/**
|
||||
@brief The function be called when the application enter foreground
|
||||
@param the pointer of the application
|
||||
*/
|
||||
virtual void applicationWillEnterForeground();
|
||||
};
|
||||
|
||||
#endif // _APP_DELEGATE_H_
|
||||
|
|
@ -1,275 +0,0 @@
|
|||
//
|
||||
// HelloWorldScene.cpp
|
||||
// ___PROJECTNAME___
|
||||
//
|
||||
// Created by ___FULLUSERNAME___ on ___DATE___.
|
||||
// Copyright ___ORGANIZATIONNAME___ ___YEAR___. All rights reserved.
|
||||
//
|
||||
#include "HelloWorldScene.h"
|
||||
#include "SimpleAudioEngine.h"
|
||||
|
||||
using namespace cocos2d;
|
||||
using namespace CocosDenshion;
|
||||
|
||||
#define PTM_RATIO 32
|
||||
|
||||
enum {
|
||||
kTagParentNode = 1,
|
||||
};
|
||||
|
||||
PhysicsSprite::PhysicsSprite()
|
||||
: _body(NULL)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void PhysicsSprite::setPhysicsBody(b2Body * body)
|
||||
{
|
||||
_body = body;
|
||||
}
|
||||
|
||||
// this method will only get called if the sprite is batched.
|
||||
// return YES if the physics values (angles, position ) changed
|
||||
// If you return NO, then nodeToParentTransform won't be called.
|
||||
bool PhysicsSprite::isDirty(void)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// returns the transform matrix according the Chipmunk Body values
|
||||
AffineTransform PhysicsSprite::nodeToParentTransform(void)
|
||||
{
|
||||
b2Vec2 pos = _body->GetPosition();
|
||||
|
||||
float x = pos.x * PTM_RATIO;
|
||||
float y = pos.y * PTM_RATIO;
|
||||
|
||||
if ( isIgnoreAnchorPointForPosition() ) {
|
||||
x += _anchorPointInPoints.x;
|
||||
y += _anchorPointInPoints.y;
|
||||
}
|
||||
|
||||
// Make matrix
|
||||
float radians = _body->GetAngle();
|
||||
float c = cosf(radians);
|
||||
float s = sinf(radians);
|
||||
|
||||
if( ! _anchorPointInPoints.equals(PointZero) ){
|
||||
x += c*-_anchorPointInPoints.x + -s*-_anchorPointInPoints.y;
|
||||
y += s*-_anchorPointInPoints.x + c*-_anchorPointInPoints.y;
|
||||
}
|
||||
|
||||
// Rot, Translate Matrix
|
||||
_transform = AffineTransformMake( c, s,
|
||||
-s, c,
|
||||
x, y );
|
||||
|
||||
return _transform;
|
||||
}
|
||||
|
||||
HelloWorld::HelloWorld()
|
||||
{
|
||||
setTouchEnabled( true );
|
||||
setAccelerometerEnabled( true );
|
||||
|
||||
Size s = Director::getInstance()->getWinSize();
|
||||
// init physics
|
||||
this->initPhysics();
|
||||
|
||||
SpriteBatchNode *parent = SpriteBatchNode::create("blocks.png", 100);
|
||||
_spriteTexture = parent->getTexture();
|
||||
|
||||
addChild(parent, 0, kTagParentNode);
|
||||
|
||||
|
||||
addNewSpriteAtPosition(ccp(s.width/2, s.height/2));
|
||||
|
||||
LabelTTF *label = LabelTTF::create("Tap screen", "Marker Felt", 32);
|
||||
addChild(label, 0);
|
||||
label->setColor(ccc3(0,0,255));
|
||||
label->setPosition(ccp( s.width/2, s.height-50));
|
||||
|
||||
scheduleUpdate();
|
||||
}
|
||||
|
||||
HelloWorld::~HelloWorld()
|
||||
{
|
||||
delete world;
|
||||
world = NULL;
|
||||
|
||||
//delete _debugDraw;
|
||||
}
|
||||
|
||||
void HelloWorld::initPhysics()
|
||||
{
|
||||
|
||||
Size s = Director::getInstance()->getWinSize();
|
||||
|
||||
b2Vec2 gravity;
|
||||
gravity.Set(0.0f, -10.0f);
|
||||
world = new b2World(gravity);
|
||||
|
||||
// Do we want to let bodies sleep?
|
||||
world->SetAllowSleeping(true);
|
||||
|
||||
world->SetContinuousPhysics(true);
|
||||
|
||||
// _debugDraw = new GLESDebugDraw( PTM_RATIO );
|
||||
// world->SetDebugDraw(_debugDraw);
|
||||
|
||||
uint32 flags = 0;
|
||||
flags += b2Draw::e_shapeBit;
|
||||
// flags += b2Draw::e_jointBit;
|
||||
// flags += b2Draw::e_aabbBit;
|
||||
// flags += b2Draw::e_pairBit;
|
||||
// flags += b2Draw::e_centerOfMassBit;
|
||||
//_debugDraw->SetFlags(flags);
|
||||
|
||||
|
||||
// Define the ground body.
|
||||
b2BodyDef groundBodyDef;
|
||||
groundBodyDef.position.Set(0, 0); // bottom-left corner
|
||||
|
||||
// Call the body factory which allocates memory for the ground body
|
||||
// from a pool and creates the ground box shape (also from a pool).
|
||||
// The body is also added to the world.
|
||||
b2Body* groundBody = world->CreateBody(&groundBodyDef);
|
||||
|
||||
// Define the ground box shape.
|
||||
b2EdgeShape groundBox;
|
||||
|
||||
// bottom
|
||||
|
||||
groundBox.Set(b2Vec2(0,0), b2Vec2(s.width/PTM_RATIO,0));
|
||||
groundBody->CreateFixture(&groundBox,0);
|
||||
|
||||
// top
|
||||
groundBox.Set(b2Vec2(0,s.height/PTM_RATIO), b2Vec2(s.width/PTM_RATIO,s.height/PTM_RATIO));
|
||||
groundBody->CreateFixture(&groundBox,0);
|
||||
|
||||
// left
|
||||
groundBox.Set(b2Vec2(0,s.height/PTM_RATIO), b2Vec2(0,0));
|
||||
groundBody->CreateFixture(&groundBox,0);
|
||||
|
||||
// right
|
||||
groundBox.Set(b2Vec2(s.width/PTM_RATIO,s.height/PTM_RATIO), b2Vec2(s.width/PTM_RATIO,0));
|
||||
groundBody->CreateFixture(&groundBox,0);
|
||||
}
|
||||
|
||||
void HelloWorld::draw()
|
||||
{
|
||||
//
|
||||
// IMPORTANT:
|
||||
// This is only for debug purposes
|
||||
// It is recommend to disable it
|
||||
//
|
||||
Layer::draw();
|
||||
|
||||
ccGLEnableVertexAttribs( kVertexAttribFlag_Position );
|
||||
|
||||
kmGLPushMatrix();
|
||||
|
||||
world->DrawDebugData();
|
||||
|
||||
kmGLPopMatrix();
|
||||
}
|
||||
|
||||
void HelloWorld::addNewSpriteAtPosition(Point p)
|
||||
{
|
||||
CCLOG("Add sprite %0.2f x %02.f",p.x,p.y);
|
||||
Node* parent = getChildByTag(kTagParentNode);
|
||||
|
||||
//We have a 64x64 sprite sheet with 4 different 32x32 images. The following code is
|
||||
//just randomly picking one of the images
|
||||
int idx = (CCRANDOM_0_1() > .5 ? 0:1);
|
||||
int idy = (CCRANDOM_0_1() > .5 ? 0:1);
|
||||
PhysicsSprite *sprite = new PhysicsSprite();
|
||||
sprite->initWithTexture(_spriteTexture, CCRectMake(32 * idx,32 * idy,32,32));
|
||||
sprite->autorelease();
|
||||
|
||||
parent->addChild(sprite);
|
||||
|
||||
sprite->setPosition( CCPointMake( p.x, p.y) );
|
||||
|
||||
// Define the dynamic body.
|
||||
//Set up a 1m squared box in the physics world
|
||||
b2BodyDef bodyDef;
|
||||
bodyDef.type = b2_dynamicBody;
|
||||
bodyDef.position.Set(p.x/PTM_RATIO, p.y/PTM_RATIO);
|
||||
|
||||
b2Body *body = world->CreateBody(&bodyDef);
|
||||
|
||||
// Define another box shape for our dynamic body.
|
||||
b2PolygonShape dynamicBox;
|
||||
dynamicBox.SetAsBox(.5f, .5f);//These are mid points for our 1m box
|
||||
|
||||
// Define the dynamic body fixture.
|
||||
b2FixtureDef fixtureDef;
|
||||
fixtureDef.shape = &dynamicBox;
|
||||
fixtureDef.density = 1.0f;
|
||||
fixtureDef.friction = 0.3f;
|
||||
body->CreateFixture(&fixtureDef);
|
||||
|
||||
sprite->setPhysicsBody(body);
|
||||
}
|
||||
|
||||
|
||||
void HelloWorld::update(float dt)
|
||||
{
|
||||
//It is recommended that a fixed time step is used with Box2D for stability
|
||||
//of the simulation, however, we are using a variable time step here.
|
||||
//You need to make an informed choice, the following URL is useful
|
||||
//http://gafferongames.com/game-physics/fix-your-timestep/
|
||||
|
||||
int velocityIterations = 8;
|
||||
int positionIterations = 1;
|
||||
|
||||
// Instruct the world to perform a single step of simulation. It is
|
||||
// generally best to keep the time step and iterations fixed.
|
||||
world->Step(dt, velocityIterations, positionIterations);
|
||||
|
||||
//Iterate over the bodies in the physics world
|
||||
for (b2Body* b = world->GetBodyList(); b; b = b->GetNext())
|
||||
{
|
||||
if (b->GetUserData() != NULL) {
|
||||
//Synchronize the AtlasSprites position and rotation with the corresponding body
|
||||
Sprite* myActor = (Sprite*)b->GetUserData();
|
||||
myActor->setPosition( CCPointMake( b->GetPosition().x * PTM_RATIO, b->GetPosition().y * PTM_RATIO) );
|
||||
myActor->setRotation( -1 * CC_RADIANS_TO_DEGREES(b->GetAngle()) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void HelloWorld::ccTouchesEnded(Set* touches, Event* event)
|
||||
{
|
||||
//Add a new body/atlas sprite at the touched location
|
||||
SetIterator it;
|
||||
Touch* touch;
|
||||
|
||||
for( it = touches->begin(); it != touches->end(); it++)
|
||||
{
|
||||
touch = (Touch*)(*it);
|
||||
|
||||
if(!touch)
|
||||
break;
|
||||
|
||||
Point location = touch->getLocationInView();
|
||||
|
||||
location = Director::getInstance()->convertToGL(location);
|
||||
|
||||
addNewSpriteAtPosition( location );
|
||||
}
|
||||
}
|
||||
|
||||
Scene* HelloWorld::scene()
|
||||
{
|
||||
// 'scene' is an autorelease object
|
||||
Scene *scene = Scene::create();
|
||||
|
||||
// add layer as a child to scene
|
||||
Layer* layer = new HelloWorld();
|
||||
scene->addChild(layer);
|
||||
layer->release();
|
||||
|
||||
return scene;
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
//
|
||||
// HelloWorldScene.h
|
||||
// ___PROJECTNAME___
|
||||
//
|
||||
// Created by ___FULLUSERNAME___ on ___DATE___.
|
||||
// Copyright ___ORGANIZATIONNAME___ ___YEAR___. All rights reserved.
|
||||
//
|
||||
#ifndef __HELLO_WORLD_H__
|
||||
#define __HELLO_WORLD_H__
|
||||
|
||||
// When you import this file, you import all the cocos2d classes
|
||||
#include "cocos2d.h"
|
||||
#include "Box2D.h"
|
||||
|
||||
class PhysicsSprite : public cocos2d::Sprite
|
||||
{
|
||||
public:
|
||||
PhysicsSprite();
|
||||
void setPhysicsBody(b2Body * body);
|
||||
virtual bool isDirty(void);
|
||||
virtual cocos2d::AffineTransform nodeToParentTransform(void);
|
||||
private:
|
||||
b2Body* _body; // strong ref
|
||||
};
|
||||
|
||||
class HelloWorld : public cocos2d::Layer {
|
||||
public:
|
||||
~HelloWorld();
|
||||
HelloWorld();
|
||||
|
||||
// returns a Scene that contains the HelloWorld as the only child
|
||||
static cocos2d::Scene* scene();
|
||||
|
||||
void initPhysics();
|
||||
// adds a new sprite at a given coordinate
|
||||
void addNewSpriteAtPosition(cocos2d::Point p);
|
||||
|
||||
virtual void draw();
|
||||
virtual void ccTouchesEnded(cocos2d::Set* touches, cocos2d::Event* event);
|
||||
void update(float dt);
|
||||
|
||||
private:
|
||||
b2World* world;
|
||||
cocos2d::Texture2D* _spriteTexture; // weak ref
|
||||
};
|
||||
|
||||
#endif // __HELLO_WORLD_H__
|
|
@ -1,8 +0,0 @@
|
|||
//
|
||||
// Prefix header for all source files of the '___PROJECTNAME___' target in the '___PROJECTNAME___' project
|
||||
//
|
||||
|
||||
#ifdef __OBJC__
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <UIKit/UIKit.h>
|
||||
#endif
|
Binary file not shown.
|
@ -1,62 +0,0 @@
|
|||
//
|
||||
// ___PROJECTNAMEASIDENTIFIER___AppDelegate.cpp
|
||||
// ___PROJECTNAME___
|
||||
//
|
||||
// Created by ___FULLUSERNAME___ on ___DATE___.
|
||||
// Copyright ___ORGANIZATIONNAME___ ___YEAR___. All rights reserved.
|
||||
//
|
||||
|
||||
#include "AppDelegate.h"
|
||||
|
||||
#include "cocos2d.h"
|
||||
#include "SimpleAudioEngine.h"
|
||||
#include "HelloWorldScene.h"
|
||||
|
||||
USING_NS_CC;
|
||||
using namespace CocosDenshion;
|
||||
|
||||
AppDelegate::AppDelegate()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
AppDelegate::~AppDelegate()
|
||||
{
|
||||
}
|
||||
|
||||
bool AppDelegate::applicationDidFinishLaunching()
|
||||
{
|
||||
// initialize director
|
||||
Director *pDirector = Director::getInstance();
|
||||
pDirector->setOpenGLView(EGLView::getInstance());
|
||||
|
||||
// turn on display FPS
|
||||
pDirector->setDisplayStats(true);
|
||||
|
||||
// set FPS. the default value is 1.0/60 if you don't call this
|
||||
pDirector->setAnimationInterval(1.0 / 60);
|
||||
|
||||
// create a scene. it's an autorelease object
|
||||
Scene *pScene = HelloWorld::scene();
|
||||
|
||||
// run
|
||||
pDirector->runWithScene(pScene);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// This function will be called when the app is inactive. When comes a phone call,it's be invoked too
|
||||
void AppDelegate::applicationDidEnterBackground()
|
||||
{
|
||||
Director::getInstance()->stopAnimation();
|
||||
SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic();
|
||||
SimpleAudioEngine::sharedEngine()->pauseAllEffects();
|
||||
}
|
||||
|
||||
// this function will be called when the app is active again
|
||||
void AppDelegate::applicationWillEnterForeground()
|
||||
{
|
||||
Director::getInstance()->startAnimation();
|
||||
SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic();
|
||||
SimpleAudioEngine::sharedEngine()->resumeAllEffects();
|
||||
}
|
|
@ -1,46 +0,0 @@
|
|||
//
|
||||
// ___PROJECTNAMEASIDENTIFIER___AppDelegate.h
|
||||
// ___PROJECTNAME___
|
||||
//
|
||||
// Created by ___FULLUSERNAME___ on ___DATE___.
|
||||
// Copyright ___ORGANIZATIONNAME___ ___YEAR___. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef _APP_DELEGATE_H_
|
||||
#define _APP_DELEGATE_H_
|
||||
|
||||
#include "CCApplication.h"
|
||||
|
||||
/**
|
||||
@brief The cocos2d Application.
|
||||
|
||||
The reason for implement as private inheritance is to hide some interface call by Director.
|
||||
*/
|
||||
class AppDelegate : private cocos2d::Application
|
||||
{
|
||||
public:
|
||||
AppDelegate();
|
||||
virtual ~AppDelegate();
|
||||
|
||||
/**
|
||||
@brief Implement Director and Scene init code here.
|
||||
@return true Initialize success, app continue.
|
||||
@return false Initialize failed, app terminate.
|
||||
*/
|
||||
virtual bool applicationDidFinishLaunching();
|
||||
|
||||
/**
|
||||
@brief The function be called when the application enter background
|
||||
@param the pointer of the application
|
||||
*/
|
||||
virtual void applicationDidEnterBackground();
|
||||
|
||||
/**
|
||||
@brief The function be called when the application enter foreground
|
||||
@param the pointer of the application
|
||||
*/
|
||||
virtual void applicationWillEnterForeground();
|
||||
};
|
||||
|
||||
#endif // _APP_DELEGATE_H_
|
||||
|
|
@ -1,271 +0,0 @@
|
|||
//
|
||||
// HelloWorldScene.cpp
|
||||
// ___PROJECTNAME___
|
||||
//
|
||||
// Created by ___FULLUSERNAME___ on ___DATE___.
|
||||
// Copyright ___ORGANIZATIONNAME___ ___YEAR___. All rights reserved.
|
||||
//
|
||||
|
||||
|
||||
#include "HelloWorldScene.h"
|
||||
#include "SimpleAudioEngine.h"
|
||||
|
||||
using namespace cocos2d;
|
||||
using namespace CocosDenshion;
|
||||
|
||||
enum {
|
||||
kTagParentNode = 1,
|
||||
};
|
||||
|
||||
// callback to remove Shapes from the Space
|
||||
void removeShape( cpBody *body, cpShape *shape, void *data )
|
||||
{
|
||||
cpShapeFree( shape );
|
||||
}
|
||||
|
||||
ChipmunkPhysicsSprite::ChipmunkPhysicsSprite()
|
||||
: _body(NULL)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
ChipmunkPhysicsSprite::~ChipmunkPhysicsSprite()
|
||||
{
|
||||
cpBodyEachShape(_body, removeShape, NULL);
|
||||
cpBodyFree( _body );
|
||||
}
|
||||
|
||||
void ChipmunkPhysicsSprite::setPhysicsBody(cpBody * body)
|
||||
{
|
||||
_body = body;
|
||||
}
|
||||
|
||||
// this method will only get called if the sprite is batched.
|
||||
// return YES if the physics values (angles, position ) changed
|
||||
// If you return NO, then nodeToParentTransform won't be called.
|
||||
bool ChipmunkPhysicsSprite::isDirty(void)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
AffineTransform ChipmunkPhysicsSprite::nodeToParentTransform(void)
|
||||
{
|
||||
float x = _body->p.x;
|
||||
float y = _body->p.y;
|
||||
|
||||
if ( isIgnoreAnchorPointForPosition() ) {
|
||||
x += _anchorPointInPoints.x;
|
||||
y += _anchorPointInPoints.y;
|
||||
}
|
||||
|
||||
// Make matrix
|
||||
float c = _body->rot.x;
|
||||
float s = _body->rot.y;
|
||||
|
||||
if( ! _anchorPointInPoints.equals(PointZero) ){
|
||||
x += c*-_anchorPointInPoints.x + -s*-_anchorPointInPoints.y;
|
||||
y += s*-_anchorPointInPoints.x + c*-_anchorPointInPoints.y;
|
||||
}
|
||||
|
||||
// Rot, Translate Matrix
|
||||
_transform = AffineTransformMake( c, s,
|
||||
-s, c,
|
||||
x, y );
|
||||
|
||||
return _transform;
|
||||
}
|
||||
|
||||
HelloWorld::HelloWorld()
|
||||
{
|
||||
}
|
||||
|
||||
HelloWorld::~HelloWorld()
|
||||
{
|
||||
// manually Free rogue shapes
|
||||
for( int i=0;i<4;i++) {
|
||||
cpShapeFree( _walls[i] );
|
||||
}
|
||||
|
||||
cpSpaceFree( _space );
|
||||
|
||||
}
|
||||
|
||||
Scene* HelloWorld::scene()
|
||||
{
|
||||
// 'scene' is an autorelease object.
|
||||
Scene *scene = Scene::create();
|
||||
|
||||
// 'layer' is an autorelease object.
|
||||
HelloWorld *layer = HelloWorld::create();
|
||||
|
||||
// add layer as a child to scene
|
||||
scene->addChild(layer);
|
||||
|
||||
// return the scene
|
||||
return scene;
|
||||
}
|
||||
|
||||
bool HelloWorld::init()
|
||||
{
|
||||
if (!Layer::init())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// enable events
|
||||
setTouchEnabled(true);
|
||||
setAccelerometerEnabled(true);
|
||||
|
||||
Size s = Director::getInstance()->getWinSize();
|
||||
|
||||
// title
|
||||
LabelTTF *label = LabelTTF::create("Multi touch the screen", "Marker Felt", 36);
|
||||
label->setPosition(ccp( s.width / 2, s.height - 30));
|
||||
this->addChild(label, -1);
|
||||
|
||||
// init physics
|
||||
initPhysics();
|
||||
|
||||
#if 1
|
||||
// Use batch node. Faster
|
||||
SpriteBatchNode *parent = SpriteBatchNode::create("grossini_dance_atlas.png", 100);
|
||||
_spriteTexture = parent->getTexture();
|
||||
#else
|
||||
// doesn't use batch node. Slower
|
||||
_spriteTexture = TextureCache::getInstance():addImage("grossini_dance_atlas.png");
|
||||
Node *parent = Node::node();
|
||||
#endif
|
||||
addChild(parent, 0, kTagParentNode);
|
||||
|
||||
addNewSpriteAtPosition(ccp(200,200));
|
||||
|
||||
scheduleUpdate();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void HelloWorld::initPhysics()
|
||||
{
|
||||
Size s = Director::getInstance()->getWinSize();
|
||||
|
||||
// init chipmunk
|
||||
cpInitChipmunk();
|
||||
|
||||
_space = cpSpaceNew();
|
||||
|
||||
_space->gravity = cpv(0, -100);
|
||||
|
||||
//
|
||||
// rogue shapes
|
||||
// We have to free them manually
|
||||
//
|
||||
// bottom
|
||||
_walls[0] = cpSegmentShapeNew( _space->staticBody, cpv(0,0), cpv(s.width,0), 0.0f);
|
||||
|
||||
// top
|
||||
_walls[1] = cpSegmentShapeNew( _space->staticBody, cpv(0,s.height), cpv(s.width,s.height), 0.0f);
|
||||
|
||||
// left
|
||||
_walls[2] = cpSegmentShapeNew( _space->staticBody, cpv(0,0), cpv(0,s.height), 0.0f);
|
||||
|
||||
// right
|
||||
_walls[3] = cpSegmentShapeNew( _space->staticBody, cpv(s.width,0), cpv(s.width,s.height), 0.0f);
|
||||
|
||||
for( int i=0;i<4;i++) {
|
||||
_walls[i]->e = 1.0f;
|
||||
_walls[i]->u = 1.0f;
|
||||
cpSpaceAddStaticShape(_space, _walls[i] );
|
||||
}
|
||||
}
|
||||
|
||||
void HelloWorld::update(float delta)
|
||||
{
|
||||
// Should use a fixed size step based on the animation interval.
|
||||
int steps = 2;
|
||||
float dt = Director::getInstance()->getAnimationInterval()/(float)steps;
|
||||
|
||||
for(int i=0; i<steps; i++){
|
||||
cpSpaceStep(_space, dt);
|
||||
}
|
||||
}
|
||||
|
||||
void HelloWorld::addNewSpriteAtPosition(Point pos)
|
||||
{
|
||||
int posx, posy;
|
||||
|
||||
Node *parent = getChildByTag(kTagParentNode);
|
||||
|
||||
posx = CCRANDOM_0_1() * 200.0f;
|
||||
posy = CCRANDOM_0_1() * 200.0f;
|
||||
|
||||
posx = (posx % 4) * 85;
|
||||
posy = (posy % 3) * 121;
|
||||
|
||||
ChipmunkPhysicsSprite *sprite = new ChipmunkPhysicsSprite();
|
||||
sprite->initWithTexture(_spriteTexture, CCRectMake(posx, posy, 85, 121));
|
||||
sprite->autorelease();
|
||||
|
||||
parent->addChild(sprite);
|
||||
|
||||
sprite->setPosition(pos);
|
||||
|
||||
int num = 4;
|
||||
cpVect verts[] = {
|
||||
cpv(-24,-54),
|
||||
cpv(-24, 54),
|
||||
cpv( 24, 54),
|
||||
cpv( 24,-54),
|
||||
};
|
||||
|
||||
cpBody *body = cpBodyNew(1.0f, cpMomentForPoly(1.0f, num, verts, cpvzero));
|
||||
|
||||
body->p = cpv(pos.x, pos.y);
|
||||
cpSpaceAddBody(_space, body);
|
||||
|
||||
cpShape* shape = cpPolyShapeNew(body, num, verts, cpvzero);
|
||||
shape->e = 0.5f; shape->u = 0.5f;
|
||||
cpSpaceAddShape(_space, shape);
|
||||
|
||||
sprite->setPhysicsBody(body);
|
||||
}
|
||||
|
||||
void HelloWorld::ccTouchesEnded(Set* touches, Event* event)
|
||||
{
|
||||
//Add a new body/atlas sprite at the touched location
|
||||
SetIterator it;
|
||||
Touch* touch;
|
||||
|
||||
for( it = touches->begin(); it != touches->end(); it++)
|
||||
{
|
||||
touch = (Touch*)(*it);
|
||||
|
||||
if(!touch)
|
||||
break;
|
||||
|
||||
Point location = touch->getLocationInView();
|
||||
|
||||
location = Director::getInstance()->convertToGL(location);
|
||||
|
||||
addNewSpriteAtPosition( location );
|
||||
}
|
||||
}
|
||||
|
||||
void HelloWorld::didAccelerate(Acceleration* pAccelerationValue)
|
||||
{
|
||||
static float prevX=0, prevY=0;
|
||||
|
||||
#define kFilterFactor 0.05f
|
||||
|
||||
float accelX = (float) pAccelerationValue->x * kFilterFactor + (1- kFilterFactor)*prevX;
|
||||
float accelY = (float) pAccelerationValue->y * kFilterFactor + (1- kFilterFactor)*prevY;
|
||||
|
||||
prevX = accelX;
|
||||
prevY = accelY;
|
||||
|
||||
Point v = ccp( accelX, accelY);
|
||||
v = ccpMult(v, 200);
|
||||
_space->gravity = cpv(v.x, v.y);
|
||||
}
|
||||
|
||||
|
|
@ -1,51 +0,0 @@
|
|||
//
|
||||
// HelloWorldScene.h
|
||||
// ___PROJECTNAME___
|
||||
//
|
||||
// Created by ___FULLUSERNAME___ on ___DATE___.
|
||||
// Copyright ___ORGANIZATIONNAME___ ___YEAR___. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef __HELLOW_WORLD_H__
|
||||
#define __HELLOW_WORLD_H__
|
||||
|
||||
#include "cocos2d.h"
|
||||
|
||||
// include Chipmunk headers
|
||||
#include "chipmunk.h"
|
||||
|
||||
class ChipmunkPhysicsSprite : public cocos2d::Sprite
|
||||
{
|
||||
public:
|
||||
ChipmunkPhysicsSprite();
|
||||
virtual ~ChipmunkPhysicsSprite();
|
||||
void setPhysicsBody(cpBody* body);
|
||||
virtual bool isDirty(void);
|
||||
virtual cocos2d::AffineTransform nodeToParentTransform(void);
|
||||
private:
|
||||
cpBody* _body; // strong ref
|
||||
};
|
||||
|
||||
// HelloWorld Layer
|
||||
class HelloWorld : public cocos2d::Layer {
|
||||
public:
|
||||
HelloWorld();
|
||||
~HelloWorld();
|
||||
bool init();
|
||||
static cocos2d::Scene* scene();
|
||||
CREATE_FUNC(HelloWorld);
|
||||
|
||||
void initPhysics();
|
||||
void addNewSpriteAtPosition(cocos2d::Point p);
|
||||
void update(float dt);
|
||||
virtual void ccTouchesEnded(cocos2d::Set* touches, cocos2d::Event* event);
|
||||
virtual void didAccelerate(cocos2d::Acceleration* pAccelerationValue);
|
||||
|
||||
private:
|
||||
cocos2d::Texture2D* _spriteTexture; // weak ref
|
||||
cpSpace* _space; // strong ref
|
||||
cpShape* _walls[4];
|
||||
|
||||
};
|
||||
|
||||
#endif // __HELLOW_WORLD_H__
|
|
@ -1,8 +0,0 @@
|
|||
//
|
||||
// Prefix header for all source files of the '___PROJECTNAME___' target in the '___PROJECTNAME___' project
|
||||
//
|
||||
|
||||
#ifdef __OBJC__
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <UIKit/UIKit.h>
|
||||
#endif
|
Binary file not shown.
|
@ -1,94 +0,0 @@
|
|||
#include "AppDelegate.h"
|
||||
|
||||
#include "cocos2d.h"
|
||||
#include "SimpleAudioEngine.h"
|
||||
#include "ScriptingCore.h"
|
||||
#include "jsb_cocos2dx_auto.hpp"
|
||||
#include "jsb_cocos2dx_extension_auto.hpp"
|
||||
#include "jsb_cocos2dx_extension_manual.h"
|
||||
#include "cocos2d_specifics.hpp"
|
||||
#include "js_bindings_chipmunk_registration.h"
|
||||
#include "js_bindings_ccbreader.h"
|
||||
#include "js_bindings_system_registration.h"
|
||||
#include "jsb_opengl_registration.h"
|
||||
#include "XMLHTTPRequest.h"
|
||||
|
||||
USING_NS_CC;
|
||||
using namespace CocosDenshion;
|
||||
|
||||
AppDelegate::AppDelegate()
|
||||
{
|
||||
}
|
||||
|
||||
AppDelegate::~AppDelegate()
|
||||
{
|
||||
// SimpleAudioEngine::end();
|
||||
}
|
||||
|
||||
bool AppDelegate::applicationDidFinishLaunching()
|
||||
{
|
||||
// initialize director
|
||||
Director *pDirector = Director::getInstance();
|
||||
pDirector->setOpenGLView(EGLView::getInstance());
|
||||
|
||||
// turn on display FPS
|
||||
pDirector->setDisplayStats(true);
|
||||
|
||||
// set FPS. the default value is 1.0/60 if you don't call this
|
||||
pDirector->setAnimationInterval(1.0 / 60);
|
||||
|
||||
ScriptingCore* sc = ScriptingCore::getInstance();
|
||||
sc->addRegisterCallback(register_all_cocos2dx);
|
||||
sc->addRegisterCallback(register_all_cocos2dx_extension);
|
||||
sc->addRegisterCallback(register_cocos2dx_js_extensions);
|
||||
sc->addRegisterCallback(register_all_cocos2dx_extension_manual);
|
||||
sc->addRegisterCallback(register_CCBuilderReader);
|
||||
sc->addRegisterCallback(jsb_register_chipmunk);
|
||||
sc->addRegisterCallback(jsb_register_system);
|
||||
sc->addRegisterCallback(JSB_register_opengl);
|
||||
sc->addRegisterCallback(MinXmlHttpRequest::_js_register);
|
||||
|
||||
sc->start();
|
||||
|
||||
ScriptEngineProtocol *pEngine = ScriptingCore::getInstance();
|
||||
ScriptEngineManager::getInstance()->setScriptEngine(pEngine);
|
||||
ScriptingCore::getInstance()->runScript("hello.js");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void handle_signal(int signal) {
|
||||
static int internal_state = 0;
|
||||
ScriptingCore* sc = ScriptingCore::getInstance();
|
||||
// should start everything back
|
||||
Director* director = Director::getInstance();
|
||||
if (director->getRunningScene()) {
|
||||
director->popToRootScene();
|
||||
} else {
|
||||
PoolManager::sharedPoolManager()->finalize();
|
||||
if (internal_state == 0) {
|
||||
//sc->dumpRoot(NULL, 0, NULL);
|
||||
sc->start();
|
||||
internal_state = 1;
|
||||
} else {
|
||||
sc->runScript("hello.js");
|
||||
internal_state = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// This function will be called when the app is inactive. When comes a phone call,it's be invoked too
|
||||
void AppDelegate::applicationDidEnterBackground()
|
||||
{
|
||||
Director::getInstance()->stopAnimation();
|
||||
SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic();
|
||||
SimpleAudioEngine::sharedEngine()->pauseAllEffects();
|
||||
}
|
||||
|
||||
// this function will be called when the app is active again
|
||||
void AppDelegate::applicationWillEnterForeground()
|
||||
{
|
||||
Director::getInstance()->startAnimation();
|
||||
SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic();
|
||||
SimpleAudioEngine::sharedEngine()->resumeAllEffects();
|
||||
}
|
|
@ -1,45 +0,0 @@
|
|||
//
|
||||
// GCTestAppDelegate.h
|
||||
// GCTest
|
||||
//
|
||||
// Created by Rohan Kuruvilla on 06/08/2012.
|
||||
// Copyright __MyCompanyName__ 2012. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef _APP_DELEGATE_H_
|
||||
#define _APP_DELEGATE_H_
|
||||
|
||||
#include "CCApplication.h"
|
||||
/**
|
||||
@brief The cocos2d Application.
|
||||
|
||||
The reason for implement as private inheritance is to hide some interface call by Director.
|
||||
*/
|
||||
class AppDelegate : private cocos2d::Application
|
||||
{
|
||||
public:
|
||||
AppDelegate();
|
||||
virtual ~AppDelegate();
|
||||
|
||||
/**
|
||||
@brief Implement Director and Scene init code here.
|
||||
@return true Initialize success, app continue.
|
||||
@return false Initialize failed, app terminate.
|
||||
*/
|
||||
virtual bool applicationDidFinishLaunching();
|
||||
|
||||
/**
|
||||
@brief The function be called when the application enter background
|
||||
@param the pointer of the application
|
||||
*/
|
||||
virtual void applicationDidEnterBackground();
|
||||
|
||||
/**
|
||||
@brief The function be called when the application enter foreground
|
||||
@param the pointer of the application
|
||||
*/
|
||||
virtual void applicationWillEnterForeground();
|
||||
};
|
||||
|
||||
#endif // _APP_DELEGATE_H_
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
//
|
||||
// Prefix header for all source files of the '___PROJECTNAME___' target in the '___PROJECTNAME___' project
|
||||
//
|
||||
|
||||
#ifdef __OBJC__
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <UIKit/UIKit.h>
|
||||
#endif
|
|
@ -1 +0,0 @@
|
|||
f06c047dd32b61f12ad51e981afe518364512be6
|
|
@ -1 +0,0 @@
|
|||
4b7c1e97acefff48ae3652f023e708245992f553
|
|
@ -1 +0,0 @@
|
|||
ae62d7b07ac3e7579ed7d6a2e1f903719e45c6d9
|
|
@ -1 +0,0 @@
|
|||
12db20c3124e1bd864312257eb8cefe95d2ee349
|
|
@ -1 +0,0 @@
|
|||
e71140c1535f16b49980f3ea0cf7d3a29a8a9788
|
|
@ -1 +0,0 @@
|
|||
dc235c169030151e337ecbfa1fc6302fc909e500
|
|
@ -1 +0,0 @@
|
|||
9e95a02e6eb2944fea12a49eb3f2c6fe7505a3ce
|
|
@ -1 +0,0 @@
|
|||
1423c81273926b3da9fb1cb36c9b710d3f14ee0e
|
|
@ -1,208 +0,0 @@
|
|||
// first attempt at the debugger
|
||||
|
||||
var g = newGlobal("debug-global");
|
||||
var dbg = Debugger(g);
|
||||
|
||||
var breakpointHandler = {
|
||||
hit: function (frame) {
|
||||
var script = frame.script;
|
||||
_socketWrite(dbg.socket, "entering breakpoint: \n");
|
||||
_socketWrite(dbg.socket, " " + script.url + ":" + script.getOffsetLine(frame.offset) + "\n");
|
||||
beginDebug(frame, frame.script);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
let offsets = script.getLineOffsets(aLocation.line);
|
||||
let codeFound = false;
|
||||
for (let i = 0; i < offsets.length; i++) {
|
||||
script.setBreakpoint(offsets[i], bpActor);
|
||||
codeFound = true;
|
||||
}
|
||||
|
||||
let actualLocation;
|
||||
if (offsets.length == 0) {
|
||||
// No code at that line in any script, skipping forward.
|
||||
let lines = script.getAllOffsets();
|
||||
let oldLine = aLocation.line;
|
||||
for (let line = oldLine; line < lines.length; ++line) {
|
||||
if (lines[line]) {
|
||||
for (let i = 0; i < lines[line].length; i++) {
|
||||
script.setBreakpoint(lines[line][i], bpActor);
|
||||
codeFound = true;
|
||||
}
|
||||
actualLocation = {
|
||||
url: aLocation.url,
|
||||
line: line,
|
||||
column: aLocation.column
|
||||
};
|
||||
bpActor.location = actualLocation;
|
||||
// Update the cache as well.
|
||||
scriptBreakpoints[line] = scriptBreakpoints[oldLine];
|
||||
scriptBreakpoints[line].line = line;
|
||||
delete scriptBreakpoints[oldLine];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
var beginDebug = function (frame, script) {
|
||||
log(">> debugging js... listening on port 1337");
|
||||
var stop = false;
|
||||
var offsets = 0;
|
||||
var processInput = function (str, socket) {
|
||||
var md = str.match(/^break current:(\d+)/);
|
||||
if (!frame && md) {
|
||||
var codeFound = false, i;
|
||||
offsets = script.getLineOffsets(parseInt(md[1], 10));
|
||||
_socketWrite(socket, "offsets: " + JSON.stringify(offsets) + "\n");
|
||||
for (i=0; i < offsets.lenth; i++) {
|
||||
script.setBreakpoint(offsets[i], breakpointHandler);
|
||||
codeFound = true;
|
||||
}
|
||||
if (offsets.length === 0) {
|
||||
var lines = script.getAllOffsets();
|
||||
var oldLine = parseInt(md[1], 10);
|
||||
for (var line = oldLine; line < lines.length; ++line) {
|
||||
if (lines[line]) {
|
||||
for (i=0; i < lines[line].length; i++) {
|
||||
script.setBreakpoint(lines[line][i], breakpointHandler);
|
||||
codeFound = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!codeFound) {
|
||||
_socketWrite(socket, "invalid offset: " + offsets.join(",") + "\n");
|
||||
} else {
|
||||
_socketWrite(socket, "socket set at line " + md[1] + " for current file\n");
|
||||
}
|
||||
return;
|
||||
}
|
||||
md = str.match(/^b(reak)?\s+([^:]+):(\d+)/);
|
||||
if (md) {
|
||||
script = _getScript(md[2]);
|
||||
if (script) {
|
||||
offsets = script.getLineOffset(parseInt(md[3], 10));
|
||||
script.setBreakpoint(offsets[0], breakpointHandler);
|
||||
_socketWrite(socket, "breakpoint set for line " + md[3] + " of script " + md[2] + "\n");
|
||||
} else {
|
||||
_socketWrite(socket, "no script with that name" + "\n");
|
||||
}
|
||||
return;
|
||||
}
|
||||
md = str.match(/^c(ontinue)?/);
|
||||
if (md) {
|
||||
stop = true;
|
||||
return;
|
||||
}
|
||||
md = str.match(/^eval\s+(.+)/);
|
||||
if (md && frame) {
|
||||
var res = frame['eval'](md[1]),
|
||||
k;
|
||||
if (res['return']) {
|
||||
var r = res['return'];
|
||||
_socketWrite(socket, "* " + (typeof r) + "\n");
|
||||
if (typeof r == "string") {
|
||||
_socketWrite(socket, "~> " + r + "\n");
|
||||
} else {
|
||||
var props = r.getOwnPropertyNames();
|
||||
for (k in props) {
|
||||
var desc = r.getOwnPropertyDescriptor(props[k]);
|
||||
_socketWrite(socket, "~> " + props[k] + " = ");
|
||||
if (desc.value) {
|
||||
_socketWrite(socket, "" + desc.value);
|
||||
} else if (desc.get) {
|
||||
_socketWrite(socket, "" + desc.get());
|
||||
} else {
|
||||
_socketWrite(socket, "undefined (no value or getter)");
|
||||
}
|
||||
_socketWrite(socket, "\n");
|
||||
}
|
||||
}
|
||||
} else if (res['throw']) {
|
||||
_socketWrite(socket, "!! got exception: " + res['throw'].message + "\n");
|
||||
} else {
|
||||
_socketWrite(socket, "!!! invalid return for eval" + "\n");
|
||||
for (k in res) {
|
||||
_socketWrite(socket, "* " + k + ": " + res[k] + "\n");
|
||||
}
|
||||
}
|
||||
return;
|
||||
} else if (md) {
|
||||
_socketWrite(socket, "! no frame to eval in\n");
|
||||
return;
|
||||
}
|
||||
md = str.match(/^line/);
|
||||
if (md && frame) {
|
||||
_socketWrite(socket, "current line: " + script.getOffsetLine(frame.offset) + "\n");
|
||||
return;
|
||||
} else if (md) {
|
||||
_socketWrite(socket, "no line, probably entering script\n");
|
||||
return;
|
||||
}
|
||||
md = str.match(/^bt/);
|
||||
if (md && frame) {
|
||||
var cur = frame,
|
||||
stack = [cur.script.url + ":" + cur.script.getOffsetLine(cur.offset)];
|
||||
while ((cur = cur.older)) {
|
||||
stack.push(cur.script.url + ":" + cur.script.getOffsetLine(cur.offset));
|
||||
}
|
||||
_socketWrite(socket, stack.join("\n") + "\n");
|
||||
return;
|
||||
} else if (md) {
|
||||
_socketWrite(socket, "no valid frame\n");
|
||||
return;
|
||||
}
|
||||
_socketWrite("! invalid command" + "\n");
|
||||
};
|
||||
|
||||
_socketOpen(1337, function (socket) {
|
||||
_socketWrite(socket, "entering debugger for file " + script.url + "\n");
|
||||
_socketWrite(socket, ">> ");
|
||||
// set the client socket
|
||||
dbg.socket = socket;
|
||||
var str;
|
||||
while (!stop && (str = _socketRead(socket))) {
|
||||
processInput(str, socket);
|
||||
if (!stop)
|
||||
_socketWrite(socket, ">> ");
|
||||
else {
|
||||
_socketWrite(socket, "continuing execution\n");
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
dbg.onNewScript = function (script) {
|
||||
// skip if the url is this script
|
||||
var last = script.url.split("/").pop();
|
||||
if (last != "debugger.js" && script.url != "debugger eval code") {
|
||||
log("on new script: " + script.url + "; will enter debugger");
|
||||
beginDebug(null, script);
|
||||
}
|
||||
};
|
||||
|
||||
dbg.onDebuggerStatement = function (frame) {
|
||||
log("!! on debugger");
|
||||
beginDebug(frame, frame.script);
|
||||
};
|
||||
|
||||
dbg.onError = function (frame, report) {
|
||||
if (dbg.socket && report) {
|
||||
_socketWrite(dbg.socket, "!! exception @ " + report.file + ":" + report.line);
|
||||
}
|
||||
log("!! exception");
|
||||
beginDebug(frame, frame.script);
|
||||
};
|
||||
|
||||
function startDebugger(files, startFunc) {
|
||||
for (var i in files) {
|
||||
g['eval']("require('" + files[i] + "');");
|
||||
}
|
||||
if (startFunc) {
|
||||
g['eval'](startFunc);
|
||||
}
|
||||
}
|
|
@ -1,155 +0,0 @@
|
|||
require("jsb.js");
|
||||
|
||||
try {
|
||||
|
||||
director = cc.Director.getInstance();
|
||||
winSize = director.getWinSize();
|
||||
centerPos = cc.p( winSize.width/2, winSize.height/2 );
|
||||
|
||||
//
|
||||
// Main Menu
|
||||
//
|
||||
|
||||
// 'MenuLayerController' class is instantiated by CocosBuilder Reader
|
||||
var MenuLayerController = function () {
|
||||
};
|
||||
|
||||
// callback triggered by CCB Reader once the instance is created
|
||||
MenuLayerController.prototype.onDidLoadFromCCB = function () {
|
||||
// Spin the 'o' in the title
|
||||
var o = this.titleLabel.getChildByTag(8);
|
||||
|
||||
var a_delay = cc.DelayTime.create(6);
|
||||
var a_tint = cc.TintTo.create(0.5, 0, 255, 0);
|
||||
var a_rotate = cc.RotateBy.create(4, 360);
|
||||
var a_rep = cc.Repeat.create(a_rotate, 1000);
|
||||
var a_seq = cc.Sequence.create(a_delay, a_tint, a_delay.copy(), a_rep);
|
||||
o.runAction(a_seq);
|
||||
};
|
||||
|
||||
// callbacks for the menu, defined in the editor
|
||||
MenuLayerController.prototype.onPlay = function () {
|
||||
director.replaceScene( cc.TransitionFade.create(1, game.getPlayScene()) );
|
||||
};
|
||||
|
||||
MenuLayerController.prototype.onOptions = function () {
|
||||
director.replaceScene( cc.TransitionFade.create(1, game.getOptionsScene()) );
|
||||
};
|
||||
|
||||
MenuLayerController.prototype.onAbout = function () {
|
||||
director.replaceScene( cc.TransitionZoomFlipY.create(1, game.getAboutScene()) );
|
||||
};
|
||||
|
||||
var AboutLayerController = function() {}
|
||||
|
||||
AboutLayerController.prototype.onDidLoadFromCCB = function () {
|
||||
var back = cc.MenuItemFont.create("Back", this.onBack, this);
|
||||
back.setColor(cc.BLACK);
|
||||
var menu = cc.Menu.create(back);
|
||||
this.rootNode.addChild(menu);
|
||||
menu.zOrder = 100;
|
||||
menu.alignItemsVertically();
|
||||
menu.setPosition(winSize.width - 50, 50);
|
||||
};
|
||||
|
||||
AboutLayerController.prototype.onBack = function () {
|
||||
director.replaceScene( cc.TransitionFade.create(1, game.getMainMenuScene()));
|
||||
};
|
||||
|
||||
var GameCreator = function() {
|
||||
|
||||
var self = {};
|
||||
self.callbacks = {};
|
||||
|
||||
self.getPlayScene = function() {
|
||||
|
||||
var scene = new cc.Scene();
|
||||
var layer = new cc.LayerGradient();
|
||||
|
||||
layer.init(cc.c4b(0, 0, 0, 255), cc.c4b(0, 128, 255, 255));
|
||||
|
||||
var lab = "Houston we have liftoff!";
|
||||
var label = cc.LabelTTF.create(lab, "Arial", 28);
|
||||
layer.addChild(label, 1);
|
||||
label.setPosition( cc.p(winSize.width / 2, winSize.height / 2));
|
||||
|
||||
var back = cc.MenuItemFont.create("Back", self.callbacks.onBack, self.callbacks);
|
||||
back.setColor( cc.BLACK );
|
||||
|
||||
var menu = cc.Menu.create( back );
|
||||
layer.addChild( menu );
|
||||
menu.alignItemsVertically();
|
||||
menu.setPosition( cc.p( winSize.width - 50, 50) );
|
||||
|
||||
scene.addChild(layer);
|
||||
|
||||
return scene;
|
||||
};
|
||||
|
||||
self.getMainMenuScene = function() {
|
||||
return cc.BuilderReader.loadAsScene("MainMenu.ccbi");
|
||||
};
|
||||
|
||||
self.getOptionsScene = function() {
|
||||
|
||||
var l = cc.LayerGradient.create();
|
||||
l.init(cc.c4b(0, 0, 0, 255), cc.c4b(255, 255, 255, 255));
|
||||
|
||||
var scene = cc.Scene.create();
|
||||
|
||||
var label1 = cc.LabelBMFont.create("MUSIC ON", "konqa32.fnt" );
|
||||
var item1 = cc.MenuItemLabel.create(label1);
|
||||
var label2 = cc.LabelBMFont.create("MUSIC OFF", "konqa32.fnt" );
|
||||
var item2 = cc.MenuItemLabel.create(label2);
|
||||
var toggle = cc.MenuItemToggle.create( item1, item2 );
|
||||
|
||||
this.onMusicToggle = function( sender ) {
|
||||
cc.log("OptionsScene onMusicToggle...");
|
||||
};
|
||||
|
||||
toggle.setCallback( this.onMusicToggle, this);
|
||||
|
||||
var back = cc.MenuItemFont.create("Back", self.callbacks.onBack, self.callbacks);
|
||||
var menu = cc.Menu.create( toggle, back );
|
||||
l.addChild( menu );
|
||||
menu.alignItemsVertically();
|
||||
menu.setPosition( centerPos );
|
||||
|
||||
scene.addChild(l);
|
||||
|
||||
return scene;
|
||||
};
|
||||
|
||||
|
||||
self.getAboutScene = function() {
|
||||
|
||||
var scene = cc.Scene.create();
|
||||
var l = cc.Layer.create();
|
||||
var about = cc.BuilderReader.load("About.ccbi", l);
|
||||
l.addChild( about )
|
||||
|
||||
scene.addChild( l );
|
||||
|
||||
return scene;
|
||||
};
|
||||
|
||||
// Manual Callbacks
|
||||
|
||||
self.callbacks.onBack = function( sender) {
|
||||
director.replaceScene( cc.TransitionFlipX.create(1, self.getMainMenuScene()) );
|
||||
};
|
||||
|
||||
return self;
|
||||
|
||||
};
|
||||
|
||||
var game = GameCreator();
|
||||
|
||||
__jsc__.garbageCollect();
|
||||
|
||||
// LOADING PLAY SCENE UNTILL CCBREADER IS FIXED
|
||||
|
||||
director.runWithScene(game.getPlayScene());
|
||||
|
||||
} catch(e) {log(e);}
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
//
|
||||
// Javascript Bindigns helper file
|
||||
//
|
||||
|
||||
// DO NOT ALTER THE ORDER
|
||||
require('jsb_cocos2d.js');
|
||||
require('jsb_chipmunk.js');
|
||||
require('jsb_opengl.js');
|
||||
require('jsb_cocosbuilder.js');
|
||||
require('jsb_sys.js');
|
|
@ -1,328 +0,0 @@
|
|||
//
|
||||
// Chipmunk defines
|
||||
//
|
||||
|
||||
var cp = cp || {};
|
||||
|
||||
cp.v = cc.p;
|
||||
cp._v = cc._p;
|
||||
cp.vzero = cp.v(0,0);
|
||||
|
||||
// Vector: Compatibility with Chipmunk-JS
|
||||
cp.v.add = cp.vadd;
|
||||
cp.v.clamp = cp.vclamp;
|
||||
cp.v.cross = cp.vcross;
|
||||
cp.v.dist = cp.vdist;
|
||||
cp.v.distsq = cp.vdistsq;
|
||||
cp.v.dot = cp.vdot;
|
||||
cp.v.eql = cp.veql;
|
||||
cp.v.forangle = cp.vforangle;
|
||||
cp.v.len = cp.vlength;
|
||||
cp.v.lengthsq = cp.vlengthsq;
|
||||
cp.v.lerp = cp.vlerp;
|
||||
cp.v.lerpconst = cp.vlerpconst;
|
||||
cp.v.mult = cp.vmult;
|
||||
cp.v.near = cp.vnear;
|
||||
cp.v.neg = cp.vneg;
|
||||
cp.v.normalize = cp.vnormalize;
|
||||
cp.v.normalize_safe = cp.vnormalize_safe;
|
||||
cp.v.perp = cp.vperp;
|
||||
cp.v.project = cp.vproject;
|
||||
cp.v.rotate = cp.vrotate;
|
||||
cp.v.rperp = cp.vrperp;
|
||||
cp.v.slerp = cp.vslerp;
|
||||
cp.v.slerpconst = cp.vslerpconst;
|
||||
cp.v.sub = cp.vsub;
|
||||
cp.v.toangle = cp.vtoangle;
|
||||
cp.v.unrotate = cp.vunrotate;
|
||||
|
||||
// XXX: renaming functions should be supported in JSB
|
||||
cp.clamp01 = cp.fclamp01;
|
||||
|
||||
|
||||
/// Initialize an offset box shaped polygon shape.
|
||||
cp.BoxShape2 = function(body, box)
|
||||
{
|
||||
var verts = [
|
||||
box.l, box.b,
|
||||
box.l, box.t,
|
||||
box.r, box.t,
|
||||
box.r, box.b
|
||||
];
|
||||
|
||||
return new cp.PolyShape(body, verts, cp.vzero);
|
||||
};
|
||||
|
||||
/// Initialize a box shaped polygon shape.
|
||||
cp.BoxShape = function(body, width, height)
|
||||
{
|
||||
var hw = width/2;
|
||||
var hh = height/2;
|
||||
|
||||
return cp.BoxShape2(body, new cp.BB(-hw, -hh, hw, hh));
|
||||
};
|
||||
|
||||
|
||||
/// Initialize an static body
|
||||
cp.StaticBody = function()
|
||||
{
|
||||
return new cp.Body(Infinity, Infinity);
|
||||
};
|
||||
|
||||
|
||||
// "Bounding Box" compatibility with Chipmunk-JS
|
||||
cp.BB = function(l, b, r, t)
|
||||
{
|
||||
return {l:l, b:b, r:r, t:t};
|
||||
};
|
||||
|
||||
// helper function to create a BB
|
||||
cp.bb = function(l, b, r, t) {
|
||||
return new cp.BB(l, b, r, t);
|
||||
};
|
||||
|
||||
//
|
||||
// Some properties
|
||||
//
|
||||
// "handle" needed in some cases
|
||||
Object.defineProperties(cp.Base.prototype,
|
||||
{
|
||||
"handle" : {
|
||||
get : function(){
|
||||
return this.getHandle();
|
||||
},
|
||||
enumerable : true,
|
||||
configurable : true
|
||||
}
|
||||
});
|
||||
|
||||
// Properties, for Chipmunk-JS compatibility
|
||||
// Space properties
|
||||
Object.defineProperties(cp.Space.prototype,
|
||||
{
|
||||
"gravity" : {
|
||||
get : function(){
|
||||
return this.getGravity();
|
||||
},
|
||||
set : function(newValue){
|
||||
this.setGravity(newValue);
|
||||
},
|
||||
enumerable : true,
|
||||
configurable : true
|
||||
},
|
||||
"iterations" : {
|
||||
get : function(){
|
||||
return this.getIterations();
|
||||
},
|
||||
set : function(newValue){
|
||||
this.setIterations(newValue);
|
||||
},
|
||||
enumerable : true,
|
||||
configurable : true
|
||||
},
|
||||
"damping" : {
|
||||
get : function(){
|
||||
return this.getDamping();
|
||||
},
|
||||
set : function(newValue){
|
||||
this.setDamping(newValue);
|
||||
},
|
||||
enumerable : true,
|
||||
configurable : true
|
||||
},
|
||||
"staticBody" : {
|
||||
get : function(){
|
||||
return this.getStaticBody();
|
||||
},
|
||||
enumerable : true,
|
||||
configurable : true
|
||||
},
|
||||
"idleSpeedThreshold" : {
|
||||
get : function(){
|
||||
return this.getIdleSpeedThreshold();
|
||||
},
|
||||
set : function(newValue){
|
||||
this.setIdleSpeedThreshold(newValue);
|
||||
},
|
||||
enumerable : true,
|
||||
configurable : true
|
||||
},
|
||||
"sleepTimeThreshold": {
|
||||
get : function(){
|
||||
return this.getSleepTimeThreshold();
|
||||
},
|
||||
set : function(newValue){
|
||||
this.setSleepTimeThreshold(newValue);
|
||||
},
|
||||
enumerable : true,
|
||||
configurable : true
|
||||
},
|
||||
"collisionSlop": {
|
||||
get : function(){
|
||||
return this.getCollisionSlop();
|
||||
},
|
||||
set : function(newValue){
|
||||
this.setCollisionSlop(newValue);
|
||||
},
|
||||
enumerable : true,
|
||||
configurable : true
|
||||
},
|
||||
"collisionBias": {
|
||||
get : function(){
|
||||
return this.getCollisionBias();
|
||||
},
|
||||
set : function(newValue){
|
||||
this.setCollisionBias(newValue);
|
||||
},
|
||||
enumerable : true,
|
||||
configurable : true
|
||||
},
|
||||
"collisionPersistence": {
|
||||
get : function(){
|
||||
return this.getCollisionPersistence();
|
||||
},
|
||||
set : function(newValue){
|
||||
this.setCollisionPersistence(newValue);
|
||||
},
|
||||
enumerable : true,
|
||||
configurable : true
|
||||
},
|
||||
"enableContactGraph": {
|
||||
get : function(){
|
||||
return this.getEnableContactGraph();
|
||||
},
|
||||
set : function(newValue){
|
||||
this.setEnableContactGraph(newValue);
|
||||
},
|
||||
enumerable : true,
|
||||
configurable : true
|
||||
}
|
||||
});
|
||||
|
||||
// Body properties
|
||||
Object.defineProperties(cp.Body.prototype,
|
||||
{
|
||||
"a" : {
|
||||
get : function(){
|
||||
return this.getAngle();
|
||||
},
|
||||
set : function(newValue){
|
||||
this.setAngle(newValue);
|
||||
},
|
||||
enumerable : true,
|
||||
configurable : true
|
||||
},
|
||||
"w" : {
|
||||
get : function(){
|
||||
return this.getAngVel();
|
||||
},
|
||||
set : function(newValue){
|
||||
this.setAngVel(newValue);
|
||||
},
|
||||
enumerable : true,
|
||||
configurable : true
|
||||
},
|
||||
"p" : {
|
||||
get : function(){
|
||||
return this.getPos();
|
||||
},
|
||||
set : function(newValue){
|
||||
this.setPos(newValue);
|
||||
},
|
||||
enumerable : true,
|
||||
configurable : true
|
||||
},
|
||||
"v" : {
|
||||
get : function(){
|
||||
return this.getVel();
|
||||
},
|
||||
set : function(newValue){
|
||||
this.setVel(newValue);
|
||||
},
|
||||
enumerable : true,
|
||||
configurable : true
|
||||
},
|
||||
"i" : {
|
||||
get : function(){
|
||||
return this.getMoment();
|
||||
},
|
||||
set : function(newValue){
|
||||
this.setMoment(newValue);
|
||||
},
|
||||
enumerable : true,
|
||||
configurable : true
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
// Shape properties
|
||||
Object.defineProperties(cp.Shape.prototype,
|
||||
{
|
||||
"body" : {
|
||||
get : function(){
|
||||
return this.getBody();
|
||||
},
|
||||
set : function(newValue){
|
||||
this.setBody(newValue);
|
||||
},
|
||||
enumerable : true,
|
||||
configurable : true
|
||||
},
|
||||
"group" : {
|
||||
get : function(){
|
||||
return this.getGroup();
|
||||
},
|
||||
set : function(newValue){
|
||||
this.setGroup(newValue);
|
||||
},
|
||||
enumerable : true,
|
||||
configurable : true
|
||||
},
|
||||
"collision_type" : {
|
||||
get : function(){
|
||||
return this.getCollisionType();
|
||||
},
|
||||
enumerable : true,
|
||||
configurable : true
|
||||
}
|
||||
});
|
||||
|
||||
// Constraint properties
|
||||
Object.defineProperties(cp.Constraint.prototype,
|
||||
{
|
||||
"maxForce" : {
|
||||
get : function(){
|
||||
return this.getMaxForce();
|
||||
},
|
||||
set : function(newValue){
|
||||
this.setMaxForce(newValue);
|
||||
},
|
||||
enumerable : true,
|
||||
configurable : true
|
||||
}
|
||||
});
|
||||
|
||||
// PinJoint properties
|
||||
Object.defineProperties(cp.PinJoint.prototype,
|
||||
{
|
||||
"anchr1" : {
|
||||
get : function(){
|
||||
return this.getAnchr1();
|
||||
},
|
||||
set : function(newValue){
|
||||
this.setAnchr1(newValue);
|
||||
},
|
||||
enumerable : true,
|
||||
configurable : true
|
||||
},
|
||||
"anchr2" : {
|
||||
get : function(){
|
||||
return this.getAnchr2();
|
||||
},
|
||||
set : function(newValue){
|
||||
this.setAnchr2(newValue);
|
||||
},
|
||||
enumerable : true,
|
||||
configurable : true
|
||||
}
|
||||
});
|
|
@ -1,528 +0,0 @@
|
|||
//
|
||||
// cocos2d constants
|
||||
//
|
||||
|
||||
var cc = cc || {};
|
||||
|
||||
cc.DIRECTOR_PROJECTION_2D = 0;
|
||||
cc.DIRECTOR_PROJECTION_3D = 1;
|
||||
|
||||
cc.TEXTURE_PIXELFORMAT_RGBA8888 = 0;
|
||||
cc.TEXTURE_PIXELFORMAT_RGB888 = 1;
|
||||
cc.TEXTURE_PIXELFORMAT_RGB565 = 2;
|
||||
cc.TEXTURE_PIXELFORMAT_A8 = 3;
|
||||
cc.TEXTURE_PIXELFORMAT_I8 = 4;
|
||||
cc.TEXTURE_PIXELFORMAT_AI88 = 5;
|
||||
cc.TEXTURE_PIXELFORMAT_RGBA4444 = 6;
|
||||
cc.TEXTURE_PIXELFORMAT_RGB5A1 = 7;
|
||||
cc.TEXTURE_PIXELFORMAT_PVRTC4 = 8;
|
||||
cc.TEXTURE_PIXELFORMAT_PVRTC4 = 9;
|
||||
cc.TEXTURE_PIXELFORMAT_DEFAULT = cc.TEXTURE_PIXELFORMAT_RGBA8888;
|
||||
|
||||
cc.TEXT_ALIGNMENT_LEFT = 0;
|
||||
cc.TEXT_ALIGNMENT_CENTER = 1;
|
||||
cc.TEXT_ALIGNMENT_RIGHT = 2;
|
||||
|
||||
cc.VERTICAL_TEXT_ALIGNMENT_TOP = 0;
|
||||
cc.VERTICAL_TEXT_ALIGNMENT_CENTER = 1;
|
||||
cc.VERTICAL_TEXT_ALIGNMENT_BOTTOM = 2;
|
||||
|
||||
cc.IMAGE_FORMAT_JPEG = 0;
|
||||
cc.IMAGE_FORMAT_PNG = 0;
|
||||
|
||||
cc.PROGRESS_TIMER_TYPE_RADIAL = 0;
|
||||
cc.PROGRESS_TIMER_TYPE_BAR = 1;
|
||||
|
||||
cc.PARTICLE_TYPE_FREE = 0;
|
||||
cc.PARTICLE_TYPE_RELATIVE = 1;
|
||||
cc.PARTICLE_TYPE_GROUPED = 2;
|
||||
cc.PARTICLE_DURATION_INFINITY = -1;
|
||||
cc.PARTICLE_MODE_GRAVITY = 0;
|
||||
cc.PARTICLE_MODE_RADIUS = 1;
|
||||
cc.PARTICLE_START_SIZE_EQUAL_TO_END_SIZE = -1;
|
||||
cc.PARTICLE_START_RADIUS_EQUAL_TO_END_RADIUS = -1;
|
||||
|
||||
cc.TOUCH_ALL_AT_ONCE = 0;
|
||||
cc.TOUCH_ONE_BY_ONE = 1;
|
||||
|
||||
cc.TMX_TILE_HORIZONTAL_FLAG = 0x80000000;
|
||||
cc.TMX_TILE_VERTICAL_FLAG = 0x40000000;
|
||||
cc.TMX_TILE_DIAGONAL_FLAG = 0x20000000;
|
||||
|
||||
cc.TRANSITION_ORIENTATION_LEFT_OVER = 0;
|
||||
cc.TRANSITION_ORIENTATION_RIGHT_OVER = 1;
|
||||
cc.TRANSITION_ORIENTATION_UP_OVER = 0;
|
||||
cc.TRANSITION_ORIENTATION_DOWN_OVER = 1;
|
||||
|
||||
cc.RED = {r:255, g:0, b:0};
|
||||
cc.GREEN = {r:0, g:255, b:0};
|
||||
cc.BLUE = {r:0, g:0, b:255};
|
||||
cc.BLACK = {r:0, g:0, b:0};
|
||||
cc.WHITE = {r:255, g:255, b:255};
|
||||
|
||||
cc.POINT_ZERO = {x:0, y:0};
|
||||
|
||||
// XXX: This definition is different than cocos2d-html5
|
||||
// cc.REPEAT_FOREVER = - 1;
|
||||
// We can't assign -1 to cc.REPEAT_FOREVER, since it will be a very big double value after
|
||||
// converting it to double by JS_ValueToNumber on android.
|
||||
// Then cast it to unsigned int, the value will be 0. The schedule will not be able to work.
|
||||
// I don't know why this occurs only on android.
|
||||
// So instead of passing -1 to it, I assign it with max value of unsigned int in c++.
|
||||
cc.REPEAT_FOREVER = 0xffffffff;
|
||||
|
||||
cc.MENU_STATE_WAITING = 0;
|
||||
cc.MENU_STATE_TRACKING_TOUCH = 1;
|
||||
cc.MENU_HANDLER_PRIORITY = -128;
|
||||
cc.DEFAULT_PADDING = 5;
|
||||
|
||||
// reusable objects
|
||||
cc._reuse_p = [ {x:0, y:0}, {x:0,y:0}, {x:0,y:0}, {x:0,y:0} ];
|
||||
cc._reuse_p_index = 0;
|
||||
cc._reuse_size = {width:0, height:0};
|
||||
cc._reuse_rect = {x:0, y:0, width:0, height:0};
|
||||
cc._reuse_color3b = {r:255, g:255, b:255 };
|
||||
cc._reuse_color4b = {r:255, g:255, b:255, a:255 };
|
||||
cc.log = cc.log || log;
|
||||
|
||||
//
|
||||
// Color 3B
|
||||
//
|
||||
cc.c3b = function( r, g, b )
|
||||
{
|
||||
return {r:r, g:g, b:b };
|
||||
};
|
||||
cc._c3b = function( r, g, b )
|
||||
{
|
||||
cc._reuse_color3b.r = r;
|
||||
cc._reuse_color3b.g = g;
|
||||
cc._reuse_color3b.b = b;
|
||||
return cc._reuse_color3b;
|
||||
};
|
||||
|
||||
//
|
||||
// Color 4B
|
||||
//
|
||||
cc.c4b = function( r, g, b, a )
|
||||
{
|
||||
return {r:r, g:g, b:b, a:a };
|
||||
};
|
||||
cc._c4b = function( r, g, b, a )
|
||||
{
|
||||
cc._reuse_color4b.r = r;
|
||||
cc._reuse_color4b.g = g;
|
||||
cc._reuse_color4b.b = b;
|
||||
cc._reuse_color4b.a = a;
|
||||
return cc._reuse_color4b;
|
||||
};
|
||||
// compatibility
|
||||
cc.c4 = cc.c4b;
|
||||
cc._c4 = cc._c4b;
|
||||
|
||||
//
|
||||
// Color 4F
|
||||
//
|
||||
cc.c4f = function( r, g, b, a )
|
||||
{
|
||||
return {r:r, g:g, b:b, a:a };
|
||||
};
|
||||
|
||||
//
|
||||
// Point
|
||||
//
|
||||
cc.p = function( x, y )
|
||||
{
|
||||
return {x:x, y:y};
|
||||
};
|
||||
cc._p = function( x, y )
|
||||
{
|
||||
if( cc._reuse_p_index == cc._reuse_p.length )
|
||||
cc._reuse_p_index = 0;
|
||||
|
||||
var p = cc._reuse_p[ cc._reuse_p_index];
|
||||
cc._reuse_p_index++;
|
||||
p.x = x;
|
||||
p.y = y;
|
||||
return p;
|
||||
};
|
||||
|
||||
cc.pointEqualToPoint = function (point1, point2) {
|
||||
return ((point1.x == point2.x) && (point1.y == point2.y));
|
||||
};
|
||||
|
||||
//
|
||||
// Grid
|
||||
//
|
||||
cc._g = function( x, y )
|
||||
{
|
||||
cc._reuse_grid.x = x;
|
||||
cc._reuse_grid.y = y;
|
||||
return cc._reuse_grid;
|
||||
};
|
||||
|
||||
//
|
||||
// Size
|
||||
//
|
||||
cc.size = function(w,h)
|
||||
{
|
||||
return {width:w, height:h};
|
||||
};
|
||||
cc._size = function(w,h)
|
||||
{
|
||||
cc._reuse_size.width = w;
|
||||
cc._reuse_size.height = h;
|
||||
return cc._reuse_size;
|
||||
};
|
||||
cc.sizeEqualToSize = function (size1, size2)
|
||||
{
|
||||
return ((size1.width == size2.width) && (size1.height == size2.height));
|
||||
};
|
||||
|
||||
//
|
||||
// Rect
|
||||
//
|
||||
cc.rect = function(x,y,w,h)
|
||||
{
|
||||
return {x:x, y:y, width:w, height:h};
|
||||
};
|
||||
cc._rect = function(x,y,w,h)
|
||||
{
|
||||
cc._reuse_rect.x = x;
|
||||
cc._reuse_rect.y = y;
|
||||
cc._reuse_rect.width = w;
|
||||
cc._reuse_rect.height = h;
|
||||
return cc._reuse_rect;
|
||||
};
|
||||
cc.rectEqualToRect = function (rect1, rect2) {
|
||||
return ( rect1.x==rect2.x && rect1.y==rect2.y && rect1.width==rect2.width && rect1.height==rect2.height);
|
||||
};
|
||||
|
||||
cc.rectContainsRect = function (rect1, rect2) {
|
||||
if ((rect1.x >= rect2.x) || (rect1.y >= rect2.y) ||
|
||||
( rect1.x + rect1.width <= rect2.x + rect2.width) ||
|
||||
( rect1.y + rect1.height <= rect2.y + rect2.height))
|
||||
return false;
|
||||
return true;
|
||||
};
|
||||
|
||||
cc.rectGetMaxX = function (rect) {
|
||||
return (rect.x + rect.width);
|
||||
};
|
||||
|
||||
cc.rectGetMidX = function (rect) {
|
||||
return (rect.x + rect.width / 2.0);
|
||||
};
|
||||
|
||||
cc.rectGetMinX = function (rect) {
|
||||
return rect.x;
|
||||
};
|
||||
|
||||
cc.rectGetMaxY = function (rect) {
|
||||
return(rect.y + rect.height);
|
||||
};
|
||||
|
||||
cc.rectGetMidY = function (rect) {
|
||||
return rect.y + rect.height / 2.0;
|
||||
};
|
||||
|
||||
cc.rectGetMinY = function (rect) {
|
||||
return rect.y;
|
||||
};
|
||||
|
||||
cc.rectContainsPoint = function (rect, point) {
|
||||
var ret = false;
|
||||
if (point.x >= rect.x && point.x <= rect.x + rect.width &&
|
||||
point.y >= rect.y && point.y <= rect.y + rect.height) {
|
||||
ret = true;
|
||||
}
|
||||
return ret;
|
||||
};
|
||||
|
||||
cc.rectIntersectsRect = function( rectA, rectB )
|
||||
{
|
||||
var bool = ! ( rectA.x > rectB.x + rectB.width ||
|
||||
rectA.x + rectA.width < rectB.x ||
|
||||
rectA.y > rectB.y +rectB.height ||
|
||||
rectA.y + rectA.height < rectB.y );
|
||||
|
||||
return bool;
|
||||
};
|
||||
|
||||
cc.rectUnion = function (rectA, rectB) {
|
||||
var rect = cc.rect(0, 0, 0, 0);
|
||||
rect.x = Math.min(rectA.x, rectB.x);
|
||||
rect.y = Math.min(rectA.y, rectB.y);
|
||||
rect.width = Math.max(rectA.x + rectA.width, rectB.x + rectB.width) - rect.x;
|
||||
rect.height = Math.max(rectA.y + rectA.height, rectB.y + rectB.height) - rect.y;
|
||||
return rect;
|
||||
};
|
||||
|
||||
cc.rectIntersection = function (rectA, rectB) {
|
||||
var intersection = cc.rect(
|
||||
Math.max(rectA.x, rectB.x),
|
||||
Math.max(rectA.y, rectB.y),
|
||||
0, 0);
|
||||
|
||||
intersection.width = Math.min(rectA.x+rectA.width, rectB.x+rectB.width) - intersection.x;
|
||||
intersection.height = Math.min(rectA.y+rectA.height, rectB.y+rectB.height) - intersection.y;
|
||||
return intersection;
|
||||
};
|
||||
|
||||
//
|
||||
// Array: for cocos2d-html5 compatibility
|
||||
//
|
||||
|
||||
/**
|
||||
* Returns index of first occurence of object, -1 if value not found.
|
||||
* @function
|
||||
* @param {Array} arr Source Array
|
||||
* @param {*} findObj find object
|
||||
* @return {Number} index of first occurence of value
|
||||
*/
|
||||
cc.ArrayGetIndexOfObject = function (arr, findObj) {
|
||||
for (var i = 0; i < arr.length; i++) {
|
||||
if (arr[i] == findObj)
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns a Boolean value that indicates whether value is present in the array.
|
||||
* @function
|
||||
* @param {Array} arr
|
||||
* @param {*} findObj
|
||||
* @return {Boolean}
|
||||
*/
|
||||
cc.ArrayContainsObject = function (arr, findObj) {
|
||||
return cc.ArrayGetIndexOfObject(arr, findObj) != -1;
|
||||
};
|
||||
|
||||
cc.ArrayRemoveObject = function (arr, delObj) {
|
||||
for (var i = 0; i < arr.length; i++) {
|
||||
if (arr[i] == delObj) {
|
||||
arr.splice(i, 1);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// Helpers
|
||||
//
|
||||
cc.dump = function(obj)
|
||||
{
|
||||
for( var i in obj )
|
||||
cc.log( i + " = " + obj[i] );
|
||||
};
|
||||
|
||||
// dump config info, but only in debug mode
|
||||
cc.dumpConfig = function()
|
||||
{
|
||||
cc.dump(sys);
|
||||
cc.dump(sys.capabilities);
|
||||
};
|
||||
|
||||
//
|
||||
// Bindings Overrides
|
||||
//
|
||||
// MenuItemToggle
|
||||
cc.MenuItemToggle.create = function( /* var args */) {
|
||||
|
||||
var n = arguments.length;
|
||||
|
||||
if (typeof arguments[n-2] === 'function' || typeof arguments[n-1] === 'function') {
|
||||
var args = Array.prototype.slice.call(arguments);
|
||||
var obj = null;
|
||||
if( typeof arguments[n-2] === 'function' )
|
||||
obj = args.pop();
|
||||
|
||||
var func = args.pop();
|
||||
|
||||
// create it with arguments,
|
||||
var item = cc.MenuItemToggle._create.apply(this, args);
|
||||
|
||||
// then set the callback
|
||||
if( obj !== null )
|
||||
item.setCallback(func, obj);
|
||||
else
|
||||
item.setCallback(func);
|
||||
return item;
|
||||
} else {
|
||||
return cc.MenuItemToggle._create.apply(this, arguments);
|
||||
}
|
||||
};
|
||||
|
||||
// LabelAtlas
|
||||
cc.LabelAtlas.create = function( a,b,c,d,e ) {
|
||||
|
||||
var n = arguments.length;
|
||||
|
||||
if ( n == 5) {
|
||||
return cc.LabelAtlas._create(a,b,c,d,e.charCodeAt(0));
|
||||
} else {
|
||||
return cc.LabelAtlas._create.apply(this, arguments);
|
||||
}
|
||||
};
|
||||
|
||||
cc.LayerMultiplex.create = cc.LayerMultiplex.createWithArray;
|
||||
|
||||
// PhysicsDebugNode
|
||||
cc.PhysicsDebugNode.create = function( space ) {
|
||||
var s = space;
|
||||
if( space.handle !== undefined )
|
||||
s = space.handle;
|
||||
return cc.PhysicsDebugNode._create( s );
|
||||
};
|
||||
cc.PhysicsDebugNode.prototype.setSpace = function( space ) {
|
||||
var s = space;
|
||||
if( space.handle !== undefined )
|
||||
s = space.handle;
|
||||
return this._setSpace( s );
|
||||
};
|
||||
|
||||
// PhysicsSprite
|
||||
cc.PhysicsSprite.prototype.setBody = function( body ) {
|
||||
var b = body;
|
||||
if( body.handle !== undefined )
|
||||
b = body.handle;
|
||||
return this._setCPBody( b );
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Associates a base class with a native superclass
|
||||
* @function
|
||||
* @param {object} jsobj subclass
|
||||
* @param {object} klass superclass
|
||||
*/
|
||||
cc.associateWithNative = function( jsobj, superclass_or_instance ) {
|
||||
|
||||
try {
|
||||
// Used when subclassing using the "extend" method
|
||||
var native = new superclass_or_instance();
|
||||
__associateObjWithNative( jsobj, native );
|
||||
} catch(err) {
|
||||
// Used when subclassing using the goog.inherits method
|
||||
__associateObjWithNative( jsobj, superclass_or_instance );
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// JSB supports 2 official ways to create subclasses
|
||||
//
|
||||
// 1) Google "subclasses" borrowed from closure library
|
||||
// This is the recommended way to do it
|
||||
//
|
||||
cc.inherits = function (childCtor, parentCtor) {
|
||||
/** @constructor */
|
||||
function tempCtor() {};
|
||||
tempCtor.prototype = parentCtor.prototype;
|
||||
childCtor.superClass_ = parentCtor.prototype;
|
||||
childCtor.prototype = new tempCtor();
|
||||
childCtor.prototype.constructor = childCtor;
|
||||
|
||||
// Copy "static" method, but doesn't generate subclasses.
|
||||
// for( var i in parentCtor ) {
|
||||
// childCtor[ i ] = parentCtor[ i ];
|
||||
// }
|
||||
};
|
||||
cc.base = function(me, opt_methodName, var_args) {
|
||||
var caller = arguments.callee.caller;
|
||||
if (caller.superClass_) {
|
||||
// This is a constructor. Call the superclass constructor.
|
||||
ret = caller.superClass_.constructor.apply( me, Array.prototype.slice.call(arguments, 1));
|
||||
return ret;
|
||||
}
|
||||
|
||||
var args = Array.prototype.slice.call(arguments, 2);
|
||||
var foundCaller = false;
|
||||
for (var ctor = me.constructor;
|
||||
ctor; ctor = ctor.superClass_ && ctor.superClass_.constructor) {
|
||||
if (ctor.prototype[opt_methodName] === caller) {
|
||||
foundCaller = true;
|
||||
} else if (foundCaller) {
|
||||
return ctor.prototype[opt_methodName].apply(me, args);
|
||||
}
|
||||
}
|
||||
|
||||
// If we did not find the caller in the prototype chain,
|
||||
// then one of two things happened:
|
||||
// 1) The caller is an instance method.
|
||||
// 2) This method was not called by the right caller.
|
||||
if (me[opt_methodName] === caller) {
|
||||
return me.constructor.prototype[opt_methodName].apply(me, args);
|
||||
} else {
|
||||
throw Error(
|
||||
'cc.base called from a method of one name ' +
|
||||
'to a method of a different name');
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// 2) Using "extend" subclassing
|
||||
// Simple JavaScript Inheritance By John Resig http://ejohn.org/
|
||||
//
|
||||
cc.Class = function(){};
|
||||
cc.Class.extend = function (prop) {
|
||||
var _super = this.prototype;
|
||||
|
||||
// Instantiate a base class (but only create the instance,
|
||||
// don't run the init constructor)
|
||||
initializing = true;
|
||||
var prototype = new this();
|
||||
initializing = false;
|
||||
fnTest = /xyz/.test(function(){xyz;}) ? /\b_super\b/ : /.*/;
|
||||
|
||||
// Copy the properties over onto the new prototype
|
||||
for (var name in prop) {
|
||||
// Check if we're overwriting an existing function
|
||||
prototype[name] = typeof prop[name] == "function" &&
|
||||
typeof _super[name] == "function" && fnTest.test(prop[name]) ?
|
||||
(function (name, fn) {
|
||||
return function () {
|
||||
var tmp = this._super;
|
||||
|
||||
// Add a new ._super() method that is the same method
|
||||
// but on the super-class
|
||||
this._super = _super[name];
|
||||
|
||||
// The method only need to be bound temporarily, so we
|
||||
// remove it when we're done executing
|
||||
var ret = fn.apply(this, arguments);
|
||||
this._super = tmp;
|
||||
|
||||
return ret;
|
||||
};
|
||||
})(name, prop[name]) :
|
||||
prop[name];
|
||||
}
|
||||
|
||||
// The dummy class constructor
|
||||
function Class() {
|
||||
// All construction is actually done in the init method
|
||||
if (!initializing && this.ctor)
|
||||
this.ctor.apply(this, arguments);
|
||||
}
|
||||
|
||||
// Populate our constructed prototype object
|
||||
Class.prototype = prototype;
|
||||
|
||||
// Enforce the constructor to be what we expect
|
||||
Class.prototype.constructor = Class;
|
||||
|
||||
// And make this class extendable
|
||||
Class.extend = arguments.callee;
|
||||
|
||||
return Class;
|
||||
};
|
||||
|
||||
cc.Node.prototype.ctor = function() {};
|
||||
cc.Node.extend = cc.Class.extend;
|
||||
cc.Layer.extend = cc.Class.extend;
|
||||
cc.LayerGradient.extend = cc.Class.extend;
|
||||
cc.LayerColor.extend = cc.Class.extend;
|
||||
cc.Sprite.extend = cc.Class.extend;
|
||||
cc.MenuItemFont.extend = cc.Class.extend;
|
||||
cc.Scene.extend = cc.Class.extend;
|
||||
cc.DrawNode.extend = cc.Class.extend;
|
|
@ -1,125 +0,0 @@
|
|||
//
|
||||
// CocosBuilder definitions
|
||||
//
|
||||
|
||||
cc.BuilderReader = cc.BuilderReader || {};
|
||||
cc.BuilderReader._resourcePath = "";
|
||||
|
||||
var _ccbGlobalContext = this;
|
||||
|
||||
cc.BuilderReader.setResourcePath = function (rootPath) {
|
||||
cc.BuilderReader._resourcePath = rootPath;
|
||||
};
|
||||
|
||||
cc.BuilderReader.load = function(file, owner, parentSize)
|
||||
{
|
||||
// Load the node graph using the correct function
|
||||
var reader = cc._Reader.create();
|
||||
reader.setCCBRootPath(cc.BuilderReader._resourcePath);
|
||||
|
||||
var node;
|
||||
|
||||
if (owner && parentSize)
|
||||
{
|
||||
node = reader.load(file, owner, parentSize);
|
||||
}
|
||||
else if (owner)
|
||||
{
|
||||
node = reader.load(file,owner);
|
||||
}
|
||||
else
|
||||
{
|
||||
node = reader.load(file);
|
||||
}
|
||||
|
||||
// Assign owner callbacks & member variables
|
||||
if (owner)
|
||||
{
|
||||
// Callbacks
|
||||
var ownerCallbackNames = reader.getOwnerCallbackNames();
|
||||
var ownerCallbackNodes = reader.getOwnerCallbackNodes();
|
||||
|
||||
for (var i = 0; i < ownerCallbackNames.length; i++)
|
||||
{
|
||||
var callbackName = ownerCallbackNames[i];
|
||||
var callbackNode = ownerCallbackNodes[i];
|
||||
|
||||
callbackNode.setCallback(owner[callbackName], owner);
|
||||
}
|
||||
|
||||
// Variables
|
||||
var ownerOutletNames = reader.getOwnerOutletNames();
|
||||
var ownerOutletNodes = reader.getOwnerOutletNodes();
|
||||
|
||||
for (var i = 0; i < ownerOutletNames.length; i++)
|
||||
{
|
||||
var outletName = ownerOutletNames[i];
|
||||
var outletNode = ownerOutletNodes[i];
|
||||
|
||||
owner[outletName] = outletNode;
|
||||
}
|
||||
}
|
||||
|
||||
var nodesWithAnimationManagers = reader.getNodesWithAnimationManagers();
|
||||
var animationManagersForNodes = reader.getAnimationManagersForNodes();
|
||||
|
||||
// Attach animation managers to nodes and assign root node callbacks and member variables
|
||||
for (var i = 0; i < nodesWithAnimationManagers.length; i++)
|
||||
{
|
||||
var innerNode = nodesWithAnimationManagers[i];
|
||||
var animationManager = animationManagersForNodes[i];
|
||||
|
||||
innerNode.animationManager = animationManager;
|
||||
|
||||
var documentControllerName = animationManager.getDocumentControllerName();
|
||||
if (!documentControllerName) continue;
|
||||
|
||||
// Create a document controller
|
||||
var controller = new _ccbGlobalContext[documentControllerName]();
|
||||
controller.controllerName = documentControllerName;
|
||||
|
||||
innerNode.controller = controller;
|
||||
controller.rootNode = innerNode;
|
||||
|
||||
// Callbacks
|
||||
var documentCallbackNames = animationManager.getDocumentCallbackNames();
|
||||
var documentCallbackNodes = animationManager.getDocumentCallbackNodes();
|
||||
|
||||
for (var j = 0; j < documentCallbackNames.length; j++)
|
||||
{
|
||||
var callbackName = documentCallbackNames[j];
|
||||
var callbackNode = documentCallbackNodes[j];
|
||||
|
||||
callbackNode.setCallback(controller[callbackName], controller);
|
||||
}
|
||||
|
||||
|
||||
// Variables
|
||||
var documentOutletNames = animationManager.getDocumentOutletNames();
|
||||
var documentOutletNodes = animationManager.getDocumentOutletNodes();
|
||||
|
||||
for (var j = 0; j < documentOutletNames.length; j++)
|
||||
{
|
||||
var outletName = documentOutletNames[j];
|
||||
var outletNode = documentOutletNodes[j];
|
||||
|
||||
controller[outletName] = outletNode;
|
||||
}
|
||||
|
||||
if (typeof(controller.onDidLoadFromCCB) == "function")
|
||||
{
|
||||
controller.onDidLoadFromCCB();
|
||||
}
|
||||
}
|
||||
|
||||
return node;
|
||||
};
|
||||
|
||||
cc.BuilderReader.loadAsScene = function(file, owner, parentSize)
|
||||
{
|
||||
var node = cc.BuilderReader.load(file, owner, parentSize);
|
||||
var scene = cc.Scene.create();
|
||||
scene.addChild( node );
|
||||
|
||||
return scene;
|
||||
};
|
|
@ -1,191 +0,0 @@
|
|||
dbg = {};
|
||||
|
||||
// fallback for no cc
|
||||
cc = {};
|
||||
cc.log = log;
|
||||
|
||||
var breakpointHandler = {
|
||||
hit: function (frame) {
|
||||
var script = frame.script;
|
||||
_lockVM(frame, frame.script);
|
||||
}
|
||||
};
|
||||
|
||||
var stepFunction = function (frame, script) {
|
||||
if (dbg.breakLine > 0) {
|
||||
var curLine = script.getOffsetLine(frame.offset);
|
||||
if (curLine < dbg.breakLine) {
|
||||
return;
|
||||
} else {
|
||||
_lockVM(frame, script);
|
||||
// dbg.breakLine = 0;
|
||||
// frame.onStep = undefined;
|
||||
}
|
||||
} else {
|
||||
cc.log("invalid state onStep");
|
||||
}
|
||||
};
|
||||
|
||||
dbg.breakLine = 0;
|
||||
|
||||
var processInput = function (str, frame, script) {
|
||||
str = str.replace(/\n$/, "");
|
||||
if (str.length === 0) {
|
||||
return;
|
||||
}
|
||||
var md = str.match(/^b(reak)?\s+([^:]+):(\d+)/);
|
||||
if (md) {
|
||||
var scripts = dbg.scripts[md[2]],
|
||||
tmpScript = null;
|
||||
if (scripts) {
|
||||
var breakLine = parseInt(md[3], 10),
|
||||
off = -1;
|
||||
for (var n=0; n < scripts.length; n++) {
|
||||
offsets = scripts[n].getLineOffsets(breakLine);
|
||||
if (offsets.length > 0) {
|
||||
off = offsets[0];
|
||||
tmpScript = scripts[n];
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (off >= 0) {
|
||||
tmpScript.setBreakpoint(off, breakpointHandler);
|
||||
_bufferWrite("breakpoint set for line " + breakLine + " of script " + md[2] + "\n");
|
||||
} else {
|
||||
_bufferWrite("no valid offsets at that line\n");
|
||||
}
|
||||
} else {
|
||||
_bufferWrite("no script named: " + md[2] + "\n");
|
||||
}
|
||||
return;
|
||||
}
|
||||
md = str.match(/^scripts/);
|
||||
if (md) {
|
||||
cc.log("sending list of available scripts");
|
||||
_bufferWrite("scripts:\n" + Object.keys(dbg.scripts).join("\n") + "\n");
|
||||
return;
|
||||
}
|
||||
md = str.match(/^s(tep)?/);
|
||||
if (md && frame) {
|
||||
cc.log("will step");
|
||||
dbg.breakLine = script.getOffsetLine(frame.offset) + 1;
|
||||
frame.onStep = function () {
|
||||
stepFunction(frame, frame.script);
|
||||
return undefined;
|
||||
};
|
||||
stop = true;
|
||||
_unlockVM();
|
||||
return;
|
||||
}
|
||||
md = str.match(/^c(ontinue)?/);
|
||||
if (md) {
|
||||
if (frame) {
|
||||
frame.onStep = undefined;
|
||||
dbg.breakLine = 0;
|
||||
}
|
||||
stop = true;
|
||||
_unlockVM();
|
||||
return;
|
||||
}
|
||||
md = str.match(/^eval\s+(.+)/);
|
||||
if (md && frame) {
|
||||
var res = frame['eval'](md[1]),
|
||||
k;
|
||||
if (res['return']) {
|
||||
var r = res['return'];
|
||||
_bufferWrite("* " + (typeof r) + "\n");
|
||||
if (typeof r != "object") {
|
||||
_bufferWrite("~> " + r + "\n");
|
||||
} else {
|
||||
var props = r.getOwnPropertyNames();
|
||||
for (k in props) {
|
||||
var desc = r.getOwnPropertyDescriptor(props[k]);
|
||||
_bufferWrite("~> " + props[k] + " = ");
|
||||
if (desc.value) {
|
||||
_bufferWrite("" + desc.value);
|
||||
} else if (desc.get) {
|
||||
_bufferWrite("" + desc.get());
|
||||
} else {
|
||||
_bufferWrite("undefined (no value or getter)");
|
||||
}
|
||||
_bufferWrite("\n");
|
||||
}
|
||||
}
|
||||
} else if (res['throw']) {
|
||||
_bufferWrite("!! got exception: " + res['throw'].message + "\n");
|
||||
}
|
||||
return;
|
||||
} else if (md) {
|
||||
_bufferWrite("!! no frame to eval in\n");
|
||||
return;
|
||||
}
|
||||
md = str.match(/^line/);
|
||||
if (md && frame) {
|
||||
_bufferWrite("current line: " + script.getOffsetLine(frame.offset) + "\n");
|
||||
return;
|
||||
} else if (md) {
|
||||
_bufferWrite("no line, probably entering script\n");
|
||||
return;
|
||||
}
|
||||
md = str.match(/^bt/);
|
||||
if (md && frame) {
|
||||
var cur = frame,
|
||||
stack = [cur.script.url + ":" + cur.script.getOffsetLine(cur.offset)];
|
||||
while ((cur = cur.older)) {
|
||||
stack.push(cur.script.url + ":" + cur.script.getOffsetLine(cur.offset));
|
||||
}
|
||||
_bufferWrite(stack.join("\n") + "\n");
|
||||
return;
|
||||
} else if (md) {
|
||||
_bufferWrite("no valid frame\n");
|
||||
return;
|
||||
}
|
||||
_bufferWrite("! invalid command: \"" + str + "\"\n");
|
||||
};
|
||||
|
||||
dbg.scripts = [];
|
||||
|
||||
dbg.onNewScript = function (script) {
|
||||
// skip if the url is this script
|
||||
var last = script.url.split("/").pop();
|
||||
|
||||
var children = script.getChildScripts(),
|
||||
arr = [script].concat(children);
|
||||
/**
|
||||
* just dumping all the offsets from the scripts
|
||||
for (var i in arr) {
|
||||
cc.log("script: " + arr[i].url);
|
||||
for (var start=arr[i].startLine, j=start; j < start+arr[i].lineCount; j++) {
|
||||
var offsets = arr[i].getLineOffsets(j);
|
||||
cc.log(" off: " + offsets.join(",") + "; line: " + j);
|
||||
}
|
||||
}
|
||||
*/
|
||||
dbg.scripts[last] = arr;
|
||||
};
|
||||
|
||||
dbg.onError = function (frame, report) {
|
||||
if (dbg.socket && report) {
|
||||
_socketWrite(dbg.socket, "!! exception @ " + report.file + ":" + report.line);
|
||||
}
|
||||
cc.log("!! exception");
|
||||
};
|
||||
|
||||
function _prepareDebugger(global) {
|
||||
var tmp = new Debugger(global);
|
||||
tmp.onNewScript = dbg.onNewScript;
|
||||
tmp.onDebuggerStatement = dbg.onDebuggerStatement;
|
||||
tmp.onError = dbg.onError;
|
||||
dbg.dbg = tmp;
|
||||
}
|
||||
|
||||
function _startDebugger(global, files, startFunc) {
|
||||
cc.log("starting with debugger enabled");
|
||||
for (var i in files) {
|
||||
global['eval']("require('" + files[i] + "');");
|
||||
}
|
||||
if (startFunc) {
|
||||
global['eval'](startFunc);
|
||||
}
|
||||
// beginDebug();
|
||||
}
|
|
@ -1,24 +0,0 @@
|
|||
//
|
||||
// OpenGL defines
|
||||
//
|
||||
|
||||
var gl = gl || {};
|
||||
|
||||
gl.NEAREST = 0x2600;
|
||||
gl.LINEAR = 0x2601;
|
||||
gl.REPEAT = 0x2901;
|
||||
gl.CLAMP_TO_EDGE = 0x812F;
|
||||
gl.CLAMP_TO_BORDER = 0x812D;
|
||||
gl.LINEAR_MIPMAP_NEAREST = 0x2701;
|
||||
gl.NEAREST_MIPMAP_NEAREST = 0x2700;
|
||||
gl.ZERO = 0;
|
||||
gl.ONE = 1;
|
||||
gl.SRC_COLOR = 0x0300;
|
||||
gl.ONE_MINUS_SRC_COLOR = 0x0301;
|
||||
gl.SRC_ALPHA = 0x0302;
|
||||
gl.ONE_MINUS_SRC_ALPHA = 0x0303;
|
||||
gl.DST_ALPHA = 0x0304;
|
||||
gl.ONE_MINUS_DST_ALPHA = 0x0305;
|
||||
gl.DST_COLOR = 0x0306;
|
||||
gl.ONE_MINUS_DST_COLOR = 0x0307;
|
||||
gl.SRC_ALPHA_SATURATE = 0x0308;
|
|
@ -1,47 +0,0 @@
|
|||
//
|
||||
// sys properties
|
||||
//
|
||||
|
||||
var sys = sys || {};
|
||||
|
||||
Object.defineProperties(sys,
|
||||
{
|
||||
"capabilities" : {
|
||||
get : function(){
|
||||
var capabilities = {"opengl":true};
|
||||
if( sys.platform == 'mobile' ) {
|
||||
capabilities["accelerometer"] = true;
|
||||
capabilities["touches"] = true;
|
||||
} else {
|
||||
// desktop
|
||||
capabilities["keyboard"] = true;
|
||||
capabilities["mouse"] = true;
|
||||
}
|
||||
return capabilities;
|
||||
},
|
||||
enumerable : true,
|
||||
configurable : true
|
||||
},
|
||||
"os" : {
|
||||
get : function(){
|
||||
return __getOS();
|
||||
},
|
||||
enumerable : true,
|
||||
configurable : true
|
||||
},
|
||||
"platform" : {
|
||||
get : function(){
|
||||
return __getPlatform();
|
||||
},
|
||||
enumerable : true,
|
||||
configurable : true
|
||||
},
|
||||
"version" : {
|
||||
get : function(){
|
||||
return __getVersion();
|
||||
},
|
||||
enumerable : true,
|
||||
configurable : true
|
||||
}
|
||||
|
||||
});
|
Binary file not shown.
|
@ -1,59 +0,0 @@
|
|||
#include "cocos2d.h"
|
||||
#include "AppDelegate.h"
|
||||
#include "SimpleAudioEngine.h"
|
||||
#include "script_support/CCScriptSupport.h"
|
||||
#include "CCLuaEngine.h"
|
||||
|
||||
USING_NS_CC;
|
||||
using namespace CocosDenshion;
|
||||
|
||||
AppDelegate::AppDelegate()
|
||||
{
|
||||
// fixed me
|
||||
//_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF|_CRTDBG_LEAK_CHECK_DF);
|
||||
}
|
||||
|
||||
AppDelegate::~AppDelegate()
|
||||
{
|
||||
// end simple audio engine here, or it may crashed on win32
|
||||
SimpleAudioEngine::sharedEngine()->end();
|
||||
//CCScriptEngineManager::destroyInstance();
|
||||
}
|
||||
|
||||
bool AppDelegate::applicationDidFinishLaunching()
|
||||
{
|
||||
// initialize director
|
||||
Director *pDirector = Director::getInstance();
|
||||
pDirector->setOpenGLView(EGLView::getInstance());
|
||||
|
||||
// turn on display FPS
|
||||
pDirector->setDisplayStats(true);
|
||||
|
||||
// set FPS. the default value is 1.0/60 if you don't call this
|
||||
pDirector->setAnimationInterval(1.0 / 60);
|
||||
|
||||
// register lua engine
|
||||
LuaEngine* pEngine = LuaEngine::defaultEngine();
|
||||
ScriptEngineManager::getInstance()->setScriptEngine(pEngine);
|
||||
|
||||
std::string path = FileUtils::getInstance()->fullPathForFilename("hello.lua");
|
||||
pEngine->executeScriptFile(path.c_str());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// This function will be called when the app is inactive. When comes a phone call,it's be invoked too
|
||||
void AppDelegate::applicationDidEnterBackground()
|
||||
{
|
||||
Director::getInstance()->stopAnimation();
|
||||
SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic();
|
||||
SimpleAudioEngine::sharedEngine()->pauseAllEffects();
|
||||
}
|
||||
|
||||
// this function will be called when the app is active again
|
||||
void AppDelegate::applicationWillEnterForeground()
|
||||
{
|
||||
Director::getInstance()->startAnimation();
|
||||
SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic();
|
||||
SimpleAudioEngine::sharedEngine()->resumeAllEffects();
|
||||
}
|
|
@ -1,38 +0,0 @@
|
|||
#ifndef _APP_DELEGATE_H_
|
||||
#define _APP_DELEGATE_H_
|
||||
|
||||
#include "CCApplication.h"
|
||||
|
||||
/**
|
||||
@brief The cocos2d Application.
|
||||
|
||||
The reason for implement as private inheritance is to hide some interface call by Director.
|
||||
*/
|
||||
class AppDelegate : private cocos2d::Application
|
||||
{
|
||||
public:
|
||||
AppDelegate();
|
||||
virtual ~AppDelegate();
|
||||
|
||||
/**
|
||||
@brief Implement Director and Scene init code here.
|
||||
@return true Initialize success, app continue.
|
||||
@return false Initialize failed, app terminate.
|
||||
*/
|
||||
virtual bool applicationDidFinishLaunching();
|
||||
|
||||
/**
|
||||
@brief The function be called when the application enter background
|
||||
@param the pointer of the application
|
||||
*/
|
||||
virtual void applicationDidEnterBackground();
|
||||
|
||||
/**
|
||||
@brief The function be called when the application enter foreground
|
||||
@param the pointer of the application
|
||||
*/
|
||||
virtual void applicationWillEnterForeground();
|
||||
};
|
||||
|
||||
#endif // _APP_DELEGATE_H_
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
//
|
||||
// Prefix header for all source files of the '___PROJECTNAME___' target in the '___PROJECTNAME___' project
|
||||
//
|
||||
|
||||
#ifdef __OBJC__
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <UIKit/UIKit.h>
|
||||
#endif
|
|
@ -1 +0,0 @@
|
|||
aec1c0a8c8068377fddca5ddd32084d8c3c3c419
|
|
@ -1 +0,0 @@
|
|||
d7290c34702d1c6bdb368acb060d93b42d5deff8
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue