mirror of https://github.com/axmolengine/axmol.git
Merge branch 'gles20' of https://github.com/cocos2d/cocos2d-x into iss1470_cocosbuilder
This commit is contained in:
commit
8cdf73640b
|
@ -74,3 +74,7 @@ Device-Release/
|
|||
|
||||
# Ignore vim swaps
|
||||
*.swp
|
||||
|
||||
# Ignore config files in javascript bindings generator
|
||||
tools/tojs/user.cfg
|
||||
tools/tojs/userconf.ini
|
||||
|
|
|
@ -1,57 +0,0 @@
|
|||
#include "AppDelegate.h"
|
||||
|
||||
#include "cocos2d.h"
|
||||
#include "HelloWorldScene.h"
|
||||
|
||||
USING_NS_CC;
|
||||
|
||||
AppDelegate::AppDelegate()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
AppDelegate::~AppDelegate()
|
||||
{
|
||||
}
|
||||
|
||||
bool AppDelegate::applicationDidFinishLaunching()
|
||||
{
|
||||
// initialize director
|
||||
CCDirector *pDirector = CCDirector::sharedDirector();
|
||||
pDirector->setOpenGLView(CCEGLView::sharedOpenGLView());
|
||||
|
||||
// enable High Resource Mode(2x, such as iphone4) and maintains low resource on other devices.
|
||||
// pDirector->enableRetinaDisplay(true);
|
||||
|
||||
// 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
|
||||
CCScene *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()
|
||||
{
|
||||
CCDirector::sharedDirector()->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()
|
||||
{
|
||||
CCDirector::sharedDirector()->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 CCDirector.
|
||||
*/
|
||||
class AppDelegate : private cocos2d::CCApplication
|
||||
{
|
||||
public:
|
||||
AppDelegate();
|
||||
virtual ~AppDelegate();
|
||||
|
||||
/**
|
||||
@brief Implement CCDirector and CCScene 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;
|
||||
|
||||
CCScene* HelloWorld::scene()
|
||||
{
|
||||
// 'scene' is an autorelease object
|
||||
CCScene *scene = CCScene::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 ( !CCLayer::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
|
||||
CCMenuItemImage *pCloseItem = CCMenuItemImage::create(
|
||||
"CloseNormal.png",
|
||||
"CloseSelected.png",
|
||||
this,
|
||||
menu_selector(HelloWorld::menuCloseCallback) );
|
||||
pCloseItem->setPosition( ccp(CCDirector::sharedDirector()->getWinSize().width - 20, 20) );
|
||||
|
||||
// create menu, it's an autorelease object
|
||||
CCMenu* pMenu = CCMenu::create(pCloseItem, NULL);
|
||||
pMenu->setPosition( CCPointZero );
|
||||
this->addChild(pMenu, 1);
|
||||
|
||||
/////////////////////////////
|
||||
// 3. add your codes below...
|
||||
|
||||
// add a label shows "Hello World"
|
||||
// create and initialize a label
|
||||
CCLabelTTF* pLabel = CCLabelTTF::create("Hello World", "Thonburi", 34);
|
||||
|
||||
// ask director the window size
|
||||
CCSize size = CCDirector::sharedDirector()->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"
|
||||
CCSprite* pSprite = CCSprite::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(CCObject* pSender)
|
||||
{
|
||||
CCDirector::sharedDirector()->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::CCLayer
|
||||
{
|
||||
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::CCScene* scene();
|
||||
|
||||
// a selector callback
|
||||
void menuCloseCallback(CCObject* pSender);
|
||||
|
||||
// implement the "static node()" method manually
|
||||
CREATE_FUNC(HelloWorld);
|
||||
};
|
||||
|
||||
#endif // __HELLOWORLD_SCENE_H__
|
|
@ -1 +0,0 @@
|
|||
5fe89fb5bd58cedf13b0363f97b20e3ea7ff255d
|
|
@ -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,33 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>SimpleGame</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>com.android.ide.eclipse.adt.ApkBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
|
@ -1,28 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="org.cocos2dx.simplegame"
|
||||
android:versionCode="1"
|
||||
android:versionName="1.0">
|
||||
|
||||
<uses-sdk android:minSdkVersion="8"/>
|
||||
|
||||
<application android:label="@string/app_name"
|
||||
android:debuggable="true"
|
||||
android:icon="@drawable/icon">
|
||||
|
||||
<activity android:name=".SimpleGame"
|
||||
android:label="@string/app_name"
|
||||
android:screenOrientation="landscape"
|
||||
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
|
||||
android:configChanges="orientation">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
</application>
|
||||
<supports-screens android:largeScreens="true"
|
||||
android:smallScreens="true"
|
||||
android:anyDensity="true"
|
||||
android:normalScreens="true"/>
|
||||
</manifest>
|
|
@ -1,17 +0,0 @@
|
|||
# This file is used to override default values used by the Ant build system.
|
||||
#
|
||||
# This file must be checked into Version Control Systems, as it is
|
||||
# integral to the build system of your project.
|
||||
|
||||
# This file is only used by the Ant script.
|
||||
|
||||
# You can use this to override default values such as
|
||||
# 'source.dir' for the location of your java source folder and
|
||||
# 'out.dir' for the location of your output folder.
|
||||
|
||||
# You can also use it define how the release builds are signed by declaring
|
||||
# the following properties:
|
||||
# 'key.store' for the location of your keystore and
|
||||
# 'key.alias' for the name of the key to use.
|
||||
# The password will be asked during the build when you use the 'release' target.
|
||||
|
|
@ -1,92 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project name="SimpleGame" default="help">
|
||||
|
||||
<!-- The local.properties file is created and updated by the 'android' tool.
|
||||
It contains the path to the SDK. It should *NOT* be checked into
|
||||
Version Control Systems. -->
|
||||
<property file="local.properties" />
|
||||
|
||||
<!-- The ant.properties file can be created by you. It is only edited by the
|
||||
'android' tool to add properties to it.
|
||||
This is the place to change some Ant specific build properties.
|
||||
Here are some properties you may want to change/update:
|
||||
|
||||
source.dir
|
||||
The name of the source directory. Default is 'src'.
|
||||
out.dir
|
||||
The name of the output directory. Default is 'bin'.
|
||||
|
||||
For other overridable properties, look at the beginning of the rules
|
||||
files in the SDK, at tools/ant/build.xml
|
||||
|
||||
Properties related to the SDK location or the project target should
|
||||
be updated using the 'android' tool with the 'update' action.
|
||||
|
||||
This file is an integral part of the build system for your
|
||||
application and should be checked into Version Control Systems.
|
||||
|
||||
-->
|
||||
<property file="ant.properties" />
|
||||
|
||||
<!-- if sdk.dir was not set from one of the property file, then
|
||||
get it from the ANDROID_HOME env var.
|
||||
This must be done before we load project.properties since
|
||||
the proguard config can use sdk.dir -->
|
||||
<property environment="env" />
|
||||
<condition property="sdk.dir" value="${env.ANDROID_HOME}">
|
||||
<isset property="env.ANDROID_HOME" />
|
||||
</condition>
|
||||
|
||||
<!-- The project.properties file is created and updated by the 'android'
|
||||
tool, as well as ADT.
|
||||
|
||||
This contains project specific properties such as project target, and library
|
||||
dependencies. Lower level build properties are stored in ant.properties
|
||||
(or in .classpath for Eclipse projects).
|
||||
|
||||
This file is an integral part of the build system for your
|
||||
application and should be checked into Version Control Systems. -->
|
||||
<loadproperties srcFile="project.properties" />
|
||||
|
||||
<!-- quick check on sdk.dir -->
|
||||
<fail
|
||||
message="sdk.dir is missing. Make sure to generate local.properties using 'android update project' or to inject it through the ANDROID_HOME environment variable."
|
||||
unless="sdk.dir"
|
||||
/>
|
||||
|
||||
<!--
|
||||
Import per project custom build rules if present at the root of the project.
|
||||
This is the place to put custom intermediary targets such as:
|
||||
-pre-build
|
||||
-pre-compile
|
||||
-post-compile (This is typically used for code obfuscation.
|
||||
Compiled code location: ${out.classes.absolute.dir}
|
||||
If this is not done in place, override ${out.dex.input.absolute.dir})
|
||||
-post-package
|
||||
-post-build
|
||||
-pre-clean
|
||||
-->
|
||||
<import file="custom_rules.xml" optional="true" />
|
||||
|
||||
<!-- Import the actual build file.
|
||||
|
||||
To customize existing targets, there are two options:
|
||||
- Customize only one target:
|
||||
- copy/paste the target into this file, *before* the
|
||||
<import> task.
|
||||
- customize it to your needs.
|
||||
- Customize the whole content of build.xml
|
||||
- copy/paste the content of the rules files (minus the top node)
|
||||
into this file, replacing the <import> task.
|
||||
- customize to your needs.
|
||||
|
||||
***********************
|
||||
****** IMPORTANT ******
|
||||
***********************
|
||||
In all cases you must update the value of version-tag below to read 'custom' instead of an integer,
|
||||
in order to avoid having your file be overridden by tools such as "android update project"
|
||||
-->
|
||||
<!-- version-tag: 1 -->
|
||||
<import file="${sdk.dir}/tools/ant/build.xml" />
|
||||
|
||||
</project>
|
|
@ -1,91 +0,0 @@
|
|||
APPNAME="SimpleGame"
|
||||
|
||||
# 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
|
||||
|
||||
if [ -z "${NDK_ROOT+aaa}" ];then
|
||||
echo "please define NDK_ROOT"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
# ... use paths relative to current directory
|
||||
COCOS2DX_ROOT="$DIR/../.."
|
||||
APP_ROOT="$DIR/.."
|
||||
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
|
||||
for file in "$APP_ROOT"/Resources/*
|
||||
do
|
||||
if [ -d "$file" ]; then
|
||||
cp -rf "$file" "$APP_ANDROID_ROOT"/assets
|
||||
fi
|
||||
|
||||
if [ -f "$file" ]; then
|
||||
cp "$file" "$APP_ANDROID_ROOT"/assets
|
||||
fi
|
||||
done
|
||||
|
||||
# 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,21 +0,0 @@
|
|||
LOCAL_PATH := $(call my-dir)
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
|
||||
LOCAL_MODULE := game_shared
|
||||
|
||||
LOCAL_MODULE_FILENAME := libgame
|
||||
|
||||
LOCAL_SRC_FILES := hellocpp/main.cpp \
|
||||
../../Classes/AppDelegate.cpp \
|
||||
../../Classes/HelloWorldScene.cpp
|
||||
|
||||
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../Classes
|
||||
|
||||
LOCAL_WHOLE_STATIC_LIBRARIES := cocos2dx_static cocosdenshion_static cocos_extension_static
|
||||
|
||||
include $(BUILD_SHARED_LIBRARY)
|
||||
|
||||
$(call import-module,CocosDenshion/android) \
|
||||
$(call import-module,cocos2dx) \
|
||||
$(call import-module,extensions)
|
|
@ -1,2 +0,0 @@
|
|||
APP_STL := gnustl_static
|
||||
APP_CPPFLAGS := -frtti
|
|
@ -1,45 +0,0 @@
|
|||
#include "AppDelegate.h"
|
||||
#include "platform/android/jni/JniHelper.h"
|
||||
#include <jni.h>
|
||||
#include <android/log.h>
|
||||
|
||||
#include "HelloWorldScene.h"
|
||||
|
||||
#define LOG_TAG "main"
|
||||
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__)
|
||||
|
||||
using namespace cocos2d;
|
||||
|
||||
extern "C"
|
||||
{
|
||||
|
||||
jint JNI_OnLoad(JavaVM *vm, void *reserved)
|
||||
{
|
||||
JniHelper::setJavaVM(vm);
|
||||
|
||||
return JNI_VERSION_1_4;
|
||||
}
|
||||
|
||||
void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thiz, jint w, jint h)
|
||||
{
|
||||
if (!CCDirector::sharedDirector()->getOpenGLView())
|
||||
{
|
||||
CCEGLView *view = CCEGLView::sharedOpenGLView();
|
||||
view->setFrameSize(w, h);
|
||||
|
||||
AppDelegate *pAppDelegate = new AppDelegate();
|
||||
CCApplication::sharedApplication()->run();
|
||||
}
|
||||
else
|
||||
{
|
||||
ccDrawInit();
|
||||
ccGLInvalidateStateCache();
|
||||
|
||||
CCShaderCache::sharedShaderCache()->reloadDefaultShaders();
|
||||
CCTextureCache::reloadAllTextures();
|
||||
CCNotificationCenter::sharedNotificationCenter()->postNotification(EVNET_COME_TO_FOREGROUND, NULL);
|
||||
CCDirector::sharedDirector()->setGLDefaultValues();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,23 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
append_str=' \'
|
||||
|
||||
list_alldir()
|
||||
{
|
||||
for file in $1/*
|
||||
do
|
||||
if [ -f $file ]; then
|
||||
echo $file$append_str | grep .cpp
|
||||
fi
|
||||
|
||||
if [ -d $file ]; then
|
||||
list_alldir $file
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
if [ $# -gt 0 ]; then
|
||||
list_alldir "$1"
|
||||
else
|
||||
list_alldir "."
|
||||
fi
|
|
@ -1,20 +0,0 @@
|
|||
# To enable ProGuard in your project, edit project.properties
|
||||
# to define the proguard.config property as described in that file.
|
||||
#
|
||||
# Add project specific ProGuard rules here.
|
||||
# By default, the flags in this file are appended to flags specified
|
||||
# in ${sdk.dir}/tools/proguard/proguard-android.txt
|
||||
# You can edit the include path and order by changing the ProGuard
|
||||
# include property in project.properties.
|
||||
#
|
||||
# For more details, see
|
||||
# http://developer.android.com/guide/developing/tools/proguard.html
|
||||
|
||||
# Add any project specific keep options here:
|
||||
|
||||
# If your project uses WebView with JS, uncomment the following
|
||||
# and specify the fully qualified class name to the JavaScript interface
|
||||
# class:
|
||||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
||||
# public *;
|
||||
#}
|
|
@ -1,14 +0,0 @@
|
|||
# This file is automatically generated by Android Tools.
|
||||
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
|
||||
#
|
||||
# This file must be checked in Version Control Systems.
|
||||
#
|
||||
# To customize properties used by the Ant build system edit
|
||||
# "ant.properties", and override values to adapt the script to your
|
||||
# project structure.
|
||||
#
|
||||
# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
|
||||
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
|
||||
|
||||
# Project target.
|
||||
target=android-8
|
|
@ -1,4 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<string name="app_name">SimpleGame</string>
|
||||
</resources>
|
|
@ -1,107 +0,0 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2010-2011 cocos2d-x.org
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
package org.cocos2dx.lib;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Configuration;
|
||||
import android.hardware.Sensor;
|
||||
import android.hardware.SensorEvent;
|
||||
import android.hardware.SensorEventListener;
|
||||
import android.hardware.SensorManager;
|
||||
import android.view.Display;
|
||||
import android.view.Surface;
|
||||
import android.view.WindowManager;
|
||||
|
||||
/**
|
||||
*
|
||||
* This class is used for controlling the Accelerometer
|
||||
*
|
||||
*/
|
||||
public class Cocos2dxAccelerometer implements SensorEventListener {
|
||||
|
||||
private static final String TAG = "Cocos2dxAccelerometer";
|
||||
private Context mContext;
|
||||
private SensorManager mSensorManager;
|
||||
private Sensor mAccelerometer;
|
||||
private int mNaturalOrientation;
|
||||
|
||||
public Cocos2dxAccelerometer(Context context){
|
||||
mContext = context;
|
||||
|
||||
//Get an instance of the SensorManager
|
||||
mSensorManager = (SensorManager) mContext.getSystemService(Context.SENSOR_SERVICE);
|
||||
mAccelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
|
||||
|
||||
Display display = ((WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
|
||||
mNaturalOrientation = display.getOrientation();
|
||||
}
|
||||
|
||||
public void enable() {
|
||||
mSensorManager.registerListener(this, mAccelerometer, SensorManager.SENSOR_DELAY_GAME);
|
||||
}
|
||||
|
||||
public void disable () {
|
||||
mSensorManager.unregisterListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSensorChanged(SensorEvent event) {
|
||||
|
||||
if (event.sensor.getType() != Sensor.TYPE_ACCELEROMETER){
|
||||
return;
|
||||
}
|
||||
|
||||
float x = event.values[0];
|
||||
float y = event.values[1];
|
||||
float z = event.values[2];
|
||||
|
||||
/*
|
||||
* Because the axes are not swapped when the device's screen orientation changes.
|
||||
* So we should swap it here.
|
||||
* In tablets such as Motorola Xoom, the default orientation is landscape, so should
|
||||
* consider this.
|
||||
*/
|
||||
int orientation = mContext.getResources().getConfiguration().orientation;
|
||||
if ((orientation == Configuration.ORIENTATION_LANDSCAPE) && (mNaturalOrientation != Surface.ROTATION_0)){
|
||||
float tmp = x;
|
||||
x = -y;
|
||||
y = tmp;
|
||||
}
|
||||
else if ((orientation == Configuration.ORIENTATION_PORTRAIT) && (mNaturalOrientation != Surface.ROTATION_0))
|
||||
{
|
||||
float tmp = x;
|
||||
x = y;
|
||||
y = -tmp;
|
||||
}
|
||||
|
||||
onSensorChanged(x, y, z, event.timestamp);
|
||||
// Log.d(TAG, "x = " + event.values[0] + " y = " + event.values[1] + " z = " + event.values[2]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAccuracyChanged(Sensor sensor, int accuracy) {
|
||||
}
|
||||
|
||||
private static native void onSensorChanged(float x, float y, float z, long timeStamp);
|
||||
}
|
|
@ -1,346 +0,0 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2010-2012 cocos2d-x.org
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
package org.cocos2dx.lib;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.PackageManager.NameNotFoundException;
|
||||
import android.content.res.AssetManager;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.util.Log;
|
||||
|
||||
public class Cocos2dxActivity extends Activity{
|
||||
|
||||
protected Cocos2dxGLSurfaceView mGLView;
|
||||
private static Cocos2dxMusic backgroundMusicPlayer;
|
||||
private static Cocos2dxSound soundPlayer;
|
||||
private static Cocos2dxAccelerometer accelerometer;
|
||||
private static AssetManager assetManager;
|
||||
private static boolean accelerometerEnabled = false;
|
||||
private static Handler handler;
|
||||
private final static int HANDLER_SHOW_DIALOG = 1;
|
||||
private final static int HANDLER_SHOW_EDITBOX_DIALOG = 2;
|
||||
|
||||
private static String packageName;
|
||||
|
||||
private static native void nativeSetPaths(String apkPath);
|
||||
private static native void nativeSetEditboxText(byte[] text);
|
||||
|
||||
|
||||
static class ShowDialogHandler extends Handler {
|
||||
WeakReference<Cocos2dxActivity> mActivity;
|
||||
|
||||
ShowDialogHandler(Cocos2dxActivity activity) {
|
||||
mActivity = new WeakReference<Cocos2dxActivity>(activity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
Cocos2dxActivity theActivity = mActivity.get();
|
||||
switch(msg.what) {
|
||||
case HANDLER_SHOW_DIALOG:
|
||||
theActivity.showDialog(((DialogMessage)msg.obj).title, ((DialogMessage)msg.obj).message);
|
||||
break;
|
||||
case HANDLER_SHOW_EDITBOX_DIALOG:
|
||||
theActivity.onShowEditBoxDialog((EditBoxMessage)msg.obj);
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
public Cocos2dxGLSurfaceView getGLView() {
|
||||
return mGLView;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
// get frame size
|
||||
DisplayMetrics dm = new DisplayMetrics();
|
||||
getWindowManager().getDefaultDisplay().getMetrics(dm);
|
||||
accelerometer = new Cocos2dxAccelerometer(this);
|
||||
|
||||
// init media player and sound player
|
||||
backgroundMusicPlayer = new Cocos2dxMusic(this);
|
||||
soundPlayer = new Cocos2dxSound(this);
|
||||
|
||||
// init asset manager for jni call
|
||||
assetManager = getAssets();
|
||||
|
||||
// init bitmap context
|
||||
Cocos2dxBitmap.setContext(this);
|
||||
|
||||
handler = new ShowDialogHandler(this);
|
||||
}
|
||||
|
||||
public static String getDeviceModel(){
|
||||
return Build.MODEL;
|
||||
}
|
||||
|
||||
public static AssetManager getAssetManager() {
|
||||
return assetManager;
|
||||
}
|
||||
|
||||
public static String getCurrentLanguage() {
|
||||
String languageName = java.util.Locale.getDefault().getLanguage();
|
||||
return languageName;
|
||||
}
|
||||
|
||||
public static void showMessageBox(String title, String message){
|
||||
Message msg = new Message();
|
||||
msg.what = HANDLER_SHOW_DIALOG;
|
||||
msg.obj = new DialogMessage(title, message);
|
||||
|
||||
handler.sendMessage(msg);
|
||||
}
|
||||
|
||||
public static void enableAccelerometer() {
|
||||
accelerometerEnabled = true;
|
||||
accelerometer.enable();
|
||||
}
|
||||
|
||||
public static void disableAccelerometer() {
|
||||
accelerometerEnabled = false;
|
||||
accelerometer.disable();
|
||||
}
|
||||
|
||||
public static void preloadBackgroundMusic(String path){
|
||||
backgroundMusicPlayer.preloadBackgroundMusic(path);
|
||||
}
|
||||
|
||||
public static void playBackgroundMusic(String path, boolean isLoop){
|
||||
backgroundMusicPlayer.playBackgroundMusic(path, isLoop);
|
||||
}
|
||||
|
||||
public static void stopBackgroundMusic(){
|
||||
backgroundMusicPlayer.stopBackgroundMusic();
|
||||
}
|
||||
|
||||
public static void pauseBackgroundMusic(){
|
||||
backgroundMusicPlayer.pauseBackgroundMusic();
|
||||
}
|
||||
|
||||
public static void resumeBackgroundMusic(){
|
||||
backgroundMusicPlayer.resumeBackgroundMusic();
|
||||
}
|
||||
|
||||
public static void rewindBackgroundMusic(){
|
||||
backgroundMusicPlayer.rewindBackgroundMusic();
|
||||
}
|
||||
|
||||
public static boolean isBackgroundMusicPlaying(){
|
||||
return backgroundMusicPlayer.isBackgroundMusicPlaying();
|
||||
}
|
||||
|
||||
public static float getBackgroundMusicVolume(){
|
||||
return backgroundMusicPlayer.getBackgroundVolume();
|
||||
}
|
||||
|
||||
public static void setBackgroundMusicVolume(float volume){
|
||||
backgroundMusicPlayer.setBackgroundVolume(volume);
|
||||
}
|
||||
|
||||
public static int playEffect(String path, boolean isLoop){
|
||||
return soundPlayer.playEffect(path, isLoop);
|
||||
}
|
||||
|
||||
public static void stopEffect(int soundId){
|
||||
soundPlayer.stopEffect(soundId);
|
||||
}
|
||||
|
||||
public static void pauseEffect(int soundId){
|
||||
soundPlayer.pauseEffect(soundId);
|
||||
}
|
||||
|
||||
public static void resumeEffect(int soundId){
|
||||
soundPlayer.resumeEffect(soundId);
|
||||
}
|
||||
|
||||
public static float getEffectsVolume(){
|
||||
return soundPlayer.getEffectsVolume();
|
||||
}
|
||||
|
||||
public static void setEffectsVolume(float volume){
|
||||
soundPlayer.setEffectsVolume(volume);
|
||||
}
|
||||
|
||||
public static void preloadEffect(String path){
|
||||
soundPlayer.preloadEffect(path);
|
||||
}
|
||||
|
||||
public static void unloadEffect(String path){
|
||||
soundPlayer.unloadEffect(path);
|
||||
}
|
||||
|
||||
public static void stopAllEffects(){
|
||||
soundPlayer.stopAllEffects();
|
||||
}
|
||||
|
||||
public static void pauseAllEffects(){
|
||||
soundPlayer.pauseAllEffects();
|
||||
}
|
||||
|
||||
public static void resumeAllEffects(){
|
||||
soundPlayer.resumeAllEffects();
|
||||
}
|
||||
|
||||
public static void end(){
|
||||
backgroundMusicPlayer.end();
|
||||
soundPlayer.end();
|
||||
}
|
||||
|
||||
public static String getCocos2dxPackageName(){
|
||||
return packageName;
|
||||
}
|
||||
|
||||
public static void terminateProcess(){
|
||||
android.os.Process.killProcess(android.os.Process.myPid());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
if (accelerometerEnabled) {
|
||||
accelerometer.enable();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
if (accelerometerEnabled) {
|
||||
accelerometer.disable();
|
||||
}
|
||||
}
|
||||
|
||||
protected void setPackageName(String packageName) {
|
||||
Cocos2dxActivity.packageName = packageName;
|
||||
|
||||
String apkFilePath = "";
|
||||
ApplicationInfo appInfo = null;
|
||||
PackageManager packMgmr = getApplication().getPackageManager();
|
||||
try {
|
||||
appInfo = packMgmr.getApplicationInfo(packageName, 0);
|
||||
} catch (NameNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException("Unable to locate assets, aborting...");
|
||||
}
|
||||
apkFilePath = appInfo.sourceDir;
|
||||
Log.w("apk path", apkFilePath);
|
||||
|
||||
// add this link at the renderer class
|
||||
nativeSetPaths(apkFilePath);
|
||||
}
|
||||
|
||||
private void showDialog(String title, String message){
|
||||
Dialog dialog = new AlertDialog.Builder(this)
|
||||
.setTitle(title)
|
||||
.setMessage(message)
|
||||
.setPositiveButton("Ok",
|
||||
new DialogInterface.OnClickListener()
|
||||
{
|
||||
public void onClick(DialogInterface dialog, int whichButton){
|
||||
|
||||
}
|
||||
}).create();
|
||||
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
private static void showEditBoxDialog(String title, String content, int inputMode, int inputFlag, int returnType, int maxLength)
|
||||
{
|
||||
Message msg = new Message();
|
||||
msg.what = HANDLER_SHOW_EDITBOX_DIALOG;
|
||||
msg.obj = new EditBoxMessage(title, content, inputMode, inputFlag, returnType, maxLength);
|
||||
handler.sendMessage(msg);
|
||||
}
|
||||
|
||||
private void onShowEditBoxDialog(EditBoxMessage msg)
|
||||
{
|
||||
Dialog dialog = new Cocos2dxEditBoxDialog(this, msg);
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
public void setEditBoxResult(String editResult)
|
||||
{
|
||||
Log.i("editbox_content", editResult);
|
||||
|
||||
try
|
||||
{
|
||||
final byte[] bytesUTF8 = editResult.getBytes("UTF8");
|
||||
// pass utf8 string from editbox activity to native.
|
||||
// Should invoke native method in GL thread.
|
||||
mGLView.queueEvent(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
nativeSetEditboxText(bytesUTF8);
|
||||
}
|
||||
});
|
||||
}
|
||||
catch (java.io.UnsupportedEncodingException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class DialogMessage {
|
||||
public String title;
|
||||
public String message;
|
||||
|
||||
public DialogMessage(String title, String message){
|
||||
this.message = message;
|
||||
this.title = title;
|
||||
}
|
||||
}
|
||||
|
||||
class EditBoxMessage {
|
||||
public String title;
|
||||
public String content;
|
||||
public int inputMode;
|
||||
public int inputFlag;
|
||||
public int returnType;
|
||||
public int maxLength;
|
||||
|
||||
public EditBoxMessage(String title, String content, int inputMode, int inputFlag, int returnType, int maxLength){
|
||||
this.content = content;
|
||||
this.title = title;
|
||||
this.inputMode = inputMode;
|
||||
this.inputFlag = inputFlag;
|
||||
this.returnType = returnType;
|
||||
this.maxLength = maxLength;
|
||||
}
|
||||
}
|
|
@ -1,455 +0,0 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2010-2011 cocos2d-x.org
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
package org.cocos2dx.lib;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import java.util.LinkedList;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.Typeface;
|
||||
import android.graphics.Paint.Align;
|
||||
import android.graphics.Paint.FontMetricsInt;
|
||||
import android.text.TextPaint;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
public class Cocos2dxBitmap{
|
||||
/*
|
||||
* The values are the same as cocos2dx/platform/CCImage.h.
|
||||
*/
|
||||
private static final int HALIGNCENTER = 3;
|
||||
private static final int HALIGNLEFT = 1;
|
||||
private static final int HALIGNRIGHT = 2;
|
||||
// vertical alignment
|
||||
private static final int VALIGNTOP = 1;
|
||||
private static final int VALIGNBOTTOM = 2;
|
||||
private static final int VALIGNCENTER = 3;
|
||||
|
||||
private static Context context;
|
||||
|
||||
public static void setContext(Context context){
|
||||
Cocos2dxBitmap.context = context;
|
||||
}
|
||||
|
||||
/*
|
||||
* @width: the width to draw, it can be 0
|
||||
* @height: the height to draw, it can be 0
|
||||
*/
|
||||
public static void createTextBitmap(String content, String fontName,
|
||||
int fontSize, int alignment, int width, int height){
|
||||
|
||||
content = refactorString(content);
|
||||
Paint paint = newPaint(fontName, fontSize, alignment);
|
||||
|
||||
TextProperty textProperty = computeTextProperty(content, paint, width, height);
|
||||
|
||||
int bitmapTotalHeight = (height == 0 ? textProperty.totalHeight:height);
|
||||
|
||||
// Draw text to bitmap
|
||||
Bitmap bitmap = Bitmap.createBitmap(textProperty.maxWidth,
|
||||
bitmapTotalHeight, Bitmap.Config.ARGB_8888);
|
||||
Canvas canvas = new Canvas(bitmap);
|
||||
|
||||
// Draw string
|
||||
FontMetricsInt fm = paint.getFontMetricsInt();
|
||||
int x = 0;
|
||||
int y = computeY(fm, height, textProperty.totalHeight, alignment);
|
||||
String[] lines = textProperty.lines;
|
||||
for (String line : lines){
|
||||
x = computeX(paint, line, textProperty.maxWidth, alignment);
|
||||
canvas.drawText(line, x, y, paint);
|
||||
y += textProperty.heightPerLine;
|
||||
}
|
||||
|
||||
initNativeObject(bitmap);
|
||||
}
|
||||
|
||||
private static int computeX(Paint paint, String content, int w, int alignment){
|
||||
int ret = 0;
|
||||
int hAlignment = alignment & 0x0F;
|
||||
|
||||
switch (hAlignment){
|
||||
case HALIGNCENTER:
|
||||
ret = w / 2;
|
||||
break;
|
||||
|
||||
// ret = 0
|
||||
case HALIGNLEFT:
|
||||
break;
|
||||
|
||||
case HALIGNRIGHT:
|
||||
ret = w;
|
||||
break;
|
||||
|
||||
/*
|
||||
* Default is align left.
|
||||
* Should be same as newPaint().
|
||||
*/
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
private static int computeY(FontMetricsInt fm, int constrainHeight, int totalHeight, int alignment) {
|
||||
int y = -fm.top;
|
||||
|
||||
if (constrainHeight > totalHeight) {
|
||||
int vAlignment = (alignment >> 4) & 0x0F;
|
||||
|
||||
switch (vAlignment) {
|
||||
case VALIGNTOP:
|
||||
y = -fm.top;
|
||||
break;
|
||||
case VALIGNCENTER:
|
||||
y = -fm.top + (constrainHeight - totalHeight)/2;
|
||||
break;
|
||||
case VALIGNBOTTOM:
|
||||
y = -fm.top + (constrainHeight - totalHeight);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return y;
|
||||
}
|
||||
|
||||
private static class TextProperty{
|
||||
// The max width of lines
|
||||
int maxWidth;
|
||||
// The height of all lines
|
||||
int totalHeight;
|
||||
int heightPerLine;
|
||||
String[] lines;
|
||||
|
||||
TextProperty(int w, int h, String[] lines){
|
||||
this.maxWidth = w;
|
||||
this.heightPerLine = h;
|
||||
this.totalHeight = h * lines.length;
|
||||
this.lines = lines;
|
||||
}
|
||||
}
|
||||
|
||||
private static TextProperty computeTextProperty(String content, Paint paint,
|
||||
int maxWidth, int maxHeight){
|
||||
FontMetricsInt fm = paint.getFontMetricsInt();
|
||||
int h = (int)Math.ceil(fm.bottom - fm.top);
|
||||
int maxContentWidth = 0;
|
||||
|
||||
String[] lines = splitString(content, maxHeight, maxWidth, paint);
|
||||
|
||||
if (maxWidth != 0){
|
||||
maxContentWidth = maxWidth;
|
||||
}
|
||||
else {
|
||||
/*
|
||||
* Compute the max width
|
||||
*/
|
||||
int temp = 0;
|
||||
for (String line : lines){
|
||||
temp = (int)Math.ceil(paint.measureText(line, 0, line.length()));
|
||||
if (temp > maxContentWidth){
|
||||
maxContentWidth = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return new TextProperty(maxContentWidth, h, lines);
|
||||
}
|
||||
|
||||
/*
|
||||
* If maxWidth or maxHeight is not 0,
|
||||
* split the string to fix the maxWidth and maxHeight.
|
||||
*/
|
||||
private static String[] splitString(String content, int maxHeight, int maxWidth,
|
||||
Paint paint){
|
||||
String[] lines = content.split("\\n");
|
||||
String[] ret = null;
|
||||
FontMetricsInt fm = paint.getFontMetricsInt();
|
||||
int heightPerLine = (int)Math.ceil(fm.bottom - fm.top);
|
||||
int maxLines = maxHeight / heightPerLine;
|
||||
|
||||
if (maxWidth != 0){
|
||||
LinkedList<String> strList = new LinkedList<String>();
|
||||
for (String line : lines){
|
||||
/*
|
||||
* The width of line is exceed maxWidth, should divide it into
|
||||
* two or more lines.
|
||||
*/
|
||||
int lineWidth = (int)Math.ceil(paint.measureText(line));
|
||||
if (lineWidth > maxWidth){
|
||||
strList.addAll(divideStringWithMaxWidth(paint, line, maxWidth));
|
||||
}
|
||||
else{
|
||||
strList.add(line);
|
||||
}
|
||||
|
||||
/*
|
||||
* Should not exceed the max height;
|
||||
*/
|
||||
if (maxLines > 0 && strList.size() >= maxLines){
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Remove exceeding lines
|
||||
*/
|
||||
if (maxLines > 0 && strList.size() > maxLines){
|
||||
while (strList.size() > maxLines){
|
||||
strList.removeLast();
|
||||
}
|
||||
}
|
||||
|
||||
ret = new String[strList.size()];
|
||||
strList.toArray(ret);
|
||||
} else
|
||||
if (maxHeight != 0 && lines.length > maxLines) {
|
||||
/*
|
||||
* Remove exceeding lines
|
||||
*/
|
||||
LinkedList<String> strList = new LinkedList<String>();
|
||||
for (int i = 0; i < maxLines; i++){
|
||||
strList.add(lines[i]);
|
||||
}
|
||||
ret = new String[strList.size()];
|
||||
strList.toArray(ret);
|
||||
}
|
||||
else {
|
||||
ret = lines;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
private static LinkedList<String> divideStringWithMaxWidth(Paint paint, String content,
|
||||
int width){
|
||||
int charLength = content.length();
|
||||
int start = 0;
|
||||
int tempWidth = 0;
|
||||
LinkedList<String> strList = new LinkedList<String>();
|
||||
|
||||
/*
|
||||
* Break a String into String[] by the width & should wrap the word
|
||||
*/
|
||||
for (int i = 1; i <= charLength; ++i){
|
||||
tempWidth = (int)Math.ceil(paint.measureText(content, start, i));
|
||||
if (tempWidth >= width){
|
||||
int lastIndexOfSpace = content.substring(0, i).lastIndexOf(" ");
|
||||
|
||||
if (lastIndexOfSpace != -1 && lastIndexOfSpace > start){
|
||||
/**
|
||||
* Should wrap the word
|
||||
*/
|
||||
strList.add(content.substring(start, lastIndexOfSpace));
|
||||
i = lastIndexOfSpace;
|
||||
}
|
||||
else {
|
||||
/*
|
||||
* Should not exceed the width
|
||||
*/
|
||||
if (tempWidth > width){
|
||||
strList.add(content.substring(start, i - 1));
|
||||
/*
|
||||
* compute from previous char
|
||||
*/
|
||||
--i;
|
||||
}
|
||||
else {
|
||||
strList.add(content.substring(start, i));
|
||||
}
|
||||
}
|
||||
|
||||
// remove spaces at the beginning of a new line
|
||||
while(content.indexOf(i++) == ' ') {
|
||||
}
|
||||
|
||||
start = i;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Add the last chars
|
||||
*/
|
||||
if (start < charLength){
|
||||
strList.add(content.substring(start));
|
||||
}
|
||||
|
||||
return strList;
|
||||
}
|
||||
|
||||
private static Paint newPaint(String fontName, int fontSize, int alignment){
|
||||
Paint paint = new Paint();
|
||||
paint.setColor(Color.WHITE);
|
||||
paint.setTextSize(fontSize);
|
||||
paint.setAntiAlias(true);
|
||||
|
||||
/*
|
||||
* Set type face for paint, now it support .ttf file.
|
||||
*/
|
||||
if (fontName.endsWith(".ttf")){
|
||||
try {
|
||||
//Typeface typeFace = Typeface.createFromAsset(context.getAssets(), fontName);
|
||||
Typeface typeFace = Cocos2dxTypefaces.get(context, fontName);
|
||||
paint.setTypeface(typeFace);
|
||||
} catch (Exception e){
|
||||
Log.e("Cocos2dxBitmap",
|
||||
"error to create ttf type face: " + fontName);
|
||||
|
||||
/*
|
||||
* The file may not find, use system font
|
||||
*/
|
||||
paint.setTypeface(Typeface.create(fontName, Typeface.NORMAL));
|
||||
}
|
||||
}
|
||||
else {
|
||||
paint.setTypeface(Typeface.create(fontName, Typeface.NORMAL));
|
||||
}
|
||||
|
||||
int hAlignment = alignment & 0x0F;
|
||||
switch (hAlignment){
|
||||
case HALIGNCENTER:
|
||||
paint.setTextAlign(Align.CENTER);
|
||||
break;
|
||||
|
||||
case HALIGNLEFT:
|
||||
paint.setTextAlign(Align.LEFT);
|
||||
break;
|
||||
|
||||
case HALIGNRIGHT:
|
||||
paint.setTextAlign(Align.RIGHT);
|
||||
break;
|
||||
|
||||
default:
|
||||
paint.setTextAlign(Align.LEFT);
|
||||
break;
|
||||
}
|
||||
|
||||
return paint;
|
||||
}
|
||||
|
||||
private static String refactorString(String str){
|
||||
// Avoid error when content is ""
|
||||
if (str.compareTo("") == 0){
|
||||
return " ";
|
||||
}
|
||||
|
||||
/*
|
||||
* If the font of "\n" is "" or "\n", insert " " in front of it.
|
||||
*
|
||||
* For example:
|
||||
* "\nabc" -> " \nabc"
|
||||
* "\nabc\n\n" -> " \nabc\n \n"
|
||||
*/
|
||||
StringBuilder strBuilder = new StringBuilder(str);
|
||||
int start = 0;
|
||||
int index = strBuilder.indexOf("\n");
|
||||
while (index != -1){
|
||||
if (index == 0 || strBuilder.charAt(index -1) == '\n'){
|
||||
strBuilder.insert(start, " ");
|
||||
start = index + 2;
|
||||
} else {
|
||||
start = index + 1;
|
||||
}
|
||||
|
||||
if (start > strBuilder.length() || index == strBuilder.length()){
|
||||
break;
|
||||
}
|
||||
|
||||
index = strBuilder.indexOf("\n", start);
|
||||
}
|
||||
|
||||
return strBuilder.toString();
|
||||
}
|
||||
|
||||
private static void initNativeObject(Bitmap bitmap){
|
||||
byte[] pixels = getPixels(bitmap);
|
||||
if (pixels == null){
|
||||
return;
|
||||
}
|
||||
|
||||
nativeInitBitmapDC(bitmap.getWidth(), bitmap.getHeight(), pixels);
|
||||
}
|
||||
|
||||
private static byte[] getPixels(Bitmap bitmap){
|
||||
if (bitmap != null){
|
||||
byte[] pixels = new byte[bitmap.getWidth() * bitmap.getHeight() * 4];
|
||||
ByteBuffer buf = ByteBuffer.wrap(pixels);
|
||||
buf.order(ByteOrder.nativeOrder());
|
||||
bitmap.copyPixelsToBuffer(buf);
|
||||
return pixels;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private static native void nativeInitBitmapDC(int width, int height, byte[] pixels);
|
||||
|
||||
private static int getFontSizeAccordingHeight(int height)
|
||||
{
|
||||
Paint paint = new Paint();
|
||||
Rect bounds = new Rect();
|
||||
|
||||
paint.setTypeface(Typeface.DEFAULT);
|
||||
int incr_text_size = 1;
|
||||
boolean found_desired_size = false;
|
||||
|
||||
while (!found_desired_size) {
|
||||
|
||||
paint.setTextSize(incr_text_size);
|
||||
String text = "SghMNy";
|
||||
paint.getTextBounds(text, 0, text.length(), bounds);
|
||||
|
||||
incr_text_size++;
|
||||
|
||||
if (height - bounds.height() <= 2) {
|
||||
found_desired_size = true;
|
||||
}
|
||||
Log.d("font size", "incr size:" + incr_text_size);
|
||||
}
|
||||
return incr_text_size;
|
||||
}
|
||||
|
||||
private static String getStringWithEllipsis(String originalText, float width, float fontSize){
|
||||
if(TextUtils.isEmpty(originalText)){
|
||||
return "";
|
||||
}
|
||||
|
||||
TextPaint paint = new TextPaint();
|
||||
paint.setTypeface(Typeface.DEFAULT);
|
||||
paint.setTextSize(fontSize);
|
||||
|
||||
return TextUtils.ellipsize(originalText, paint, width,
|
||||
TextUtils.TruncateAt.valueOf("END")).toString();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,338 +0,0 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2010-2012 cocos2d-x.org
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
package org.cocos2dx.lib;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.text.InputFilter;
|
||||
import android.text.InputType;
|
||||
import android.util.Log;
|
||||
import android.util.TypedValue;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.WindowManager;
|
||||
import android.view.inputmethod.EditorInfo;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.EditText;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.TextView.OnEditorActionListener;
|
||||
|
||||
public class Cocos2dxEditBoxDialog extends Dialog {
|
||||
|
||||
/**
|
||||
* The user is allowed to enter any text, including line breaks.
|
||||
*/
|
||||
private final int kEditBoxInputModeAny = 0;
|
||||
|
||||
/**
|
||||
* The user is allowed to enter an e-mail address.
|
||||
*/
|
||||
private final int kEditBoxInputModeEmailAddr = 1;
|
||||
|
||||
/**
|
||||
* The user is allowed to enter an integer value.
|
||||
*/
|
||||
private final int kEditBoxInputModeNumeric = 2;
|
||||
|
||||
/**
|
||||
* The user is allowed to enter a phone number.
|
||||
*/
|
||||
private final int kEditBoxInputModePhoneNumber = 3;
|
||||
|
||||
/**
|
||||
* The user is allowed to enter a URL.
|
||||
*/
|
||||
private final int kEditBoxInputModeUrl = 4;
|
||||
|
||||
/**
|
||||
* The user is allowed to enter a real number value.
|
||||
* This extends kEditBoxInputModeNumeric by allowing a decimal point.
|
||||
*/
|
||||
private final int kEditBoxInputModeDecimal = 5;
|
||||
|
||||
/**
|
||||
* The user is allowed to enter any text, except for line breaks.
|
||||
*/
|
||||
private final int kEditBoxInputModeSingleLine = 6;
|
||||
|
||||
|
||||
/**
|
||||
* Indicates that the text entered is confidential data that should be
|
||||
* obscured whenever possible. This implies EDIT_BOX_INPUT_FLAG_SENSITIVE.
|
||||
*/
|
||||
private final int kEditBoxInputFlagPassword = 0;
|
||||
|
||||
/**
|
||||
* Indicates that the text entered is sensitive data that the
|
||||
* implementation must never store into a dictionary or table for use
|
||||
* in predictive, auto-completing, or other accelerated input schemes.
|
||||
* A credit card number is an example of sensitive data.
|
||||
*/
|
||||
private final int kEditBoxInputFlagSensitive = 1;
|
||||
|
||||
/**
|
||||
* This flag is a hint to the implementation that during text editing,
|
||||
* the initial letter of each word should be capitalized.
|
||||
*/
|
||||
private final int kEditBoxInputFlagInitialCapsWord = 2;
|
||||
|
||||
/**
|
||||
* This flag is a hint to the implementation that during text editing,
|
||||
* the initial letter of each sentence should be capitalized.
|
||||
*/
|
||||
private final int kEditBoxInputFlagInitialCapsSentence = 3;
|
||||
|
||||
/**
|
||||
* Capitalize all characters automatically.
|
||||
*/
|
||||
private final int kEditBoxInputFlagInitialCapsAllCharacters = 4;
|
||||
|
||||
private final int kKeyboardReturnTypeDefault = 0;
|
||||
private final int kKeyboardReturnTypeDone = 1;
|
||||
private final int kKeyboardReturnTypeSend = 2;
|
||||
private final int kKeyboardReturnTypeSearch = 3;
|
||||
private final int kKeyboardReturnTypeGo = 4;
|
||||
|
||||
//
|
||||
private EditText mInputEditText = null;
|
||||
private TextView mTextViewTitle = null;
|
||||
private int mInputMode = 0;
|
||||
private int mInputFlag = 0;
|
||||
private int mReturnType = 0;
|
||||
private int mMaxLength = -1;
|
||||
|
||||
private int mInputFlagConstraints = 0x00000;
|
||||
private int mInputModeContraints = 0x00000;
|
||||
private boolean mIsMultiline = false;
|
||||
private Cocos2dxActivity mParentActivity = null;
|
||||
private EditBoxMessage mMsg = null;
|
||||
|
||||
public Cocos2dxEditBoxDialog(Context context, EditBoxMessage msg) {
|
||||
//super(context, R.style.Theme_Translucent);
|
||||
super(context, android.R.style.Theme_Translucent_NoTitleBar_Fullscreen);
|
||||
// TODO Auto-generated constructor stub
|
||||
mParentActivity = (Cocos2dxActivity)context;
|
||||
mMsg = msg;
|
||||
}
|
||||
|
||||
// Converting dips to pixels
|
||||
private int convertDipsToPixels(float dips)
|
||||
{
|
||||
float scale = getContext().getResources().getDisplayMetrics().density;
|
||||
return Math.round(dips * scale);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
// TODO Auto-generated method stub
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
getWindow().setBackgroundDrawable(new ColorDrawable(0x80000000));
|
||||
|
||||
LinearLayout layout = new LinearLayout(mParentActivity);
|
||||
layout.setOrientation(LinearLayout.VERTICAL);
|
||||
|
||||
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.
|
||||
LayoutParams.FILL_PARENT,ViewGroup.LayoutParams.FILL_PARENT);
|
||||
|
||||
mTextViewTitle = new TextView(mParentActivity);
|
||||
LinearLayout.LayoutParams textviewParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
|
||||
ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||
textviewParams.leftMargin = textviewParams.rightMargin = convertDipsToPixels(10);
|
||||
mTextViewTitle.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
|
||||
layout.addView(mTextViewTitle, textviewParams);
|
||||
|
||||
mInputEditText = new EditText(mParentActivity);
|
||||
LinearLayout.LayoutParams editTextParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
|
||||
ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||
editTextParams.leftMargin = editTextParams.rightMargin = convertDipsToPixels(10);
|
||||
|
||||
layout.addView(mInputEditText, editTextParams);
|
||||
|
||||
setContentView(layout, layoutParams);
|
||||
|
||||
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||
|
||||
mInputMode = mMsg.inputMode;
|
||||
mInputFlag = mMsg.inputFlag;
|
||||
mReturnType = mMsg.returnType;
|
||||
mMaxLength = mMsg.maxLength;
|
||||
|
||||
mTextViewTitle.setText(mMsg.title);
|
||||
mInputEditText.setText(mMsg.content);
|
||||
|
||||
int oldImeOptions = mInputEditText.getImeOptions();
|
||||
mInputEditText.setImeOptions(oldImeOptions | EditorInfo.IME_FLAG_NO_EXTRACT_UI);
|
||||
oldImeOptions = mInputEditText.getImeOptions();
|
||||
|
||||
switch (mInputMode)
|
||||
{
|
||||
case kEditBoxInputModeAny:
|
||||
mInputModeContraints =
|
||||
InputType.TYPE_CLASS_TEXT |
|
||||
InputType.TYPE_TEXT_FLAG_MULTI_LINE;
|
||||
break;
|
||||
case kEditBoxInputModeEmailAddr:
|
||||
mInputModeContraints =
|
||||
InputType.TYPE_CLASS_TEXT |
|
||||
InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS;
|
||||
break;
|
||||
case kEditBoxInputModeNumeric:
|
||||
mInputModeContraints =
|
||||
InputType.TYPE_CLASS_NUMBER |
|
||||
InputType.TYPE_NUMBER_FLAG_SIGNED;
|
||||
break;
|
||||
case kEditBoxInputModePhoneNumber:
|
||||
mInputModeContraints = InputType.TYPE_CLASS_PHONE;
|
||||
break;
|
||||
case kEditBoxInputModeUrl:
|
||||
mInputModeContraints =
|
||||
InputType.TYPE_CLASS_TEXT |
|
||||
InputType.TYPE_TEXT_VARIATION_URI;
|
||||
break;
|
||||
case kEditBoxInputModeDecimal:
|
||||
mInputModeContraints =
|
||||
InputType.TYPE_CLASS_NUMBER |
|
||||
InputType.TYPE_NUMBER_FLAG_DECIMAL |
|
||||
InputType.TYPE_NUMBER_FLAG_SIGNED;
|
||||
break;
|
||||
case kEditBoxInputModeSingleLine:
|
||||
mInputModeContraints = InputType.TYPE_CLASS_TEXT;
|
||||
break;
|
||||
default:
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if ( mIsMultiline ) {
|
||||
mInputModeContraints |= InputType.TYPE_TEXT_FLAG_MULTI_LINE;
|
||||
}
|
||||
|
||||
mInputEditText.setInputType(mInputModeContraints | mInputFlagConstraints);
|
||||
|
||||
switch (mInputFlag)
|
||||
{
|
||||
case kEditBoxInputFlagPassword:
|
||||
mInputFlagConstraints = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD;
|
||||
break;
|
||||
case kEditBoxInputFlagSensitive:
|
||||
mInputFlagConstraints = InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS;
|
||||
break;
|
||||
case kEditBoxInputFlagInitialCapsWord:
|
||||
mInputFlagConstraints = InputType.TYPE_TEXT_FLAG_CAP_WORDS;
|
||||
break;
|
||||
case kEditBoxInputFlagInitialCapsSentence:
|
||||
mInputFlagConstraints = InputType.TYPE_TEXT_FLAG_CAP_SENTENCES;
|
||||
break;
|
||||
case kEditBoxInputFlagInitialCapsAllCharacters:
|
||||
mInputFlagConstraints = InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
mInputEditText.setInputType(mInputFlagConstraints | mInputModeContraints);
|
||||
|
||||
switch (mReturnType) {
|
||||
case kKeyboardReturnTypeDefault:
|
||||
mInputEditText.setImeOptions(oldImeOptions | EditorInfo.IME_ACTION_NONE);
|
||||
break;
|
||||
case kKeyboardReturnTypeDone:
|
||||
mInputEditText.setImeOptions(oldImeOptions | EditorInfo.IME_ACTION_DONE);
|
||||
break;
|
||||
case kKeyboardReturnTypeSend:
|
||||
mInputEditText.setImeOptions(oldImeOptions | EditorInfo.IME_ACTION_SEND);
|
||||
break;
|
||||
case kKeyboardReturnTypeSearch:
|
||||
mInputEditText.setImeOptions(oldImeOptions | EditorInfo.IME_ACTION_SEARCH);
|
||||
break;
|
||||
case kKeyboardReturnTypeGo:
|
||||
mInputEditText.setImeOptions(oldImeOptions | EditorInfo.IME_ACTION_GO);
|
||||
break;
|
||||
default:
|
||||
mInputEditText.setImeOptions(oldImeOptions | EditorInfo.IME_ACTION_NONE);
|
||||
break;
|
||||
}
|
||||
|
||||
if (mMaxLength > 0) {
|
||||
mInputEditText.setFilters(
|
||||
new InputFilter[] {
|
||||
new InputFilter.LengthFilter(mMaxLength)
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
Handler initHandler = new Handler();
|
||||
initHandler.postDelayed(new Runnable() {
|
||||
public void run() {
|
||||
mInputEditText.requestFocus();
|
||||
mInputEditText.setSelection(mInputEditText.length());
|
||||
openKeyboard();
|
||||
}
|
||||
}, 200);
|
||||
|
||||
mInputEditText.setOnEditorActionListener(new OnEditorActionListener() {
|
||||
@Override
|
||||
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
|
||||
// if user didn't set keyboard type,
|
||||
// this callback will be invoked twice with 'KeyEvent.ACTION_DOWN' and 'KeyEvent.ACTION_UP'
|
||||
if (actionId != EditorInfo.IME_NULL
|
||||
|| (actionId == EditorInfo.IME_NULL
|
||||
&& event != null
|
||||
&& event.getAction() == KeyEvent.ACTION_DOWN))
|
||||
{
|
||||
//Log.d("EditBox", "actionId: "+actionId +",event: "+event);
|
||||
mParentActivity.setEditBoxResult(mInputEditText.getText().toString());
|
||||
closeKeyboard();
|
||||
dismiss();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void openKeyboard() {
|
||||
InputMethodManager imm = (InputMethodManager) mParentActivity.getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
imm.showSoftInput(mInputEditText, 0);
|
||||
Log.d("Cocos2dxEditBox", "openKeyboard");
|
||||
}
|
||||
|
||||
private void closeKeyboard() {
|
||||
InputMethodManager imm = (InputMethodManager) mParentActivity.getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
imm.hideSoftInputFromWindow(mInputEditText.getWindowToken(), 0);
|
||||
Log.d("Cocos2dxEditBox", "closeKeyboard");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
// TODO Auto-generated method stub
|
||||
super.onStop();
|
||||
Log.d("EditBox", "onStop...");
|
||||
}
|
||||
}
|
|
@ -1,65 +0,0 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2012 cocos2d-x.org
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
package org.cocos2dx.lib;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.KeyEvent;
|
||||
import android.widget.EditText;
|
||||
|
||||
public class Cocos2dxEditText extends EditText {
|
||||
|
||||
private Cocos2dxGLSurfaceView mView;
|
||||
|
||||
public Cocos2dxEditText(Context context) {
|
||||
super(context);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
public Cocos2dxEditText(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
public Cocos2dxEditText(Context context, AttributeSet attrs, int defStyle) {
|
||||
super(context, attrs, defStyle);
|
||||
}
|
||||
|
||||
public void setMainView(Cocos2dxGLSurfaceView glSurfaceView) {
|
||||
mView = glSurfaceView;
|
||||
}
|
||||
|
||||
/*
|
||||
* Let GlSurfaceView get focus if back key is input
|
||||
*/
|
||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||
super.onKeyDown(keyCode, event);
|
||||
|
||||
if (keyCode == KeyEvent.KEYCODE_BACK) {
|
||||
mView.requestFocus();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -1,417 +0,0 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2010-2011 cocos2d-x.org
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
package org.cocos2dx.lib;
|
||||
|
||||
import android.content.Context;
|
||||
import android.opengl.GLSurfaceView;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.text.Editable;
|
||||
import android.text.TextWatcher;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.TextView;
|
||||
import android.widget.TextView.OnEditorActionListener;
|
||||
|
||||
class TextInputWraper implements TextWatcher, OnEditorActionListener {
|
||||
|
||||
private static final Boolean debug = false;
|
||||
private void LogD(String msg) {
|
||||
if (debug) Log.d("TextInputFilter", msg);
|
||||
}
|
||||
|
||||
private Cocos2dxGLSurfaceView mMainView;
|
||||
private String mText;
|
||||
private String mOriginText;
|
||||
|
||||
private Boolean isFullScreenEdit() {
|
||||
InputMethodManager imm = (InputMethodManager)mMainView.getTextField().getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
return imm.isFullscreenMode();
|
||||
}
|
||||
|
||||
public TextInputWraper(Cocos2dxGLSurfaceView view) {
|
||||
mMainView = view;
|
||||
}
|
||||
|
||||
public void setOriginText(String text) {
|
||||
mOriginText = text;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
if (isFullScreenEdit()) {
|
||||
return;
|
||||
}
|
||||
|
||||
LogD("afterTextChanged: " + s);
|
||||
int nModified = s.length() - mText.length();
|
||||
if (nModified > 0) {
|
||||
final String insertText = s.subSequence(mText.length(), s.length()).toString();
|
||||
mMainView.insertText(insertText);
|
||||
LogD("insertText(" + insertText + ")");
|
||||
}
|
||||
else {
|
||||
for (; nModified < 0; ++nModified) {
|
||||
mMainView.deleteBackward();
|
||||
LogD("deleteBackward");
|
||||
}
|
||||
}
|
||||
mText = s.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count,
|
||||
int after) {
|
||||
LogD("beforeTextChanged(" + s + ")start: " + start + ",count: " + count + ",after: " + after);
|
||||
mText = s.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
|
||||
if (mMainView.getTextField() == v && isFullScreenEdit()) {
|
||||
// user press the action button, delete all old text and insert new text
|
||||
for (int i = mOriginText.length(); i > 0; --i) {
|
||||
mMainView.deleteBackward();
|
||||
LogD("deleteBackward");
|
||||
}
|
||||
String text = v.getText().toString();
|
||||
|
||||
/*
|
||||
* If user input nothing, translate "\n" to engine.
|
||||
*/
|
||||
if (text.compareTo("") == 0){
|
||||
text = "\n";
|
||||
}
|
||||
|
||||
if ('\n' != text.charAt(text.length() - 1)) {
|
||||
text += '\n';
|
||||
}
|
||||
|
||||
final String insertText = text;
|
||||
mMainView.insertText(insertText);
|
||||
LogD("insertText(" + insertText + ")");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public class Cocos2dxGLSurfaceView extends GLSurfaceView {
|
||||
|
||||
static private Cocos2dxGLSurfaceView mainView;
|
||||
|
||||
private static final String TAG = Cocos2dxGLSurfaceView.class.getCanonicalName();
|
||||
private Cocos2dxRenderer mRenderer;
|
||||
|
||||
private static final boolean debug = false;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// for initialize
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
public Cocos2dxGLSurfaceView(Context context) {
|
||||
super(context);
|
||||
initView();
|
||||
}
|
||||
|
||||
public Cocos2dxGLSurfaceView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
initView();
|
||||
}
|
||||
|
||||
public void setCocos2dxRenderer(Cocos2dxRenderer renderer){
|
||||
mRenderer = renderer;
|
||||
setRenderer(mRenderer);
|
||||
}
|
||||
|
||||
protected void initView() {
|
||||
setFocusableInTouchMode(true);
|
||||
|
||||
textInputWraper = new TextInputWraper(this);
|
||||
|
||||
handler = new Handler(){
|
||||
public void handleMessage(Message msg){
|
||||
switch(msg.what){
|
||||
case HANDLER_OPEN_IME_KEYBOARD:
|
||||
if (null != mTextField && mTextField.requestFocus()) {
|
||||
mTextField.removeTextChangedListener(textInputWraper);
|
||||
mTextField.setText("");
|
||||
String text = (String)msg.obj;
|
||||
mTextField.append(text);
|
||||
textInputWraper.setOriginText(text);
|
||||
mTextField.addTextChangedListener(textInputWraper);
|
||||
InputMethodManager imm = (InputMethodManager)mainView.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
imm.showSoftInput(mTextField, 0);
|
||||
Log.d("GLSurfaceView", "showSoftInput");
|
||||
}
|
||||
break;
|
||||
|
||||
case HANDLER_CLOSE_IME_KEYBOARD:
|
||||
if (null != mTextField) {
|
||||
mTextField.removeTextChangedListener(textInputWraper);
|
||||
InputMethodManager imm = (InputMethodManager)mainView.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
imm.hideSoftInputFromWindow(mTextField.getWindowToken(), 0);
|
||||
Log.d("GLSurfaceView", "HideSoftInput");
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
mainView = this;
|
||||
}
|
||||
|
||||
public void onPause(){
|
||||
queueEvent(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mRenderer.handleOnPause();
|
||||
}
|
||||
});
|
||||
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
public void onResume(){
|
||||
super.onResume();
|
||||
|
||||
queueEvent(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mRenderer.handleOnResume();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// for text input
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
private final static int HANDLER_OPEN_IME_KEYBOARD = 2;
|
||||
private final static int HANDLER_CLOSE_IME_KEYBOARD = 3;
|
||||
private static Handler handler;
|
||||
private static TextInputWraper textInputWraper;
|
||||
private Cocos2dxEditText mTextField;
|
||||
|
||||
public TextView getTextField() {
|
||||
return mTextField;
|
||||
}
|
||||
|
||||
public void setTextField(Cocos2dxEditText view) {
|
||||
mTextField = view;
|
||||
if (null != mTextField && null != textInputWraper) {
|
||||
mTextField.setOnEditorActionListener(textInputWraper);
|
||||
mTextField.setMainView(this);
|
||||
this.requestFocus();
|
||||
}
|
||||
}
|
||||
|
||||
public static void openIMEKeyboard() {
|
||||
Message msg = new Message();
|
||||
msg.what = HANDLER_OPEN_IME_KEYBOARD;
|
||||
msg.obj = mainView.getContentText();
|
||||
handler.sendMessage(msg);
|
||||
|
||||
}
|
||||
|
||||
private String getContentText() {
|
||||
return mRenderer.getContentText();
|
||||
}
|
||||
|
||||
public static void closeIMEKeyboard() {
|
||||
Message msg = new Message();
|
||||
msg.what = HANDLER_CLOSE_IME_KEYBOARD;
|
||||
handler.sendMessage(msg);
|
||||
}
|
||||
|
||||
public void insertText(final String text) {
|
||||
queueEvent(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mRenderer.handleInsertText(text);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void deleteBackward() {
|
||||
queueEvent(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mRenderer.handleDeleteBackward();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// for touch event
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public boolean onTouchEvent(final MotionEvent event) {
|
||||
// these data are used in ACTION_MOVE and ACTION_CANCEL
|
||||
final int pointerNumber = event.getPointerCount();
|
||||
final int[] ids = new int[pointerNumber];
|
||||
final float[] xs = new float[pointerNumber];
|
||||
final float[] ys = new float[pointerNumber];
|
||||
|
||||
for (int i = 0; i < pointerNumber; i++) {
|
||||
ids[i] = event.getPointerId(i);
|
||||
xs[i] = event.getX(i);
|
||||
ys[i] = event.getY(i);
|
||||
}
|
||||
|
||||
switch (event.getAction() & MotionEvent.ACTION_MASK) {
|
||||
case MotionEvent.ACTION_POINTER_DOWN:
|
||||
final int indexPointerDown = event.getAction() >> MotionEvent.ACTION_POINTER_ID_SHIFT;
|
||||
final int idPointerDown = event.getPointerId(indexPointerDown);
|
||||
final float xPointerDown = event.getX(indexPointerDown);
|
||||
final float yPointerDown = event.getY(indexPointerDown);
|
||||
|
||||
queueEvent(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mRenderer.handleActionDown(idPointerDown, xPointerDown, yPointerDown);
|
||||
}
|
||||
});
|
||||
break;
|
||||
|
||||
case MotionEvent.ACTION_DOWN:
|
||||
// there are only one finger on the screen
|
||||
final int idDown = event.getPointerId(0);
|
||||
final float xDown = xs[0];
|
||||
final float yDown = ys[0];
|
||||
|
||||
queueEvent(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mRenderer.handleActionDown(idDown, xDown, yDown);
|
||||
}
|
||||
});
|
||||
break;
|
||||
|
||||
case MotionEvent.ACTION_MOVE:
|
||||
queueEvent(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mRenderer.handleActionMove(ids, xs, ys);
|
||||
}
|
||||
});
|
||||
break;
|
||||
|
||||
case MotionEvent.ACTION_POINTER_UP:
|
||||
final int indexPointUp = event.getAction() >> MotionEvent.ACTION_POINTER_ID_SHIFT;
|
||||
final int idPointerUp = event.getPointerId(indexPointUp);
|
||||
final float xPointerUp = event.getX(indexPointUp);
|
||||
final float yPointerUp = event.getY(indexPointUp);
|
||||
|
||||
queueEvent(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mRenderer.handleActionUp(idPointerUp, xPointerUp, yPointerUp);
|
||||
}
|
||||
});
|
||||
break;
|
||||
|
||||
case MotionEvent.ACTION_UP:
|
||||
// there are only one finger on the screen
|
||||
final int idUp = event.getPointerId(0);
|
||||
final float xUp = xs[0];
|
||||
final float yUp = ys[0];
|
||||
|
||||
queueEvent(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mRenderer.handleActionUp(idUp, xUp, yUp);
|
||||
}
|
||||
});
|
||||
break;
|
||||
|
||||
case MotionEvent.ACTION_CANCEL:
|
||||
queueEvent(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mRenderer.handleActionCancel(ids, xs, ys);
|
||||
}
|
||||
});
|
||||
break;
|
||||
}
|
||||
|
||||
if (debug){
|
||||
dumpEvent(event);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* This function is called before Cocos2dxRenderer.nativeInit(), so the width and height is correct.
|
||||
*/
|
||||
protected void onSizeChanged(int w, int h, int oldw, int oldh){
|
||||
this.mRenderer.setScreenWidthAndHeight(w, h);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||
final int kc = keyCode;
|
||||
if (keyCode == KeyEvent.KEYCODE_BACK || keyCode == KeyEvent.KEYCODE_MENU) {
|
||||
queueEvent(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mRenderer.handleKeyDown(kc);
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
return super.onKeyDown(keyCode, event);
|
||||
}
|
||||
|
||||
// Show an event in the LogCat view, for debugging
|
||||
private void dumpEvent(MotionEvent event) {
|
||||
String names[] = { "DOWN" , "UP" , "MOVE" , "CANCEL" , "OUTSIDE" ,
|
||||
"POINTER_DOWN" , "POINTER_UP" , "7?" , "8?" , "9?" };
|
||||
StringBuilder sb = new StringBuilder();
|
||||
int action = event.getAction();
|
||||
int actionCode = action & MotionEvent.ACTION_MASK;
|
||||
sb.append("event ACTION_" ).append(names[actionCode]);
|
||||
if (actionCode == MotionEvent.ACTION_POINTER_DOWN
|
||||
|| actionCode == MotionEvent.ACTION_POINTER_UP) {
|
||||
sb.append("(pid " ).append(
|
||||
action >> MotionEvent.ACTION_POINTER_ID_SHIFT);
|
||||
sb.append(")" );
|
||||
}
|
||||
sb.append("[" );
|
||||
for (int i = 0; i < event.getPointerCount(); i++) {
|
||||
sb.append("#" ).append(i);
|
||||
sb.append("(pid " ).append(event.getPointerId(i));
|
||||
sb.append(")=" ).append((int) event.getX(i));
|
||||
sb.append("," ).append((int) event.getY(i));
|
||||
if (i + 1 < event.getPointerCount())
|
||||
sb.append(";" );
|
||||
}
|
||||
sb.append("]" );
|
||||
Log.d(TAG, sb.toString());
|
||||
}
|
||||
}
|
|
@ -1,228 +0,0 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2010-2011 cocos2d-x.org
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
package org.cocos2dx.lib;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.AssetFileDescriptor;
|
||||
import android.media.MediaPlayer;
|
||||
import android.util.Log;
|
||||
|
||||
/**
|
||||
*
|
||||
* This class is used for controlling background music
|
||||
*
|
||||
*/
|
||||
public class Cocos2dxMusic {
|
||||
|
||||
private static final String TAG = "Cocos2dxMusic";
|
||||
private float mLeftVolume;
|
||||
private float mRightVolume;
|
||||
private Context mContext;
|
||||
private MediaPlayer mBackgroundMediaPlayer;
|
||||
private boolean mIsPaused;
|
||||
private String mCurrentPath;
|
||||
|
||||
public Cocos2dxMusic(Context context){
|
||||
this.mContext = context;
|
||||
initData();
|
||||
}
|
||||
|
||||
public void preloadBackgroundMusic(String path){
|
||||
if ((mCurrentPath == null) || (! mCurrentPath.equals(path))){
|
||||
// preload new background music
|
||||
|
||||
// release old resource and create a new one
|
||||
if (mBackgroundMediaPlayer != null){
|
||||
mBackgroundMediaPlayer.release();
|
||||
}
|
||||
|
||||
mBackgroundMediaPlayer = createMediaplayerFromAssets(path);
|
||||
|
||||
// record the path
|
||||
mCurrentPath = path;
|
||||
}
|
||||
}
|
||||
|
||||
public void playBackgroundMusic(String path, boolean isLoop){
|
||||
if (mCurrentPath == null){
|
||||
// it is the first time to play background music
|
||||
// or end() was called
|
||||
mBackgroundMediaPlayer = createMediaplayerFromAssets(path);
|
||||
mCurrentPath = path;
|
||||
}
|
||||
else {
|
||||
if (! mCurrentPath.equals(path)){
|
||||
// play new background music
|
||||
|
||||
// release old resource and create a new one
|
||||
if (mBackgroundMediaPlayer != null){
|
||||
mBackgroundMediaPlayer.release();
|
||||
}
|
||||
mBackgroundMediaPlayer = createMediaplayerFromAssets(path);
|
||||
|
||||
// record the path
|
||||
mCurrentPath = path;
|
||||
}
|
||||
}
|
||||
|
||||
if (mBackgroundMediaPlayer == null){
|
||||
Log.e(TAG, "playBackgroundMusic: background media player is null");
|
||||
} else {
|
||||
// if the music is playing or paused, stop it
|
||||
mBackgroundMediaPlayer.stop();
|
||||
|
||||
mBackgroundMediaPlayer.setLooping(isLoop);
|
||||
|
||||
try {
|
||||
mBackgroundMediaPlayer.prepare();
|
||||
mBackgroundMediaPlayer.seekTo(0);
|
||||
mBackgroundMediaPlayer.start();
|
||||
|
||||
this.mIsPaused = false;
|
||||
} catch (Exception e){
|
||||
Log.e(TAG, "playBackgroundMusic: error state");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void stopBackgroundMusic(){
|
||||
if (mBackgroundMediaPlayer != null){
|
||||
mBackgroundMediaPlayer.stop();
|
||||
|
||||
// should set the state, if not , the following sequence will be error
|
||||
// play -> pause -> stop -> resume
|
||||
this.mIsPaused = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void pauseBackgroundMusic(){
|
||||
if (mBackgroundMediaPlayer != null && mBackgroundMediaPlayer.isPlaying()){
|
||||
mBackgroundMediaPlayer.pause();
|
||||
this.mIsPaused = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void resumeBackgroundMusic(){
|
||||
if (mBackgroundMediaPlayer != null && this.mIsPaused){
|
||||
mBackgroundMediaPlayer.start();
|
||||
this.mIsPaused = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void rewindBackgroundMusic(){
|
||||
if (mBackgroundMediaPlayer != null){
|
||||
mBackgroundMediaPlayer.stop();
|
||||
|
||||
try {
|
||||
mBackgroundMediaPlayer.prepare();
|
||||
mBackgroundMediaPlayer.seekTo(0);
|
||||
mBackgroundMediaPlayer.start();
|
||||
|
||||
this.mIsPaused = false;
|
||||
} catch (Exception e){
|
||||
Log.e(TAG, "rewindBackgroundMusic: error state");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isBackgroundMusicPlaying(){
|
||||
boolean ret = false;
|
||||
|
||||
if (mBackgroundMediaPlayer == null){
|
||||
ret = false;
|
||||
} else {
|
||||
ret = mBackgroundMediaPlayer.isPlaying();
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public void end(){
|
||||
if (mBackgroundMediaPlayer != null){
|
||||
mBackgroundMediaPlayer.release();
|
||||
}
|
||||
|
||||
initData();
|
||||
}
|
||||
|
||||
public float getBackgroundVolume(){
|
||||
if (this.mBackgroundMediaPlayer != null){
|
||||
return (this.mLeftVolume + this.mRightVolume) / 2;
|
||||
} else {
|
||||
return 0.0f;
|
||||
}
|
||||
}
|
||||
|
||||
public void setBackgroundVolume(float volume){
|
||||
if (volume < 0.0f){
|
||||
volume = 0.0f;
|
||||
}
|
||||
|
||||
if (volume > 1.0f){
|
||||
volume = 1.0f;
|
||||
}
|
||||
|
||||
this.mLeftVolume = this.mRightVolume = volume;
|
||||
if (this.mBackgroundMediaPlayer != null){
|
||||
this.mBackgroundMediaPlayer.setVolume(this.mLeftVolume, this.mRightVolume);
|
||||
}
|
||||
}
|
||||
|
||||
private void initData(){
|
||||
mLeftVolume =0.5f;
|
||||
mRightVolume = 0.5f;
|
||||
mBackgroundMediaPlayer = null;
|
||||
mIsPaused = false;
|
||||
mCurrentPath = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* create mediaplayer for music
|
||||
* @param path the path relative to assets
|
||||
* @return
|
||||
*/
|
||||
private MediaPlayer createMediaplayerFromAssets(String path){
|
||||
MediaPlayer mediaPlayer = new MediaPlayer();
|
||||
|
||||
try{
|
||||
if (path.startsWith("/")) {
|
||||
mediaPlayer.setDataSource(path);
|
||||
}
|
||||
else {
|
||||
AssetFileDescriptor assetFileDescritor = mContext.getAssets().openFd(path);
|
||||
mediaPlayer.setDataSource(assetFileDescritor.getFileDescriptor(),
|
||||
assetFileDescritor.getStartOffset(), assetFileDescritor.getLength());
|
||||
}
|
||||
|
||||
mediaPlayer.prepare();
|
||||
|
||||
mediaPlayer.setVolume(mLeftVolume, mRightVolume);
|
||||
}catch (Exception e) {
|
||||
mediaPlayer = null;
|
||||
Log.e(TAG, "error: " + e.getMessage(), e);
|
||||
}
|
||||
|
||||
return mediaPlayer;
|
||||
}
|
||||
}
|
|
@ -1,137 +0,0 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2010-2011 cocos2d-x.org
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
package org.cocos2dx.lib;
|
||||
|
||||
import javax.microedition.khronos.egl.EGLConfig;
|
||||
import javax.microedition.khronos.opengles.GL10;
|
||||
|
||||
import android.opengl.GLSurfaceView;
|
||||
|
||||
public class Cocos2dxRenderer implements GLSurfaceView.Renderer {
|
||||
private final static long NANOSECONDSPERSECOND = 1000000000L;
|
||||
private final static long NANOSECONDSPERMINISECOND = 1000000;
|
||||
private static long animationInterval = (long)(1.0 / 60 * NANOSECONDSPERSECOND);
|
||||
private long last;
|
||||
private int screenWidth;
|
||||
private int screenHeight;
|
||||
|
||||
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
|
||||
nativeInit(screenWidth, screenHeight);
|
||||
last = System.nanoTime();
|
||||
}
|
||||
|
||||
public void setScreenWidthAndHeight(int w, int h){
|
||||
this.screenWidth = w;
|
||||
this.screenHeight = h;
|
||||
}
|
||||
|
||||
public void onSurfaceChanged(GL10 gl, int w, int h) {
|
||||
}
|
||||
|
||||
public void onDrawFrame(GL10 gl) {
|
||||
|
||||
long now = System.nanoTime();
|
||||
long interval = now - last;
|
||||
|
||||
// should render a frame when onDrawFrame() is called
|
||||
// or there is a "ghost"
|
||||
nativeRender();
|
||||
|
||||
// fps controlling
|
||||
if (interval < animationInterval){
|
||||
try {
|
||||
// because we render it before, so we should sleep twice time interval
|
||||
Thread.sleep((animationInterval - interval) * 2 / NANOSECONDSPERMINISECOND);
|
||||
} catch (Exception e){}
|
||||
}
|
||||
|
||||
last = now;
|
||||
}
|
||||
|
||||
public void handleActionDown(int id, float x, float y)
|
||||
{
|
||||
nativeTouchesBegin(id, x, y);
|
||||
}
|
||||
|
||||
public void handleActionUp(int id, float x, float y)
|
||||
{
|
||||
nativeTouchesEnd(id, x, y);
|
||||
}
|
||||
|
||||
public void handleActionCancel(int[] id, float[] x, float[] y)
|
||||
{
|
||||
nativeTouchesCancel(id, x, y);
|
||||
}
|
||||
|
||||
public void handleActionMove(int[] id, float[] x, float[] y)
|
||||
{
|
||||
nativeTouchesMove(id, x, y);
|
||||
}
|
||||
|
||||
public void handleKeyDown(int keyCode)
|
||||
{
|
||||
nativeKeyDown(keyCode);
|
||||
}
|
||||
|
||||
public void handleOnPause(){
|
||||
nativeOnPause();
|
||||
}
|
||||
|
||||
public void handleOnResume(){
|
||||
nativeOnResume();
|
||||
}
|
||||
|
||||
public static void setAnimationInterval(double interval){
|
||||
animationInterval = (long)(interval * NANOSECONDSPERSECOND);
|
||||
}
|
||||
private static native void nativeTouchesBegin(int id, float x, float y);
|
||||
private static native void nativeTouchesEnd(int id, float x, float y);
|
||||
private static native void nativeTouchesMove(int[] id, float[] x, float[] y);
|
||||
private static native void nativeTouchesCancel(int[] id, float[] x, float[] y);
|
||||
private static native boolean nativeKeyDown(int keyCode);
|
||||
private static native void nativeRender();
|
||||
private static native void nativeInit(int w, int h);
|
||||
private static native void nativeOnPause();
|
||||
private static native void nativeOnResume();
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
// handle input method edit message
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public void handleInsertText(final String text) {
|
||||
nativeInsertText(text);
|
||||
}
|
||||
|
||||
public void handleDeleteBackward() {
|
||||
nativeDeleteBackward();
|
||||
}
|
||||
|
||||
public String getContentText() {
|
||||
return nativeGetContentText();
|
||||
}
|
||||
|
||||
private static native void nativeInsertText(String text);
|
||||
private static native void nativeDeleteBackward();
|
||||
private static native String nativeGetContentText();
|
||||
}
|
|
@ -1,245 +0,0 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2010-2011 cocos2d-x.org
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
package org.cocos2dx.lib;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
import android.content.Context;
|
||||
import android.media.AudioManager;
|
||||
import android.media.SoundPool;
|
||||
import android.util.Log;
|
||||
|
||||
/**
|
||||
*
|
||||
* This class is used for controlling effect
|
||||
*
|
||||
*/
|
||||
|
||||
public class Cocos2dxSound {
|
||||
private Context mContext;
|
||||
private SoundPool mSoundPool;
|
||||
private float mLeftVolume;
|
||||
private float mRightVolume;
|
||||
|
||||
// sound path and stream ids map
|
||||
// a file may be played many times at the same time
|
||||
// so there is an array map to a file path
|
||||
private HashMap<String,ArrayList<Integer>> mPathStreamIDsMap;
|
||||
|
||||
private HashMap<String, Integer> mPathSoundIdMap;
|
||||
|
||||
private static final String TAG = "Cocos2dxSound";
|
||||
private static final int MAX_SIMULTANEOUS_STREAMS_DEFAULT = 5;
|
||||
private static final float SOUND_RATE = 1.0f;
|
||||
private static final int SOUND_PRIORITY = 1;
|
||||
private static final int SOUND_QUALITY = 5;
|
||||
|
||||
private final static int INVALID_SOUND_ID = -1;
|
||||
private final static int INVALID_STREAM_ID = -1;
|
||||
|
||||
public Cocos2dxSound(Context context){
|
||||
this.mContext = context;
|
||||
initData();
|
||||
}
|
||||
|
||||
public int preloadEffect(String path){
|
||||
Integer soundID = this.mPathSoundIdMap.get(path);
|
||||
|
||||
if (soundID == null) {
|
||||
soundID = createSoundIdFromAsset(path);
|
||||
this.mPathSoundIdMap.put(path, soundID);
|
||||
}
|
||||
|
||||
return soundID;
|
||||
}
|
||||
|
||||
public void unloadEffect(String path){
|
||||
// stop effects
|
||||
ArrayList<Integer> streamIDs = this.mPathStreamIDsMap.get(path);
|
||||
if (streamIDs != null) {
|
||||
for (Integer streamID : streamIDs) {
|
||||
this.mSoundPool.stop(streamID);
|
||||
}
|
||||
}
|
||||
this.mPathStreamIDsMap.remove(path);
|
||||
|
||||
// unload effect
|
||||
Integer soundID = this.mPathSoundIdMap.get(path);
|
||||
this.mSoundPool.unload(soundID);
|
||||
this.mPathSoundIdMap.remove(path);
|
||||
}
|
||||
|
||||
public int playEffect(String path, boolean isLoop){
|
||||
Integer soundId = this.mPathSoundIdMap.get(path);
|
||||
int streamId = INVALID_STREAM_ID;
|
||||
|
||||
if (soundId != null){
|
||||
// play sound
|
||||
streamId = this.mSoundPool.play(soundId.intValue(), this.mLeftVolume,
|
||||
this.mRightVolume, SOUND_PRIORITY, isLoop ? -1 : 0, SOUND_RATE);
|
||||
|
||||
// record stream id
|
||||
ArrayList<Integer> streamIds = this.mPathStreamIDsMap.get(path);
|
||||
if (streamIds == null) {
|
||||
streamIds = new ArrayList<Integer>();
|
||||
this.mPathStreamIDsMap.put(path, streamIds);
|
||||
}
|
||||
streamIds.add(streamId);
|
||||
} else {
|
||||
// the effect is not prepared
|
||||
soundId = preloadEffect(path);
|
||||
if (soundId == INVALID_SOUND_ID){
|
||||
// can not preload effect
|
||||
return INVALID_SOUND_ID;
|
||||
}
|
||||
|
||||
/*
|
||||
* Someone reports that, it can not play effect for the
|
||||
* first time. If you are lucky to meet it. There are two
|
||||
* ways to resolve it.
|
||||
* 1. Add some delay here. I don't know how long it is, so
|
||||
* I don't add it here.
|
||||
* 2. If you use 2.2(API level 8), you can call
|
||||
* SoundPool.setOnLoadCompleteListener() to play the effect.
|
||||
* Because the method is supported from 2.2, so I can't use
|
||||
* it here.
|
||||
*/
|
||||
playEffect(path, isLoop);
|
||||
}
|
||||
|
||||
return streamId;
|
||||
}
|
||||
|
||||
public void stopEffect(int streamID){
|
||||
this.mSoundPool.stop(streamID);
|
||||
|
||||
// remove record
|
||||
for (String path : this.mPathStreamIDsMap.keySet()) {
|
||||
if (this.mPathStreamIDsMap.get(path).contains(streamID)) {
|
||||
this.mPathStreamIDsMap.get(path).remove(this.mPathStreamIDsMap.get(path).indexOf(streamID));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void pauseEffect(int streamID){
|
||||
this.mSoundPool.pause(streamID);
|
||||
}
|
||||
|
||||
public void resumeEffect(int streamID){
|
||||
this.mSoundPool.resume(streamID);
|
||||
}
|
||||
|
||||
public void pauseAllEffects(){
|
||||
this.mSoundPool.autoPause();
|
||||
}
|
||||
|
||||
public void resumeAllEffects(){
|
||||
// autoPause() is available since level 8
|
||||
this.mSoundPool.autoResume();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void stopAllEffects(){
|
||||
// stop effects
|
||||
if (! this.mPathStreamIDsMap.isEmpty()) {
|
||||
Iterator<?> iter = this.mPathStreamIDsMap.entrySet().iterator();
|
||||
while (iter.hasNext()){
|
||||
Map.Entry<String, ArrayList<Integer>> entry = (Map.Entry<String, ArrayList<Integer>>)iter.next();
|
||||
for (int streamID : entry.getValue()) {
|
||||
this.mSoundPool.stop(streamID);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// remove records
|
||||
this.mPathStreamIDsMap.clear();
|
||||
}
|
||||
|
||||
public float getEffectsVolume(){
|
||||
return (this.mLeftVolume + this.mRightVolume) / 2;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void setEffectsVolume(float volume){
|
||||
// volume should be in [0, 1.0]
|
||||
if (volume < 0){
|
||||
volume = 0;
|
||||
}
|
||||
if (volume > 1){
|
||||
volume = 1;
|
||||
}
|
||||
|
||||
this.mLeftVolume = this.mRightVolume = volume;
|
||||
|
||||
// change the volume of playing sounds
|
||||
if (! this.mPathStreamIDsMap.isEmpty()) {
|
||||
Iterator<?> iter = this.mPathStreamIDsMap.entrySet().iterator();
|
||||
while (iter.hasNext()){
|
||||
Map.Entry<String, ArrayList<Integer>> entry = (Map.Entry<String, ArrayList<Integer>>)iter.next();
|
||||
for (int streamID : entry.getValue()) {
|
||||
this.mSoundPool.setVolume(streamID, mLeftVolume, mRightVolume);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void end(){
|
||||
this.mSoundPool.release();
|
||||
this.mPathStreamIDsMap.clear();
|
||||
this.mPathSoundIdMap.clear();
|
||||
|
||||
initData();
|
||||
}
|
||||
|
||||
public int createSoundIdFromAsset(String path){
|
||||
int soundId = INVALID_SOUND_ID;
|
||||
|
||||
try {
|
||||
if (path.startsWith("/")){
|
||||
soundId = mSoundPool.load(path, 0);
|
||||
}
|
||||
else {
|
||||
soundId = mSoundPool.load(mContext.getAssets().openFd(path), 0);
|
||||
}
|
||||
} catch(Exception e){
|
||||
soundId = INVALID_SOUND_ID;
|
||||
Log.e(TAG, "error: " + e.getMessage(), e);
|
||||
}
|
||||
|
||||
return soundId;
|
||||
}
|
||||
|
||||
private void initData(){
|
||||
this.mPathStreamIDsMap = new HashMap<String,ArrayList<Integer>>();
|
||||
this.mPathSoundIdMap = new HashMap<String, Integer>();
|
||||
mSoundPool = new SoundPool(MAX_SIMULTANEOUS_STREAMS_DEFAULT, AudioManager.STREAM_MUSIC, SOUND_QUALITY);
|
||||
|
||||
this.mLeftVolume = 0.5f;
|
||||
this.mRightVolume = 0.5f;
|
||||
}
|
||||
}
|
|
@ -1,44 +0,0 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2010-2011 cocos2d-x.org
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
package org.cocos2dx.lib;
|
||||
|
||||
import java.util.Hashtable;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Typeface;
|
||||
|
||||
public class Cocos2dxTypefaces {
|
||||
private static final Hashtable<String, Typeface> cache = new Hashtable<String, Typeface>();
|
||||
|
||||
public static Typeface get(Context context, String name){
|
||||
synchronized(cache){
|
||||
if (! cache.containsKey(name)){
|
||||
Typeface t = Typeface.createFromAsset(context.getAssets(), name);
|
||||
cache.put(name, t);
|
||||
}
|
||||
|
||||
return cache.get(name);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,108 +0,0 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2010-2012 cocos2d-x.org
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
package org.cocos2dx.simplegame;
|
||||
|
||||
import org.cocos2dx.lib.Cocos2dxActivity;
|
||||
import org.cocos2dx.lib.Cocos2dxEditText;
|
||||
import org.cocos2dx.lib.Cocos2dxGLSurfaceView;
|
||||
import org.cocos2dx.lib.Cocos2dxRenderer;
|
||||
|
||||
import android.app.ActivityManager;
|
||||
import android.content.Context;
|
||||
import android.content.pm.ConfigurationInfo;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.widget.FrameLayout;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
public class SimpleGame extends Cocos2dxActivity{
|
||||
|
||||
protected void onCreate(Bundle savedInstanceState){
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
if (detectOpenGLES20()) {
|
||||
// get the packageName,it's used to set the resource path
|
||||
String packageName = getApplication().getPackageName();
|
||||
super.setPackageName(packageName);
|
||||
|
||||
// FrameLayout
|
||||
ViewGroup.LayoutParams framelayout_params =
|
||||
new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
|
||||
ViewGroup.LayoutParams.FILL_PARENT);
|
||||
FrameLayout framelayout = new FrameLayout(this);
|
||||
framelayout.setLayoutParams(framelayout_params);
|
||||
|
||||
// Cocos2dxEditText layout
|
||||
ViewGroup.LayoutParams edittext_layout_params =
|
||||
new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
|
||||
ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||
Cocos2dxEditText edittext = new Cocos2dxEditText(this);
|
||||
edittext.setLayoutParams(edittext_layout_params);
|
||||
|
||||
// ...add to FrameLayout
|
||||
framelayout.addView(edittext);
|
||||
|
||||
// Cocos2dxGLSurfaceView
|
||||
mGLView = new Cocos2dxGLSurfaceView(this);
|
||||
|
||||
// ...add to FrameLayout
|
||||
framelayout.addView(mGLView);
|
||||
|
||||
mGLView.setEGLContextClientVersion(2);
|
||||
mGLView.setCocos2dxRenderer(new Cocos2dxRenderer());
|
||||
mGLView.setTextField(edittext);
|
||||
|
||||
// Set framelayout as the content view
|
||||
setContentView(framelayout);
|
||||
}
|
||||
else {
|
||||
Log.d("activity", "don't support gles2.0");
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
mGLView.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
mGLView.onResume();
|
||||
}
|
||||
|
||||
private boolean detectOpenGLES20()
|
||||
{
|
||||
ActivityManager am =
|
||||
(ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
|
||||
ConfigurationInfo info = am.getDeviceConfigurationInfo();
|
||||
return (info.reqGlEsVersion >= 0x20000);
|
||||
}
|
||||
|
||||
static {
|
||||
System.loadLibrary("game");
|
||||
}
|
||||
}
|
|
@ -58,7 +58,7 @@ using the camera.
|
|||
|
||||
- It doesn't work on batched nodes like CCSprite objects when they are parented to a CCSpriteBatchNode object.
|
||||
|
||||
- It is recommended to use it ONLY if you are going to create 3D effects. For 2D effecs, use the action CCFollow or position/scale/rotate.
|
||||
- It is recommended to use it ONLY if you are going to create 3D effects. For 2D effects, use the action CCFollow or position/scale/rotate.
|
||||
|
||||
*/
|
||||
class CC_DLL CCCamera : public CCObject
|
||||
|
|
|
@ -70,7 +70,7 @@ using namespace std;
|
|||
unsigned int g_uNumberOfDraws = 0;
|
||||
|
||||
NS_CC_BEGIN
|
||||
// XXX it shoul be a Director ivar. Move it there once support for multiple directors is added
|
||||
// XXX it should be a Director ivar. Move it there once support for multiple directors is added
|
||||
|
||||
// singleton stuff
|
||||
static CCDisplayLinkDirector s_SharedDirector;
|
||||
|
@ -136,7 +136,7 @@ bool CCDirector::init(void)
|
|||
|
||||
m_pobOpenGLView = NULL;
|
||||
|
||||
m_fContentScaleFactor = 1;
|
||||
m_fContentScaleFactor = 1.0f;
|
||||
m_bIsContentScaleSupported = false;
|
||||
|
||||
// scheduler
|
||||
|
@ -200,7 +200,7 @@ void CCDirector::setGLDefaultValues(void)
|
|||
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
}
|
||||
|
||||
// Draw the SCene
|
||||
// Draw the Scene
|
||||
void CCDirector::drawScene(void)
|
||||
{
|
||||
// calculate "global" dt
|
||||
|
@ -290,16 +290,13 @@ void CCDirector::calculateDeltaTime(void)
|
|||
*m_pLastUpdate = now;
|
||||
}
|
||||
|
||||
|
||||
// m_pobOpenGLView
|
||||
|
||||
void CCDirector::setOpenGLView(CCEGLView *pobOpenGLView)
|
||||
{
|
||||
CCAssert(pobOpenGLView, "opengl view should not be null");
|
||||
|
||||
if (m_pobOpenGLView != pobOpenGLView)
|
||||
{
|
||||
// because EAGLView is not kind of CCObject
|
||||
// EAGLView is not a CCObject
|
||||
delete m_pobOpenGLView; // [openGLView_ release]
|
||||
m_pobOpenGLView = pobOpenGLView;
|
||||
|
||||
|
@ -591,6 +588,9 @@ void CCDirector::end()
|
|||
|
||||
void CCDirector::purgeDirector()
|
||||
{
|
||||
// cleanup scheduler
|
||||
getScheduler()->unscheduleAllSelectors();
|
||||
|
||||
// don't release the event handlers
|
||||
// They are needed in case the director is run again
|
||||
m_pTouchDispatcher->removeAllDelegates();
|
||||
|
@ -814,7 +814,7 @@ bool CCDirector::enableRetinaDisplay(bool enabled)
|
|||
return true;
|
||||
}
|
||||
|
||||
// Already diabled?
|
||||
// Already disabled?
|
||||
if (!enabled && m_fContentScaleFactor == 1)
|
||||
{
|
||||
return false;
|
||||
|
@ -942,7 +942,7 @@ CCAccelerometer* CCDirector::getAccelerometer()
|
|||
* implementation of DisplayLinkDirector
|
||||
**************************************************/
|
||||
|
||||
// should we afford 4 types of director ??
|
||||
// should we implement 4 types of director ??
|
||||
// I think DisplayLinkDirector is enough
|
||||
// so we now only support DisplayLinkDirector
|
||||
void CCDisplayLinkDirector::startAnimation(void)
|
||||
|
|
|
@ -58,7 +58,7 @@ typedef enum {
|
|||
/// it calls "updateProjection" on the projection delegate.
|
||||
kCCDirectorProjectionCustom,
|
||||
|
||||
/// Detault projection is 3D projection
|
||||
/// Default projection is 3D projection
|
||||
kCCDirectorProjectionDefault = kCCDirectorProjection3D,
|
||||
} ccDirectorProjection;
|
||||
|
||||
|
@ -83,7 +83,7 @@ and when to execute the Scenes.
|
|||
- setting the OpenGL pixel format (default on is RGB565)
|
||||
- setting the OpenGL buffer depth (default one is 0-bit)
|
||||
- setting the projection (default one is 3D)
|
||||
- setting the orientation (default one is Protrait)
|
||||
- setting the orientation (default one is Portrait)
|
||||
|
||||
Since the CCDirector is a singleton, the standard way to use it is by calling:
|
||||
_ CCDirector::sharedDirector()->methodName();
|
||||
|
|
|
@ -54,7 +54,7 @@ static void lazy_init( void )
|
|||
if( ! s_bInitialized ) {
|
||||
|
||||
//
|
||||
// Position and 1 color passed as a uniform (to similate glColor4ub )
|
||||
// Position and 1 color passed as a uniform (to simulate glColor4ub )
|
||||
//
|
||||
s_pShader = CCShaderCache::sharedShaderCache()->programForKey(kCCShader_Position_uColor);
|
||||
|
||||
|
@ -67,7 +67,7 @@ static void lazy_init( void )
|
|||
}
|
||||
}
|
||||
|
||||
// When back to foreground on android, we want to it to inilialize again
|
||||
// When switching from backround to foreground on android, we want the params to be initialized again
|
||||
void ccDrawInit()
|
||||
{
|
||||
s_bInitialized = false;
|
||||
|
|
|
@ -56,7 +56,7 @@ NS_CC_BEGIN
|
|||
|
||||
class CCPointArray;
|
||||
|
||||
/** initlialize context */
|
||||
/** initialize context */
|
||||
void CC_DLL ccDrawInit();
|
||||
|
||||
/** draws a point given x and y coordinate measured in points */
|
||||
|
@ -78,12 +78,12 @@ void CC_DLL ccDrawRect( CCPoint origin, CCPoint destination );
|
|||
*/
|
||||
void CC_DLL ccDrawSolidRect( CCPoint origin, CCPoint destination, ccColor4F color );
|
||||
|
||||
/** draws a poligon given a pointer to CCPoint coordiantes and the number of vertices measured in points.
|
||||
/** draws a polygon given a pointer to CCPoint coordinates and the number of vertices measured in points.
|
||||
The polygon can be closed or open
|
||||
*/
|
||||
void CC_DLL ccDrawPoly( const CCPoint *vertices, unsigned int numOfVertices, bool closePolygon );
|
||||
|
||||
/** draws a solid polygon given a pointer to CGPoint coordiantes, the number of vertices measured in points, and a color.
|
||||
/** 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 CCPoint *poli, unsigned int numberOfPoints, ccColor4F color );
|
||||
|
||||
|
|
|
@ -164,7 +164,7 @@ void CCTimer::update(float dt)
|
|||
|
||||
if (m_nScriptHandler)
|
||||
{
|
||||
CCScriptEngineManager::sharedManager()->getScriptEngine()->executeSchedule(m_nScriptHandler, m_fElapsed, NULL);
|
||||
CCScriptEngineManager::sharedManager()->getScriptEngine()->executeSchedule(this, m_fElapsed);
|
||||
}
|
||||
m_fElapsed = 0;
|
||||
}
|
||||
|
@ -183,7 +183,7 @@ void CCTimer::update(float dt)
|
|||
|
||||
if (m_nScriptHandler)
|
||||
{
|
||||
CCScriptEngineManager::sharedManager()->getScriptEngine()->executeSchedule(m_nScriptHandler, m_fElapsed, NULL);
|
||||
CCScriptEngineManager::sharedManager()->getScriptEngine()->executeSchedule(this, m_fElapsed);
|
||||
}
|
||||
|
||||
m_fElapsed = m_fElapsed - m_fDelay;
|
||||
|
@ -202,7 +202,7 @@ void CCTimer::update(float dt)
|
|||
|
||||
if (m_nScriptHandler)
|
||||
{
|
||||
CCScriptEngineManager::sharedManager()->getScriptEngine()->executeSchedule(m_nScriptHandler, m_fElapsed, NULL);
|
||||
CCScriptEngineManager::sharedManager()->getScriptEngine()->executeSchedule(this, m_fElapsed);
|
||||
}
|
||||
|
||||
m_fElapsed = 0;
|
||||
|
@ -375,7 +375,7 @@ void CCScheduler::priorityIn(tListEntry **ppList, CCObject *pTarget, int nPriori
|
|||
pListElement->next = pListElement->prev = NULL;
|
||||
pListElement->markedForDeletion = false;
|
||||
|
||||
// empey list ?
|
||||
// empty list ?
|
||||
if (! *ppList)
|
||||
{
|
||||
DL_APPEND(*ppList, pListElement);
|
||||
|
@ -610,14 +610,14 @@ void CCScheduler::unscheduleAllSelectorsForTarget(CCObject *pTarget)
|
|||
|
||||
unsigned int CCScheduler::scheduleScriptFunc(unsigned int nHandler, float fInterval, bool bPaused)
|
||||
{
|
||||
CCSchedulerScriptHandlerEntry* pEntry = CCSchedulerScriptHandlerEntry::entryWithHandler(nHandler, fInterval, bPaused);
|
||||
CCSchedulerScriptHandlerEntry* pEntry = CCSchedulerScriptHandlerEntry::create(nHandler, fInterval, bPaused);
|
||||
if (!m_pScriptHandlerEntries)
|
||||
{
|
||||
m_pScriptHandlerEntries = CCArray::createWithCapacity(20);
|
||||
m_pScriptHandlerEntries->retain();
|
||||
}
|
||||
m_pScriptHandlerEntries->addObject(pEntry);
|
||||
return pEntry->getEntryID();
|
||||
return pEntry->getEntryId();
|
||||
}
|
||||
|
||||
void CCScheduler::unscheduleScriptEntry(unsigned int uScheduleScriptEntryID)
|
||||
|
@ -625,7 +625,7 @@ void CCScheduler::unscheduleScriptEntry(unsigned int uScheduleScriptEntryID)
|
|||
for (int i = m_pScriptHandlerEntries->count() - 1; i >= 0; i--)
|
||||
{
|
||||
CCSchedulerScriptHandlerEntry* pEntry = static_cast<CCSchedulerScriptHandlerEntry*>(m_pScriptHandlerEntries->objectAtIndex(i));
|
||||
if (pEntry->getEntryID() == uScheduleScriptEntryID)
|
||||
if (pEntry->getEntryId() == uScheduleScriptEntryID)
|
||||
{
|
||||
pEntry->markedForDeletion();
|
||||
break;
|
||||
|
@ -763,7 +763,7 @@ void CCScheduler::update(float dt)
|
|||
dt *= m_fTimeScale;
|
||||
}
|
||||
|
||||
// Iterate all over the Updates selectors
|
||||
// Iterate over all the Updates' selectors
|
||||
tListEntry *pEntry, *pTmp;
|
||||
|
||||
// updates with priority < 0
|
||||
|
@ -783,7 +783,7 @@ void CCScheduler::update(float dt)
|
|||
CCScriptEngineProtocol* pEngine = CCScriptEngineManager::sharedManager()->getScriptEngine();
|
||||
if (pEngine != NULL && kScriptTypeJavascript == pEngine->getScriptType())
|
||||
{
|
||||
CCScriptEngineManager::sharedManager()->getScriptEngine()->executeSchedule(1, dt, (CCNode *)pEntry->target);
|
||||
CCScriptEngineManager::sharedManager()->getScriptEngine()->executeSchedule(NULL, dt, (CCNode *)pEntry->target);
|
||||
}
|
||||
|
||||
pEntry->target->update(dt);
|
||||
|
@ -799,7 +799,7 @@ void CCScheduler::update(float dt)
|
|||
}
|
||||
}
|
||||
|
||||
// Interate all over the custom selectors
|
||||
// Iterate over all the custom selectors
|
||||
for (tHashSelectorEntry *elt = m_pHashForSelectors; elt != NULL; )
|
||||
{
|
||||
m_pCurrentTarget = elt;
|
||||
|
@ -838,7 +838,7 @@ void CCScheduler::update(float dt)
|
|||
}
|
||||
}
|
||||
|
||||
// Interate all over the script callbacks
|
||||
// Iterate over all the script callbacks
|
||||
if (m_pScriptHandlerEntries)
|
||||
{
|
||||
for (int i = m_pScriptHandlerEntries->count() - 1; i >= 0; i--)
|
||||
|
@ -855,7 +855,7 @@ void CCScheduler::update(float dt)
|
|||
}
|
||||
}
|
||||
|
||||
// delete all updates that are morked for deletion
|
||||
// delete all updates that are marked for deletion
|
||||
// updates with priority < 0
|
||||
DL_FOREACH_SAFE(m_pUpdatesNegList, pEntry, pTmp)
|
||||
{
|
||||
|
|
|
@ -47,7 +47,7 @@ class CCSet;
|
|||
//
|
||||
// CCTimer
|
||||
//
|
||||
/** @brief Light weight timer */
|
||||
/** @brief Light-weight timer */
|
||||
class CC_DLL CCTimer : public CCObject
|
||||
{
|
||||
public:
|
||||
|
@ -80,6 +80,8 @@ public:
|
|||
/** Allocates a timer with a script callback function and an interval in seconds. */
|
||||
static CCTimer* timerWithScriptHandler(int nHandler, float fSeconds);
|
||||
|
||||
inline int getScriptHandler() { return m_nScriptHandler; };
|
||||
|
||||
public:
|
||||
SEL_SCHEDULE m_pfnSelector;
|
||||
float m_fInterval;
|
||||
|
@ -106,7 +108,7 @@ struct _hashUpdateEntry;
|
|||
|
||||
class CCArray;
|
||||
|
||||
/** @brief Scheduler is responsible of triggering the scheduled callbacks.
|
||||
/** @brief Scheduler is responsible for triggering the scheduled callbacks.
|
||||
You should not use NSTimer. Instead use this class.
|
||||
|
||||
There are 2 different types of callbacks (selectors):
|
||||
|
@ -140,9 +142,9 @@ public:
|
|||
|
||||
/** The scheduled method will be called every 'interval' seconds.
|
||||
If paused is YES, then it won't be called until it is resumed.
|
||||
If 'interval' is 0, it will be called every frame, but if so, it recommened to use 'scheduleUpdateForTarget:' instead.
|
||||
If 'interval' is 0, it will be called every frame, but if so, it's recommended to use 'scheduleUpdateForTarget:' instead.
|
||||
If the selector is already scheduled, then only the interval parameter will be updated without re-scheduling it again.
|
||||
repeat let the action be repeated repeat + 1 times, use kCCRepeatForever to let the action run continiously
|
||||
repeat let the action be repeated repeat + 1 times, use kCCRepeatForever to let the action run continuously
|
||||
delay is the amount of time the action will wait before it'll start
|
||||
|
||||
@since v0.99.3, repeat and delay added in v1.1
|
||||
|
|
|
@ -234,7 +234,7 @@ public:
|
|||
public:
|
||||
/** creates the action with a set boundary,
|
||||
It will work with no boundary if @param rect is equal to CCRectZero.
|
||||
@deprecated: Please use create(CCNode*, const CCRect&) intead. This interface will be deprecated sooner or later.
|
||||
@deprecated: Please use create(CCNode*, const CCRect&) instead. This interface will be deprecated sooner or later.
|
||||
*/
|
||||
CC_DEPRECATED_ATTRIBUTE static CCFollow* actionWithTarget(CCNode *pFollowedNode, const CCRect& rect = CCRectZero);
|
||||
/** creates the action with a set boundary,
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
* THE SOFTWARE.
|
||||
*
|
||||
*
|
||||
* Orignal code by Radu Gruian: http://www.codeproject.com/Articles/30838/Overhauser-Catmull-Rom-Splines-for-Camera-Animatio.So
|
||||
* Original code by Radu Gruian: http://www.codeproject.com/Articles/30838/Overhauser-Catmull-Rom-Splines-for-Camera-Animatio.So
|
||||
*
|
||||
* Adapted to cocos2d-x by Vit Valentin
|
||||
*
|
||||
|
@ -96,12 +96,12 @@ CCPointArray::CCPointArray() :m_pControlPoints(NULL){}
|
|||
|
||||
void CCPointArray::addControlPoint(CCPoint controlPoint)
|
||||
{
|
||||
// should create a new object of CCPoint
|
||||
// because developer always use this function like this
|
||||
// should create a new object: CCPoint
|
||||
// because developers are accustomed to using
|
||||
// addControlPoint(ccp(x, y))
|
||||
// passing controlPoint is a temple object
|
||||
// and CCArray::addObject() will retain the passing object, so it
|
||||
// should be an object created in heap
|
||||
// which assumes controlPoint is a temporary struct
|
||||
// but CCArray::addObject() will retain the passed object, so temp
|
||||
// should be an object created in the heap.
|
||||
CCPoint *temp = new CCPoint(controlPoint.x, controlPoint.y);
|
||||
m_pControlPoints->addObject(temp);
|
||||
temp->release();
|
||||
|
@ -109,12 +109,12 @@ void CCPointArray::addControlPoint(CCPoint controlPoint)
|
|||
|
||||
void CCPointArray::insertControlPoint(CCPoint &controlPoint, unsigned int index)
|
||||
{
|
||||
// should create a new object of CCPoint
|
||||
// because developer always use this function like this
|
||||
// should create a new object: CCPoint
|
||||
// because developers are accustomed to using
|
||||
// insertControlPoint(ccp(x, y))
|
||||
// passing controlPoint is a temple object
|
||||
// and CCArray::insertObject() will retain the passing object, so it
|
||||
// should be an object created in heap
|
||||
// which assumes controlPoint is a temporary struct
|
||||
// but CCArray::insertObject() will retain the passed object, so temp
|
||||
// should be an object created in the heap.
|
||||
CCPoint *temp = new CCPoint(controlPoint.x, controlPoint.y);
|
||||
m_pControlPoints->insertObject(temp, index);
|
||||
temp->release();
|
||||
|
@ -130,12 +130,12 @@ CCPoint CCPointArray::getControlPointAtIndex(unsigned int index)
|
|||
|
||||
void CCPointArray::replaceControlPoint(cocos2d::CCPoint &controlPoint, unsigned int index)
|
||||
{
|
||||
// should create a new object of CCPoint
|
||||
// because developer always use this function like this
|
||||
// should create a new object: CCPoint
|
||||
// because developers are accustomed to using
|
||||
// replaceControlPoint(ccp(x, y))
|
||||
// passing controlPoint is a temple object
|
||||
// and CCArray::insertObject() will retain the passing object, so it
|
||||
// should be an object created in heap
|
||||
// which assumes controlPoint is a temporary struct
|
||||
// but CCArray::insertObject() will retain the passed object, so temp
|
||||
// should be an object created in the heap.
|
||||
CCPoint *temp = new CCPoint(controlPoint.x, controlPoint.y);
|
||||
m_pControlPoints->replaceObjectAtIndex(index, temp);
|
||||
temp->release();
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
* THE SOFTWARE.
|
||||
*
|
||||
*
|
||||
* Orignal code by Radu Gruian: http://www.codeproject.com/Articles/30838/Overhauser-Catmull-Rom-Splines-for-Camera-Animatio.So
|
||||
* Original code by Radu Gruian: http://www.codeproject.com/Articles/30838/Overhauser-Catmull-Rom-Splines-for-Camera-Animatio.So
|
||||
*
|
||||
* Adapted to cocos2d-x by Vit Valentin
|
||||
*
|
||||
|
|
|
@ -320,7 +320,7 @@ protected:
|
|||
|
||||
/**
|
||||
@brief Ease Elastic In action.
|
||||
@warning This action doesn't use a bijective fucntion. Actions like Sequence might have an unexpected result when used with this action.
|
||||
@warning This action doesn't use a bijective function. Actions like Sequence might have an unexpected result when used with this action.
|
||||
@since v0.8.2
|
||||
@ingroup Actions
|
||||
*/
|
||||
|
@ -345,7 +345,7 @@ public:
|
|||
|
||||
/**
|
||||
@brief Ease Elastic Out action.
|
||||
@warning This action doesn't use a bijective fucntion. Actions like Sequence might have an unexpected result when used with this action.
|
||||
@warning This action doesn't use a bijective function. Actions like Sequence might have an unexpected result when used with this action.
|
||||
@since v0.8.2
|
||||
@ingroup Actions
|
||||
*/
|
||||
|
@ -371,7 +371,7 @@ public:
|
|||
|
||||
/**
|
||||
@brief Ease Elastic InOut action.
|
||||
@warning This action doesn't use a bijective fucntion. Actions like Sequence might have an unexpected result when used with this action.
|
||||
@warning This action doesn't use a bijective function. Actions like Sequence might have an unexpected result when used with this action.
|
||||
@since v0.8.2
|
||||
@ingroup Actions
|
||||
*/
|
||||
|
@ -440,7 +440,7 @@ public:
|
|||
|
||||
/**
|
||||
@brief EaseBounceOut action.
|
||||
@warning This action doesn't use a bijective fucntion. Actions like Sequence might have an unexpected result when used with this action.
|
||||
@warning This action doesn't use a bijective function. Actions like Sequence might have an unexpected result when used with this action.
|
||||
@since v0.8.2
|
||||
@ingroup Actions
|
||||
*/
|
||||
|
@ -462,7 +462,7 @@ public:
|
|||
|
||||
/**
|
||||
@brief CCEaseBounceInOut action.
|
||||
@warning This action doesn't use a bijective fucntion. Actions like Sequence might have an unexpected result when used with this action.
|
||||
@warning This action doesn't use a bijective function. Actions like Sequence might have an unexpected result when used with this action.
|
||||
@since v0.8.2
|
||||
@ingroup Actions
|
||||
*/
|
||||
|
@ -484,7 +484,7 @@ public:
|
|||
|
||||
/**
|
||||
@brief CCEaseBackIn action.
|
||||
@warning This action doesn't use a bijective fucntion. Actions like Sequence might have an unexpected result when used with this action.
|
||||
@warning This action doesn't use a bijective function. Actions like Sequence might have an unexpected result when used with this action.
|
||||
@since v0.8.2
|
||||
@ingroup Actions
|
||||
*/
|
||||
|
@ -506,7 +506,7 @@ public:
|
|||
|
||||
/**
|
||||
@brief CCEaseBackOut action.
|
||||
@warning This action doesn't use a bijective fucntion. Actions like Sequence might have an unexpected result when used with this action.
|
||||
@warning This action doesn't use a bijective function. Actions like Sequence might have an unexpected result when used with this action.
|
||||
@since v0.8.2
|
||||
@ingroup Actions
|
||||
*/
|
||||
|
@ -528,7 +528,7 @@ public:
|
|||
|
||||
/**
|
||||
@brief CCEaseBackInOut action.
|
||||
@warning This action doesn't use a bijective fucntion. Actions like Sequence might have an unexpected result when used with this action.
|
||||
@warning This action doesn't use a bijective function. Actions like Sequence might have an unexpected result when used with this action.
|
||||
@since v0.8.2
|
||||
@ingroup Actions
|
||||
*/
|
||||
|
|
|
@ -435,7 +435,7 @@ void CCCallFunc::execute() {
|
|||
(m_pSelectorTarget->*m_pCallFunc)();
|
||||
}
|
||||
if (m_nScriptHandler) {
|
||||
CCScriptEngineManager::sharedManager()->getScriptEngine()->executeFunctionByHandler(m_nScriptHandler);
|
||||
CCScriptEngineManager::sharedManager()->getScriptEngine()->executeCallFuncActionEvent(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -447,7 +447,7 @@ void CCCallFuncN::execute() {
|
|||
(m_pSelectorTarget->*m_pCallFuncN)(m_pTarget);
|
||||
}
|
||||
if (m_nScriptHandler) {
|
||||
CCScriptEngineManager::sharedManager()->getScriptEngine()->executeFunctionWithCCObject(m_nScriptHandler, m_pTarget, "CCNode");
|
||||
CCScriptEngineManager::sharedManager()->getScriptEngine()->executeCallFuncActionEvent(this, m_pTarget);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -263,7 +263,8 @@ public:
|
|||
m_pSelectorTarget = pSel;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
inline int getScriptHandler() { return m_nScriptHandler; };
|
||||
protected:
|
||||
/** Target that will be called */
|
||||
CCObject* m_pSelectorTarget;
|
||||
|
|
|
@ -384,7 +384,7 @@ bool CCRepeat::initWithAction(CCFiniteTimeAction *pAction, unsigned int times)
|
|||
pAction->retain();
|
||||
|
||||
m_bActionInstant = dynamic_cast<CCActionInstant*>(pAction) ? true : false;
|
||||
//a instant action needs to be executed one time less in the update method since it uses startWithTarget to execute the action
|
||||
//an instant action needs to be executed one time less in the update method since it uses startWithTarget to execute the action
|
||||
if (m_bActionInstant)
|
||||
{
|
||||
m_uTimes -=1;
|
||||
|
@ -463,7 +463,7 @@ void CCRepeat::update(float dt)
|
|||
m_uTotal++;
|
||||
}
|
||||
|
||||
// don't set a instantaction back or update it, it has no use because it has no duration
|
||||
// don't set an instant action back or update it, it has no use because it has no duration
|
||||
if (!m_bActionInstant)
|
||||
{
|
||||
if (m_uTotal == m_uTimes)
|
||||
|
|
|
@ -116,7 +116,7 @@ public:
|
|||
@deprecated: This interface will be deprecated sooner or later.
|
||||
*/
|
||||
CC_DEPRECATED_ATTRIBUTE static CCFiniteTimeAction* actions(CCFiniteTimeAction *pAction1, ...);
|
||||
/** helper contructor to create an array of sequenceable actions given an array
|
||||
/** helper constructor to create an array of sequenceable actions given an array
|
||||
@deprecated: This interface will be deprecated sooner or later.
|
||||
*/
|
||||
CC_DEPRECATED_ATTRIBUTE static CCFiniteTimeAction* actionWithArray(CCArray *arrayOfActions);
|
||||
|
@ -127,7 +127,7 @@ public:
|
|||
|
||||
/** helper constructor to create an array of sequenceable actions */
|
||||
static CCFiniteTimeAction* create(CCFiniteTimeAction *pAction1, ...);
|
||||
/** helper contructor to create an array of sequenceable actions given an array */
|
||||
/** helper constructor to create an array of sequenceable actions given an array */
|
||||
static CCFiniteTimeAction* create(CCArray *arrayOfActions);
|
||||
/** creates the action */
|
||||
static CCSequence* createWithTwoActions(CCFiniteTimeAction *pActionOne, CCFiniteTimeAction *pActionTwo);
|
||||
|
@ -257,7 +257,7 @@ public:
|
|||
*/
|
||||
CC_DEPRECATED_ATTRIBUTE static CCFiniteTimeAction* actions(CCFiniteTimeAction *pAction1, ...);
|
||||
|
||||
/** helper contructor to create an array of spawned actions given an array
|
||||
/** helper constructor to create an array of spawned actions given an array
|
||||
@deprecated: This interface will be deprecated sooner or later.
|
||||
*/
|
||||
CC_DEPRECATED_ATTRIBUTE static CCFiniteTimeAction* actionWithArray(CCArray *arrayOfActions);
|
||||
|
@ -270,7 +270,7 @@ public:
|
|||
/** helper constructor to create an array of spawned actions */
|
||||
static CCFiniteTimeAction* create(CCFiniteTimeAction *pAction1, ...);
|
||||
|
||||
/** helper contructor to create an array of spawned actions given an array */
|
||||
/** helper constructor to create an array of spawned actions given an array */
|
||||
static CCFiniteTimeAction* create(CCArray *arrayOfActions);
|
||||
|
||||
/** creates the Spawn action */
|
||||
|
|
|
@ -96,7 +96,7 @@ void CCPageTurn3D::update(float time)
|
|||
p.y = ( R + ay - ( r * (1 - cosBeta) * sinTheta));
|
||||
|
||||
// We scale z here to avoid the animation being
|
||||
// too much bigger than the screen due to perspectve transform
|
||||
// too much bigger than the screen due to perspective transform
|
||||
p.z = (r * ( 1 - cosBeta ) * cosTheta) / 7;// "100" didn't work for
|
||||
|
||||
// Stop z coord from dropping beneath underlying page in a transition
|
||||
|
|
|
@ -50,7 +50,7 @@ public:
|
|||
[target runAction:modifyWidth];
|
||||
|
||||
|
||||
Another example: CCScaleTo action could be rewriten using CCPropertyAction:
|
||||
Another example: CCScaleTo action could be rewritten using CCPropertyAction:
|
||||
|
||||
// scaleA and scaleB are equivalents
|
||||
id scaleA = [CCScaleTo actionWithDuration:2 scale:3];
|
||||
|
|
|
@ -130,7 +130,7 @@ void CCAtlasNode::calculateMaxItems()
|
|||
|
||||
void CCAtlasNode::updateAtlasValues()
|
||||
{
|
||||
CCAssert(false, "CCAtlasNode:Abstract updateAtlasValue not overriden");
|
||||
CCAssert(false, "CCAtlasNode:Abstract updateAtlasValue not overridden");
|
||||
}
|
||||
|
||||
// CCAtlasNode - draw
|
||||
|
|
|
@ -98,7 +98,7 @@ public:
|
|||
bool initWithTileFile(const char* tile, unsigned int tileWidth, unsigned int tileHeight, unsigned int itemsToRender);
|
||||
|
||||
/** updates the Atlas (indexed vertex array).
|
||||
* Shall be overriden in subclasses
|
||||
* Shall be overridden in subclasses
|
||||
*/
|
||||
virtual void updateAtlasValues();
|
||||
|
||||
|
|
|
@ -171,7 +171,7 @@ void CCNode::setZOrder(int z)
|
|||
}
|
||||
}
|
||||
|
||||
/// ertexZ getter
|
||||
/// vertexZ getter
|
||||
float CCNode::getVertexZ()
|
||||
{
|
||||
return m_fVertexZ;
|
||||
|
@ -491,7 +491,7 @@ CCNode* CCNode::getChildByTag(int aTag)
|
|||
}
|
||||
|
||||
/* "add" logic MUST only be on this method
|
||||
* If a class want's to extend the 'addChild' behaviour it only needs
|
||||
* If a class want's to extend the 'addChild' behavior it only needs
|
||||
* to override this method
|
||||
*/
|
||||
void CCNode::addChild(CCNode *child, int zOrder, int tag)
|
||||
|
@ -681,7 +681,7 @@ void CCNode::sortAllChildren()
|
|||
{
|
||||
//CCAssert(0);
|
||||
// override me
|
||||
// Only use- this function to draw your staff.
|
||||
// Only use- this function to draw your stuff.
|
||||
// DON'T draw your stuff outside this method
|
||||
}
|
||||
|
||||
|
@ -798,11 +798,10 @@ void CCNode::onEnter()
|
|||
|
||||
m_bIsRunning = true;
|
||||
|
||||
if ( (m_eScriptType == kScriptTypeLua && m_nScriptHandler != 0)
|
||||
|| m_eScriptType == kScriptTypeJavascript )
|
||||
if (m_eScriptType != kScriptTypeNone)
|
||||
{
|
||||
CCScriptEngineManager::sharedManager()->getScriptEngine()->executeFunctionWithIntegerData(m_nScriptHandler, kCCNodeOnEnter, this);
|
||||
}
|
||||
CCScriptEngineManager::sharedManager()->getScriptEngine()->executeNodeEvent(this, kCCNodeOnEnter);
|
||||
}
|
||||
}
|
||||
|
||||
void CCNode::onEnterTransitionDidFinish()
|
||||
|
@ -811,7 +810,7 @@ void CCNode::onEnterTransitionDidFinish()
|
|||
|
||||
if (m_eScriptType == kScriptTypeJavascript)
|
||||
{
|
||||
CCScriptEngineManager::sharedManager()->getScriptEngine()->executeFunctionWithIntegerData(m_nScriptHandler, kCCNodeOnEnterTransitionDidFinish, this);
|
||||
CCScriptEngineManager::sharedManager()->getScriptEngine()->executeNodeEvent(this, kCCNodeOnEnterTransitionDidFinish);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -821,7 +820,7 @@ void CCNode::onExitTransitionDidStart()
|
|||
|
||||
if (m_eScriptType == kScriptTypeJavascript)
|
||||
{
|
||||
CCScriptEngineManager::sharedManager()->getScriptEngine()->executeFunctionWithIntegerData(m_nScriptHandler, kCCNodeOnExitTransitionDidStart, this);
|
||||
CCScriptEngineManager::sharedManager()->getScriptEngine()->executeNodeEvent(this, kCCNodeOnExitTransitionDidStart);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -831,10 +830,9 @@ void CCNode::onExit()
|
|||
|
||||
m_bIsRunning = false;
|
||||
|
||||
if ( (m_eScriptType == kScriptTypeLua && m_nScriptHandler != 0)
|
||||
|| m_eScriptType == kScriptTypeJavascript )
|
||||
if ( m_eScriptType != kScriptTypeNone)
|
||||
{
|
||||
CCScriptEngineManager::sharedManager()->getScriptEngine()->executeFunctionWithIntegerData(m_nScriptHandler, kCCNodeOnExit, this);
|
||||
CCScriptEngineManager::sharedManager()->getScriptEngine()->executeNodeEvent(this, kCCNodeOnExit);
|
||||
}
|
||||
|
||||
arrayMakeObjectsPerformSelector(m_pChildren, onExit, CCNode*);
|
||||
|
@ -851,7 +849,7 @@ void CCNode::unregisterScriptHandler(void)
|
|||
{
|
||||
if (m_nScriptHandler)
|
||||
{
|
||||
CCScriptEngineManager::sharedManager()->getScriptEngine()->removeLuaHandler(m_nScriptHandler);
|
||||
CCScriptEngineManager::sharedManager()->getScriptEngine()->removeScriptHandler(m_nScriptHandler);
|
||||
LUALOG("[LUA] Remove CCNode event handler: %d", m_nScriptHandler);
|
||||
m_nScriptHandler = 0;
|
||||
}
|
||||
|
|
|
@ -25,8 +25,8 @@
|
|||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __PLATFOMR_CCNODE_H__
|
||||
#define __PLATFOMR_CCNODE_H__
|
||||
#ifndef __PLATFORM_CCNODE_H__
|
||||
#define __PLATFORM_CCNODE_H__
|
||||
|
||||
#include "ccMacros.h"
|
||||
#include "cocoa/CCAffineTransform.h"
|
||||
|
@ -61,12 +61,11 @@ enum {
|
|||
enum {
|
||||
kCCNodeOnEnter,
|
||||
kCCNodeOnExit,
|
||||
kCCMenuItemActivated,
|
||||
kCCNodeOnEnterTransitionDidFinish,
|
||||
kCCNodeOnExitTransitionDidStart
|
||||
};
|
||||
|
||||
/** @brief CCNode is the main element. Anything thats gets drawn or contains things that get drawn is a CCNode.
|
||||
/** @brief CCNode is the main element. Anything that gets drawn or contains things that get drawn is a CCNode.
|
||||
The most popular CCNodes are: CCScene, CCLayer, CCSprite, CCMenu.
|
||||
|
||||
The main features of a CCNode are:
|
||||
|
@ -240,7 +239,7 @@ public:
|
|||
/** A weak reference to the parent */
|
||||
CC_PROPERTY(CCNode *, m_pParent, Parent)
|
||||
|
||||
// If ture, the Anchor Point will be (0,0) when you position the CCNode.
|
||||
// If true, the Anchor Point will be (0,0) when you position the CCNode.
|
||||
// Used by CCLayer and CCScene
|
||||
bool m_bIgnoreAnchorPointForPosition;
|
||||
bool isIgnoreAnchorPointForPosition();
|
||||
|
@ -279,6 +278,8 @@ public:
|
|||
*/
|
||||
CC_PROPERTY(CCScheduler*, m_pScheduler, Scheduler);
|
||||
|
||||
inline int getScriptHandler() { return m_nScriptHandler; };
|
||||
|
||||
protected:
|
||||
|
||||
// transform
|
||||
|
@ -324,7 +325,7 @@ public:
|
|||
*/
|
||||
static CCNode * create(void);
|
||||
|
||||
//scene managment
|
||||
//scene management
|
||||
|
||||
/** callback that is called every time the CCNode enters the 'stage'.
|
||||
If the CCNode enters the 'stage' with a transition, this callback is called when the transition starts.
|
||||
|
@ -576,7 +577,7 @@ public:
|
|||
*/
|
||||
virtual CCAffineTransform parentToNodeTransform(void);
|
||||
|
||||
/** Retrusn the world affine transform matrix. The matrix is in Pixels.
|
||||
/** Returns the world affine transform matrix. The matrix is in Pixels.
|
||||
@since v0.7.1
|
||||
*/
|
||||
virtual CCAffineTransform nodeToWorldTransform(void);
|
||||
|
@ -610,7 +611,7 @@ public:
|
|||
*/
|
||||
CCPoint convertTouchToNodeSpace(CCTouch * touch);
|
||||
|
||||
/** converts a CCTouch (world coordinates) into a local coordiante. This method is AR (Anchor Relative).
|
||||
/** converts a CCTouch (world coordinates) into a local coordinate. This method is AR (Anchor Relative).
|
||||
@since v0.7.1
|
||||
*/
|
||||
CCPoint convertTouchToNodeSpaceAR(CCTouch * touch);
|
||||
|
@ -621,7 +622,7 @@ public:
|
|||
|
||||
NS_CC_END
|
||||
|
||||
#endif // __PLATFOMR_CCNODE_H__
|
||||
#endif // __PLATFORM_CCNODE_H__
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -414,7 +414,7 @@ void CCArray::reverseObjects()
|
|||
{
|
||||
if (data->num > 1)
|
||||
{
|
||||
//floor it since in case of a oneven number the number of swaps stays the same
|
||||
// floorf(), since in the case of an even number, the number of swaps stays the same
|
||||
int count = (int) floorf(data->num/2.f);
|
||||
unsigned int maxIndex = data->num - 1;
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ THE SOFTWARE.
|
|||
*/
|
||||
|
||||
/** @def CCARRAY_FOREACH
|
||||
A convience macro to iterate over a CCArray using. It is faster than the "fast enumeration" interface.
|
||||
A convenience macro to iterate over a CCArray using. It is faster than the "fast enumeration" interface.
|
||||
@since v0.99.4
|
||||
*/
|
||||
|
||||
|
@ -139,7 +139,7 @@ public:
|
|||
@brief Generate a CCArray pointer by file
|
||||
@param pFileName The file name of *.plist file
|
||||
@return The CCArray pointer generated from the file
|
||||
@deprecated: Please use createWithContentsOfFile(const char*) intead. This interface will be deprecated sooner or later.
|
||||
@deprecated: Please use createWithContentsOfFile(const char*) instead. This interface will be deprecated sooner or later.
|
||||
*/
|
||||
CC_DEPRECATED_ATTRIBUTE static CCArray* arrayWithContentsOfFile(const char* pFileName);
|
||||
|
||||
|
|
|
@ -264,7 +264,7 @@ void CCDictionary::removeAllObjects()
|
|||
|
||||
CCObject* CCDictionary::copyWithZone(CCZone* pZone)
|
||||
{
|
||||
CCAssert(pZone == NULL, "CCDirctionary should not be inherited.");
|
||||
CCAssert(pZone == NULL, "CCDictionary should not be inherited.");
|
||||
CCDictionary* pNewDict = new CCDictionary();
|
||||
|
||||
CCDictElement* pElement = NULL;
|
||||
|
|
|
@ -50,7 +50,7 @@ static inline void split(std::string src, const char* token, strArray& vect)
|
|||
}
|
||||
|
||||
// first, judge whether the form of the string like this: {x,y}
|
||||
// if the form is right,the string will be splited into the parameter strs;
|
||||
// if the form is right,the string will be split into the parameter strs;
|
||||
// or the parameter strs will be empty.
|
||||
// if the form is right return true,else return false.
|
||||
static bool splitWithForm(const char* pStr, strArray& strs)
|
||||
|
|
|
@ -44,7 +44,7 @@ CCObject::CCObject(void)
|
|||
m_uID = ++uObjectCount;
|
||||
m_nLuaID = 0;
|
||||
|
||||
// when the object is created, the refrence count of it is 1
|
||||
// when the object is created, the reference count of it is 1
|
||||
m_uReference = 1;
|
||||
m_bManaged = false;
|
||||
}
|
||||
|
@ -61,14 +61,14 @@ CCObject::~CCObject(void)
|
|||
// if the object is referenced by Lua engine, remove it
|
||||
if (m_nLuaID)
|
||||
{
|
||||
CCScriptEngineManager::sharedManager()->getScriptEngine()->removeCCObjectByID(m_nLuaID);
|
||||
CCScriptEngineManager::sharedManager()->getScriptEngine()->removeScriptObjectByCCObject(this);
|
||||
}
|
||||
else
|
||||
{
|
||||
CCScriptEngineProtocol* pEngine = CCScriptEngineManager::sharedManager()->getScriptEngine();
|
||||
if (pEngine != NULL && pEngine->getScriptType() == kScriptTypeJavascript)
|
||||
{
|
||||
pEngine->removeJSObjectByCCObject(this);
|
||||
pEngine->removeScriptObjectByCCObject(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -53,7 +53,7 @@ public:
|
|||
// Lua reference id
|
||||
int m_nLuaID;
|
||||
protected:
|
||||
// count of refrence
|
||||
// count of references
|
||||
unsigned int m_uReference;
|
||||
// is the object autoreleased
|
||||
bool m_bManaged;
|
||||
|
|
|
@ -45,7 +45,7 @@ public:
|
|||
virtual ~CCSet(void);
|
||||
|
||||
/**
|
||||
*@brief Return a copy of the CCSet, it will copy all the elelments.
|
||||
*@brief Return a copy of the CCSet, it will copy all the elements.
|
||||
*/
|
||||
CCSet* copy();
|
||||
/**
|
||||
|
@ -73,7 +73,7 @@ public:
|
|||
*/
|
||||
CCSetIterator begin();
|
||||
/**
|
||||
*@brief Return the iterator that points to the poisition after the last element.
|
||||
*@brief Return the iterator that points to the position after the last element.
|
||||
*/
|
||||
CCSetIterator end();
|
||||
/**
|
||||
|
|
|
@ -219,7 +219,7 @@ CCString* CCString::createWithFormat(const char* format, ...)
|
|||
|
||||
CCString* CCString::stringWithContentsOfFile(const char* pszFileName)
|
||||
{
|
||||
return CCString::create(pszFileName);
|
||||
return CCString::createWithContentsOfFile(pszFileName);
|
||||
}
|
||||
|
||||
CCString* CCString::createWithContentsOfFile(const char* pszFileName)
|
||||
|
|
|
@ -84,7 +84,7 @@ public:
|
|||
virtual CCObject* copyWithZone(CCZone* pZone);
|
||||
virtual bool isEqual(const CCObject* pObject);
|
||||
|
||||
/* static funcitons */
|
||||
/* static functions */
|
||||
/** create a string with c string
|
||||
* @return A CCString pointer which is an autorelease object pointer,
|
||||
* it means that you needn't do a release operation unless you retain it.
|
||||
|
@ -120,7 +120,7 @@ public:
|
|||
*/
|
||||
CC_DEPRECATED_ATTRIBUTE static CCString* stringWithContentsOfFile(const char* pszFileName);
|
||||
|
||||
/** create a string with std string, you can also pass a c string pointer because the default constuctor of std::string can access a c string pointer.
|
||||
/** create a string with std string, you can also pass a c string pointer because the default constructor of std::string can access a c string pointer.
|
||||
* @return A CCString pointer which is an autorelease object pointer,
|
||||
* it means that you needn't do a release operation unless you retain it.
|
||||
*/
|
||||
|
|
|
@ -53,7 +53,7 @@ void CCGrabber::grab(CCTexture2D *pTexture)
|
|||
GLuint status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
|
||||
if (status != GL_FRAMEBUFFER_COMPLETE)
|
||||
{
|
||||
CCAssert(0, "Frame Grabber: could not attach texture to frmaebuffer");
|
||||
CCAssert(0, "Frame Grabber: could not attach texture to framebuffer");
|
||||
}
|
||||
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, m_oldFBO);
|
||||
|
|
|
@ -346,7 +346,7 @@ void CCGrid3D::blit(void)
|
|||
// position
|
||||
glVertexAttribPointer(kCCVertexAttrib_Position, 3, GL_FLOAT, GL_FALSE, 0, m_pVertices);
|
||||
|
||||
// texCoods
|
||||
// texCoords
|
||||
glVertexAttribPointer(kCCVertexAttrib_TexCoords, 2, GL_FLOAT, GL_FALSE, 0, m_pTexCoordinates);
|
||||
|
||||
glDrawElements(GL_TRIANGLES, (GLsizei) n*6, GL_UNSIGNED_SHORT, m_pIndices);
|
||||
|
@ -551,7 +551,7 @@ void CCTiledGrid3D::blit(void)
|
|||
// position
|
||||
glVertexAttribPointer(kCCVertexAttrib_Position, 3, GL_FLOAT, GL_FALSE, 0, m_pVertices);
|
||||
|
||||
// texCoods
|
||||
// texCoords
|
||||
glVertexAttribPointer(kCCVertexAttrib_TexCoords, 2, GL_FLOAT, GL_FALSE, 0, m_pTexCoordinates);
|
||||
|
||||
glDrawElements(GL_TRIANGLES, (GLsizei)n*6, GL_UNSIGNED_SHORT, m_pIndices);
|
||||
|
|
|
@ -51,7 +51,7 @@ class CC_DLL CCGridBase : public CCObject
|
|||
public:
|
||||
virtual ~CCGridBase(void);
|
||||
|
||||
/** wheter or not the grid is active */
|
||||
/** whether or not the grid is active */
|
||||
inline bool isActive(void) { return m_bActive; }
|
||||
void setActive(bool bActive);
|
||||
|
||||
|
|
|
@ -50,7 +50,7 @@ public:
|
|||
virtual GLubyte getOpacity(void) = 0;
|
||||
|
||||
/** sets the opacity.
|
||||
@warning If the the texture has premultiplied alpha then, the R, G and B channels will be modifed.
|
||||
@warning If the the texture has premultiplied alpha then, the R, G and B channels will be modified.
|
||||
Values goes from 0 to 255, where 255 means fully opaque.
|
||||
*/
|
||||
virtual void setOpacity(GLubyte opacity) = 0;
|
||||
|
@ -59,7 +59,7 @@ public:
|
|||
|
||||
/** sets the premultipliedAlphaOpacity property.
|
||||
If set to NO then opacity will be applied as: glColor(R,G,B,opacity);
|
||||
If set to YES then oapcity will be applied as: glColor(opacity, opacity, opacity, opacity );
|
||||
If set to YES then opacity will be applied as: glColor(opacity, opacity, opacity, opacity );
|
||||
Textures with premultiplied alpha will have this property by default on YES. Otherwise the default value is NO
|
||||
@since v0.8
|
||||
*/
|
||||
|
@ -72,7 +72,7 @@ public:
|
|||
};
|
||||
|
||||
/**
|
||||
@brief You can specify the blending fuction.
|
||||
@brief You can specify the blending function.
|
||||
@since v0.99.0
|
||||
*/
|
||||
class CC_DLL CCBlendProtocol
|
||||
|
@ -91,7 +91,7 @@ public:
|
|||
src=GL_ONE dst= GL_ONE_MINUS_SRC_ALPHA
|
||||
else
|
||||
src=GL_SRC_ALPHA dst= GL_ONE_MINUS_SRC_ALPHA
|
||||
But you can change the blending funtion at any time.
|
||||
But you can change the blending function at any time.
|
||||
@since v0.8.0
|
||||
*/
|
||||
class CC_DLL CCTextureProtocol : public CCBlendProtocol
|
||||
|
@ -119,7 +119,7 @@ public:
|
|||
class CC_DLL CCDirectorDelegate
|
||||
{
|
||||
public:
|
||||
/** Called by CCDirector when the porjection is updated, and "custom" projection is used
|
||||
/** Called by CCDirector when the projection is updated, and "custom" projection is used
|
||||
@since v0.99.5
|
||||
*/
|
||||
virtual void updateProjection(void) = 0;
|
||||
|
|
|
@ -36,14 +36,14 @@ THE SOFTWARE.
|
|||
|
||||
/** @def CC_ENABLE_GL_STATE_CACHE
|
||||
If enabled, cocos2d will maintain an OpenGL state cache internally to avoid unnecessary switches.
|
||||
In order to use them, you have to use the following functions, insead of the the GL ones:
|
||||
In order to use them, you have to use the following functions, instead of the the GL ones:
|
||||
- ccGLUseProgram() instead of glUseProgram()
|
||||
- ccGLDeleteProgram() instead of glDeleteProgram()
|
||||
- ccGLBlendFunc() instead of glBlendFunc()
|
||||
|
||||
If this functionality is disabled, then ccGLUseProgram(), ccGLDeleteProgram(), ccGLBlendFunc() will call the GL ones, without using the cache.
|
||||
|
||||
It is recommened to enable whenever possible to improve speed.
|
||||
It is recommended to enable whenever possible to improve speed.
|
||||
If you are migrating your code from GL ES 1.1, then keep it disabled. Once all your code works as expected, turn it on.
|
||||
|
||||
@since v2.0.0
|
||||
|
@ -77,7 +77,7 @@ To enabled set it to 1. Disabled by default.
|
|||
#endif
|
||||
|
||||
/** @def CC_DIRECTOR_FPS_INTERVAL
|
||||
Senconds between FPS updates.
|
||||
Seconds between FPS updates.
|
||||
0.5 seconds, means that the FPS number will be updated every 0.5 seconds.
|
||||
Having a bigger number means a more reliable FPS
|
||||
|
||||
|
@ -190,7 +190,7 @@ Only valid for cocos2d-mac. Not supported on cocos2d-ios.
|
|||
|
||||
/** @def CC_SPRITE_DEBUG_DRAW
|
||||
If enabled, all subclasses of CCSprite will draw a bounding box
|
||||
Useful for debugging purposes only. It is recommened to leave it disabled.
|
||||
Useful for debugging purposes only. It is recommended to leave it disabled.
|
||||
|
||||
To enable set it to a value different than 0. Disabled by default:
|
||||
0 -- disabled
|
||||
|
@ -206,7 +206,7 @@ Only valid for cocos2d-mac. Not supported on cocos2d-ios.
|
|||
|
||||
/** @def CC_SPRITEBATCHNODE_DEBUG_DRAW
|
||||
If enabled, all subclasses of CCSprite that are rendered using an CCSpriteBatchNode draw a bounding box.
|
||||
Useful for debugging purposes only. It is recommened to leave it disabled.
|
||||
Useful for debugging purposes only. It is recommended to leave it disabled.
|
||||
|
||||
To enable set it to a value different than 0. Disabled by default.
|
||||
*/
|
||||
|
@ -216,7 +216,7 @@ To enable set it to a value different than 0. Disabled by default.
|
|||
|
||||
/** @def CC_LABELBMFONT_DEBUG_DRAW
|
||||
If enabled, all subclasses of CCLabelBMFont will draw a bounding box
|
||||
Useful for debugging purposes only. It is recommened to leave it disabled.
|
||||
Useful for debugging purposes only. It is recommended to leave it disabled.
|
||||
|
||||
To enable set it to a value different than 0. Disabled by default.
|
||||
*/
|
||||
|
@ -226,7 +226,7 @@ To enable set it to a value different than 0. Disabled by default.
|
|||
|
||||
/** @def CC_LABELATLAS_DEBUG_DRAW
|
||||
If enabled, all subclasses of LabeltAtlas will draw a bounding box
|
||||
Useful for debugging purposes only. It is recommened to leave it disabled.
|
||||
Useful for debugging purposes only. It is recommended to leave it disabled.
|
||||
|
||||
To enable set it to a value different than 0. Disabled by default.
|
||||
*/
|
||||
|
@ -235,9 +235,9 @@ To enable set it to a value different than 0. Disabled by default.
|
|||
#endif
|
||||
|
||||
/** @def CC_ENABLE_PROFILERS
|
||||
If enabled, will activate various profilers withing cocos2d. This statistical data will be output to the console
|
||||
If enabled, will activate various profilers within cocos2d. This statistical data will be output to the console
|
||||
once per second showing average time (in milliseconds) required to execute the specific routine(s).
|
||||
Useful for debugging purposes only. It is recommened to leave it disabled.
|
||||
Useful for debugging purposes only. It is recommended to leave it disabled.
|
||||
|
||||
To enable set it to a value different than 0. Disabled by default.
|
||||
*/
|
||||
|
|
|
@ -163,7 +163,7 @@ CCSizeMake( (__size_in_points__).width * CC_CONTENT_SCALE_FACTOR(), (__size_in_p
|
|||
void operator=(const TypeName&)
|
||||
|
||||
/**
|
||||
Helper marcos which converts 4-byte little/big endian
|
||||
Helper macros which converts 4-byte little/big endian
|
||||
integral number to the machine native number representation
|
||||
|
||||
It should work same as apples CFSwapInt32LittleToHost(..)
|
||||
|
|
|
@ -254,7 +254,7 @@ typedef struct _ccV3F_C4B_T2F
|
|||
// char __padding2__[4];
|
||||
|
||||
// tex coords (2F)
|
||||
ccTex2F texCoords; // 8 byts
|
||||
ccTex2F texCoords; // 8 bytes
|
||||
} ccV3F_C4B_T2F;
|
||||
|
||||
//! 4 ccVertex2FTex2FColor4B Quad
|
||||
|
@ -305,7 +305,7 @@ typedef struct _ccBlendFunc
|
|||
GLenum dst;
|
||||
} ccBlendFunc;
|
||||
|
||||
// XXX: If any of these enums are edited and/or reordered, udpate CCTexture2D.m
|
||||
// XXX: If any of these enums are edited and/or reordered, update CCTexture2D.m
|
||||
//! Vertical text alignment type
|
||||
typedef enum
|
||||
{
|
||||
|
@ -314,7 +314,7 @@ typedef enum
|
|||
kCCVerticalTextAlignmentBottom,
|
||||
} CCVerticalTextAlignment;
|
||||
|
||||
// XXX: If any of these enums are edited and/or reordered, udpate CCTexture2D.m
|
||||
// XXX: If any of these enums are edited and/or reordered, update CCTexture2D.m
|
||||
//! Horizontal text alignment type
|
||||
typedef enum
|
||||
{
|
||||
|
|
|
@ -35,7 +35,7 @@ extern "C" {
|
|||
#endif
|
||||
|
||||
/**
|
||||
* A struture that represents an axis-aligned
|
||||
* A structure that represents an axis-aligned
|
||||
* bounding box.
|
||||
*/
|
||||
typedef struct kmAABB {
|
||||
|
|
|
@ -32,13 +32,13 @@
|
|||
#endif
|
||||
#endif // __arm__
|
||||
|
||||
// Matrixes are assumed to be stored in column major format according to OpenGL
|
||||
// Matrices are assumed to be stored in column major format according to OpenGL
|
||||
// specification.
|
||||
|
||||
// Multiplies two 4x4 matrices (a,b) outputing a 4x4 matrix (output)
|
||||
// Multiplies two 4x4 matrices (a,b) outputting a 4x4 matrix (output)
|
||||
void NEON_Matrix4Mul(const float* a, const float* b, float* output );
|
||||
|
||||
// Multiplies a 4x4 matrix (m) with a vector 4 (v), outputing a vector 4
|
||||
// Multiplies a 4x4 matrix (m) with a vector 4 (v), outputting a vector 4
|
||||
void NEON_Matrix4Vector4Mul(const float* m, const float* v, float* output);
|
||||
|
||||
|
||||
|
|
|
@ -62,7 +62,7 @@ CC_DLL kmPlane* const kmPlaneFromPoints(kmPlane* pOut, const struct kmVec3* p1,
|
|||
CC_DLL kmVec3* const kmPlaneIntersectLine(struct kmVec3* pOut, const kmPlane* pP, const struct kmVec3* pV1, const struct kmVec3* pV2);
|
||||
CC_DLL kmPlane* const kmPlaneNormalize(kmPlane* pOut, const kmPlane* pP);
|
||||
CC_DLL kmPlane* const kmPlaneScale(kmPlane* pOut, const kmPlane* pP, kmScalar s);
|
||||
CC_DLL const POINT_CLASSIFICATION kmPlaneClassifyPoint(const kmPlane* pIn, const kmVec3* pP); /** Classifys a point against a plane */
|
||||
CC_DLL const POINT_CLASSIFICATION kmPlaneClassifyPoint(const kmPlane* pIn, const kmVec3* pP); /** Classifies a point against a plane */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -100,7 +100,7 @@ void kmGLPushMatrix(void)
|
|||
void kmGLPopMatrix(void)
|
||||
{
|
||||
assert(initialized && "Cannot Pop empty matrix stack");
|
||||
//No need to lazy initialize, you shouldnt be popping first anyway!
|
||||
//No need to lazy initialize, you shouldn't be popping first anyway!
|
||||
km_mat4_stack_pop(current_stack, NULL);
|
||||
}
|
||||
|
||||
|
|
|
@ -55,7 +55,7 @@ const kmScalar kmMat3Determinant(const kmMat3* pIn)
|
|||
m = | 1 4 7 | 1 4 |
|
||||
| 2 5 8 | 2 5 |
|
||||
now sum up the products of the diagonals going to the right (i.e. 0,4,8)
|
||||
and substract the products of the other diagonals (i.e. 2,4,6)
|
||||
and subtract the products of the other diagonals (i.e. 2,4,6)
|
||||
*/
|
||||
|
||||
output = pIn->mat[0] * pIn->mat[4] * pIn->mat[8] + pIn->mat[1] * pIn->mat[5] * pIn->mat[6] + pIn->mat[2] * pIn->mat[3] * pIn->mat[7];
|
||||
|
|
|
@ -41,7 +41,7 @@ public:
|
|||
// The back key clicked
|
||||
virtual void keyBackClicked() {}
|
||||
|
||||
// The menu key clicked. only avialble on wophone & android
|
||||
// The menu key clicked. only available on wophone & android
|
||||
virtual void keyMenuClicked() {};
|
||||
};
|
||||
|
||||
|
|
|
@ -931,7 +931,7 @@ void CCLabelBMFont::createFontChars()
|
|||
// Color MUST be set before opacity, since opacity might change color if OpacityModifyRGB is on
|
||||
fontChar->setColor(m_tColor);
|
||||
|
||||
// only apply opaccity if it is different than 255 )
|
||||
// only apply opacity if it is different than 255 )
|
||||
// to prevent modifying the color too (issue #610)
|
||||
if( m_cOpacity != 255 )
|
||||
{
|
||||
|
|
|
@ -93,7 +93,7 @@ typedef struct _BMFontPadding {
|
|||
*/
|
||||
class CC_DLL CCBMFontConfiguration : public CCObject
|
||||
{
|
||||
// XXX: Creating a public interface so that the bitmapFontArray[] is accesible
|
||||
// XXX: Creating a public interface so that the bitmapFontArray[] is accessible
|
||||
public://@public
|
||||
// BMFont definitions
|
||||
struct _FontDefHashElement* m_pFontDefDictionary;
|
||||
|
@ -142,7 +142,7 @@ Features:
|
|||
- scaled
|
||||
- translated
|
||||
- tinted
|
||||
- chage the opacity
|
||||
- change the opacity
|
||||
- It can be used as part of a menu item.
|
||||
- anchorPoint can be used to align the "label"
|
||||
- Supports AngelCode text format
|
||||
|
@ -202,11 +202,11 @@ public:
|
|||
@since v0.99.3
|
||||
*/
|
||||
static void purgeCachedData();
|
||||
/** creates a bitmap font altas with an initial string and the FNT file
|
||||
/** creates a bitmap font atlas with an initial string and the FNT file
|
||||
@deprecated: This interface will be deprecated sooner or later.
|
||||
*/
|
||||
CC_DEPRECATED_ATTRIBUTE static CCLabelBMFont * labelWithString(const char *str, const char *fntFile, float width = kCCLabelAutomaticWidth, CCTextAlignment alignment = kCCTextAlignmentLeft, CCPoint imageOffset = CCPointZero);
|
||||
/** creates a bitmap font altas with an initial string and the FNT file */
|
||||
/** creates a bitmap font atlas with an initial string and the FNT file */
|
||||
static CCLabelBMFont * create(const char *str, const char *fntFile, float width, CCTextAlignment alignment, CCPoint imageOffset);
|
||||
|
||||
static CCLabelBMFont * create(const char *str, const char *fntFile, float width, CCTextAlignment alignment) {
|
||||
|
@ -231,7 +231,7 @@ public:
|
|||
static CCLabelBMFont * create();
|
||||
|
||||
bool init();
|
||||
/** init a bitmap font altas with an initial string and the FNT file */
|
||||
/** init a bitmap font atlas with an initial string and the FNT file */
|
||||
bool initWithString(const char *str, const char *fntFile, float width = kCCLabelAutomaticWidth, CCTextAlignment alignment = kCCTextAlignmentLeft, CCPoint imageOffset = CCPointZero);
|
||||
|
||||
/** updates the font chars based on the string to render */
|
||||
|
|
|
@ -227,7 +227,7 @@ void CCLabelTTF::setDimensions(const CCSize &dim)
|
|||
{
|
||||
m_tDimensions = dim;
|
||||
|
||||
// Force udpate
|
||||
// Force update
|
||||
if (m_string.size() > 0)
|
||||
{
|
||||
this->updateTexture();
|
||||
|
|
|
@ -123,7 +123,7 @@ void CCLayer::registerWithTouchDispatcher()
|
|||
void CCLayer::registerScriptTouchHandler(int nHandler, bool bIsMultiTouches, int nPriority, bool bSwallowsTouches)
|
||||
{
|
||||
unregisterScriptTouchHandler();
|
||||
m_pScriptHandlerEntry = CCTouchScriptHandlerEntry::entryWithHandler(nHandler, bIsMultiTouches, nPriority, bSwallowsTouches);
|
||||
m_pScriptHandlerEntry = CCTouchScriptHandlerEntry::create(nHandler, bIsMultiTouches, nPriority, bSwallowsTouches);
|
||||
m_pScriptHandlerEntry->retain();
|
||||
}
|
||||
|
||||
|
@ -138,22 +138,12 @@ void CCLayer::unregisterScriptTouchHandler(void)
|
|||
|
||||
int CCLayer::excuteScriptTouchHandler(int nEventType, CCTouch *pTouch)
|
||||
{
|
||||
return CCScriptEngineManager::sharedManager()->getScriptEngine()->executeTouchEvent(m_pScriptHandlerEntry->getHandler(), nEventType, pTouch);
|
||||
return CCScriptEngineManager::sharedManager()->getScriptEngine()->executeLayerTouchEvent(this, nEventType, pTouch);
|
||||
}
|
||||
|
||||
int CCLayer::excuteScriptTouchHandler(int nEventType, CCSet *pTouches)
|
||||
{
|
||||
int ret = 0;
|
||||
if (kScriptTypeJavascript == m_eScriptType)
|
||||
{
|
||||
ret = CCScriptEngineManager::sharedManager()->getScriptEngine()->executeTouchesEvent(1, nEventType, pTouches, this);
|
||||
}
|
||||
else if (kScriptTypeLua == m_eScriptType)
|
||||
{
|
||||
ret = CCScriptEngineManager::sharedManager()->getScriptEngine()->executeTouchesEvent(m_pScriptHandlerEntry->getHandler(), nEventType, pTouches, this);
|
||||
}
|
||||
|
||||
return ret;
|
||||
return CCScriptEngineManager::sharedManager()->getScriptEngine()->executeLayerTouchesEvent(this, nEventType, pTouches);
|
||||
}
|
||||
|
||||
/// isTouchEnabled getter
|
||||
|
@ -257,7 +247,7 @@ void CCLayer::onEnter()
|
|||
pDirector->getAccelerometer()->setDelegate(this);
|
||||
}
|
||||
|
||||
// add this layer to concern the kaypad msg
|
||||
// add this layer to concern the keypad msg
|
||||
if (m_bIsKeypadEnabled)
|
||||
{
|
||||
pDirector->getKeypadDispatcher()->addDelegate(this);
|
||||
|
@ -279,7 +269,7 @@ void CCLayer::onExit()
|
|||
pDirector->getAccelerometer()->setDelegate(NULL);
|
||||
}
|
||||
|
||||
// remove this layer from the delegates who concern the kaypad msg
|
||||
// remove this layer from the delegates who concern the keypad msg
|
||||
if (m_bIsKeypadEnabled)
|
||||
{
|
||||
pDirector->getKeypadDispatcher()->removeDelegate(this);
|
||||
|
@ -301,7 +291,7 @@ void CCLayer::onEnterTransitionDidFinish()
|
|||
|
||||
bool CCLayer::ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent)
|
||||
{
|
||||
if (kScriptTypeJavascript == m_eScriptType || (kScriptTypeLua == m_eScriptType && m_pScriptHandlerEntry))
|
||||
if (kScriptTypeNone != m_eScriptType)
|
||||
{
|
||||
return excuteScriptTouchHandler(CCTOUCHBEGAN, pTouch) == 0 ? false : true;
|
||||
}
|
||||
|
@ -314,7 +304,7 @@ bool CCLayer::ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent)
|
|||
|
||||
void CCLayer::ccTouchMoved(CCTouch *pTouch, CCEvent *pEvent)
|
||||
{
|
||||
if (kScriptTypeJavascript == m_eScriptType || (kScriptTypeLua == m_eScriptType && m_pScriptHandlerEntry))
|
||||
if (kScriptTypeNone != m_eScriptType)
|
||||
{
|
||||
excuteScriptTouchHandler(CCTOUCHMOVED, pTouch);
|
||||
return;
|
||||
|
@ -326,7 +316,7 @@ void CCLayer::ccTouchMoved(CCTouch *pTouch, CCEvent *pEvent)
|
|||
|
||||
void CCLayer::ccTouchEnded(CCTouch *pTouch, CCEvent *pEvent)
|
||||
{
|
||||
if (kScriptTypeJavascript == m_eScriptType || (kScriptTypeLua == m_eScriptType && m_pScriptHandlerEntry))
|
||||
if (kScriptTypeNone != m_eScriptType)
|
||||
{
|
||||
excuteScriptTouchHandler(CCTOUCHENDED, pTouch);
|
||||
return;
|
||||
|
@ -338,7 +328,7 @@ void CCLayer::ccTouchEnded(CCTouch *pTouch, CCEvent *pEvent)
|
|||
|
||||
void CCLayer::ccTouchCancelled(CCTouch *pTouch, CCEvent *pEvent)
|
||||
{
|
||||
if (kScriptTypeJavascript == m_eScriptType || (kScriptTypeLua == m_eScriptType && m_pScriptHandlerEntry))
|
||||
if (kScriptTypeNone != m_eScriptType)
|
||||
{
|
||||
excuteScriptTouchHandler(CCTOUCHCANCELLED, pTouch);
|
||||
return;
|
||||
|
@ -350,7 +340,7 @@ void CCLayer::ccTouchCancelled(CCTouch *pTouch, CCEvent *pEvent)
|
|||
|
||||
void CCLayer::ccTouchesBegan(CCSet *pTouches, CCEvent *pEvent)
|
||||
{
|
||||
if (kScriptTypeJavascript == m_eScriptType || (kScriptTypeLua == m_eScriptType && m_pScriptHandlerEntry))
|
||||
if (kScriptTypeNone != m_eScriptType)
|
||||
{
|
||||
excuteScriptTouchHandler(CCTOUCHBEGAN, pTouches);
|
||||
return;
|
||||
|
@ -362,7 +352,7 @@ void CCLayer::ccTouchesBegan(CCSet *pTouches, CCEvent *pEvent)
|
|||
|
||||
void CCLayer::ccTouchesMoved(CCSet *pTouches, CCEvent *pEvent)
|
||||
{
|
||||
if (kScriptTypeJavascript == m_eScriptType || (kScriptTypeLua == m_eScriptType && m_pScriptHandlerEntry))
|
||||
if (kScriptTypeNone != m_eScriptType)
|
||||
{
|
||||
excuteScriptTouchHandler(CCTOUCHMOVED, pTouches);
|
||||
return;
|
||||
|
@ -374,7 +364,7 @@ void CCLayer::ccTouchesMoved(CCSet *pTouches, CCEvent *pEvent)
|
|||
|
||||
void CCLayer::ccTouchesEnded(CCSet *pTouches, CCEvent *pEvent)
|
||||
{
|
||||
if (kScriptTypeJavascript == m_eScriptType || (kScriptTypeLua == m_eScriptType && m_pScriptHandlerEntry))
|
||||
if (kScriptTypeNone != m_eScriptType)
|
||||
{
|
||||
excuteScriptTouchHandler(CCTOUCHENDED, pTouches);
|
||||
return;
|
||||
|
@ -386,7 +376,7 @@ void CCLayer::ccTouchesEnded(CCSet *pTouches, CCEvent *pEvent)
|
|||
|
||||
void CCLayer::ccTouchesCancelled(CCSet *pTouches, CCEvent *pEvent)
|
||||
{
|
||||
if (kScriptTypeJavascript == m_eScriptType || (kScriptTypeLua == m_eScriptType && m_pScriptHandlerEntry))
|
||||
if (kScriptTypeNone != m_eScriptType)
|
||||
{
|
||||
excuteScriptTouchHandler(CCTOUCHCANCELLED, pTouches);
|
||||
return;
|
||||
|
|
|
@ -119,6 +119,7 @@ public:
|
|||
bool isKeypadEnabled();
|
||||
void setKeypadEnabled(bool value);
|
||||
|
||||
inline CCTouchScriptHandlerEntry* getScriptHandlerEntry() { return m_pScriptHandlerEntry; };
|
||||
protected:
|
||||
bool m_bIsTouchEnabled;
|
||||
bool m_bIsAccelerometerEnabled;
|
||||
|
@ -292,7 +293,7 @@ public:
|
|||
|
||||
/**
|
||||
* lua script can not init with undetermined number of variables
|
||||
* so add these functinons to be used with lua.
|
||||
* so add these functions to be used with lua.
|
||||
@deprecated: This interface will be deprecated sooner or later.
|
||||
*/
|
||||
CC_DEPRECATED_ATTRIBUTE static CCLayerMultiplex * layerWithLayer(CCLayer* layer);
|
||||
|
@ -302,7 +303,7 @@ public:
|
|||
|
||||
/**
|
||||
* lua script can not init with undetermined number of variables
|
||||
* so add these functinons to be used with lua.
|
||||
* so add these functions to be used with lua.
|
||||
*/
|
||||
static CCLayerMultiplex * createWithLayer(CCLayer* layer);
|
||||
|
||||
|
|
|
@ -130,7 +130,7 @@ public:
|
|||
/** called after the transition finishes */
|
||||
void finish(void);
|
||||
|
||||
/** used by some transitions to hide the outter scene */
|
||||
/** used by some transitions to hide the outer scene */
|
||||
void hideOutShowIn(void);
|
||||
|
||||
protected:
|
||||
|
@ -266,7 +266,7 @@ public:
|
|||
|
||||
/** initializes the scenes */
|
||||
virtual void initScenes(void);
|
||||
/** returns the action that will be performed by the incomming and outgoing scene */
|
||||
/** returns the action that will be performed by the incoming and outgoing scene */
|
||||
virtual CCActionInterval* action(void);
|
||||
|
||||
virtual void onEnter();
|
||||
|
@ -290,7 +290,7 @@ public:
|
|||
|
||||
/** initializes the scenes */
|
||||
virtual void initScenes(void);
|
||||
/** returns the action that will be performed by the incomming and outgoing scene */
|
||||
/** returns the action that will be performed by the incoming and outgoing scene */
|
||||
virtual CCActionInterval* action(void);
|
||||
|
||||
TRANSITION_CREATE_FUNC(CCTransitionSlideInR);
|
||||
|
@ -310,7 +310,7 @@ public:
|
|||
|
||||
/** initializes the scenes */
|
||||
virtual void initScenes(void);
|
||||
/** returns the action that will be performed by the incomming and outgoing scene */
|
||||
/** returns the action that will be performed by the incoming and outgoing scene */
|
||||
virtual CCActionInterval* action(void);
|
||||
|
||||
TRANSITION_CREATE_FUNC(CCTransitionSlideInB);
|
||||
|
@ -330,7 +330,7 @@ public:
|
|||
|
||||
/** initializes the scenes */
|
||||
virtual void initScenes(void);
|
||||
/** returns the action that will be performed by the incomming and outgoing scene */
|
||||
/** returns the action that will be performed by the incoming and outgoing scene */
|
||||
virtual CCActionInterval* action(void);
|
||||
|
||||
TRANSITION_CREATE_FUNC(CCTransitionSlideInT);
|
||||
|
|
|
@ -59,7 +59,7 @@ protected:
|
|||
|
||||
|
||||
/** CCTransitionRadialCCW transition.
|
||||
A counter colock-wise radial transition to the next scene
|
||||
A counter clock-wise radial transition to the next scene
|
||||
*/
|
||||
class CC_DLL CCTransitionProgressRadialCCW : public CCTransitionProgress
|
||||
{
|
||||
|
@ -73,7 +73,7 @@ protected:
|
|||
|
||||
|
||||
/** CCTransitionRadialCW transition.
|
||||
A counter colock-wise radial transition to the next scene
|
||||
A counter clock-wise radial transition to the next scene
|
||||
*/
|
||||
class CC_DLL CCTransitionProgressRadialCW : public CCTransitionProgress
|
||||
{
|
||||
|
@ -86,7 +86,7 @@ protected:
|
|||
};
|
||||
|
||||
/** CCTransitionProgressHorizontal transition.
|
||||
A colock-wise radial transition to the next scene
|
||||
A clock-wise radial transition to the next scene
|
||||
*/
|
||||
class CC_DLL CCTransitionProgressHorizontal : public CCTransitionProgress
|
||||
{
|
||||
|
|
|
@ -51,7 +51,7 @@ enum {
|
|||
*
|
||||
* Features and Limitation:
|
||||
* - You can add MenuItem objects in runtime using addChild:
|
||||
* - But the only accecpted children are MenuItem objects
|
||||
* - But the only accepted children are MenuItem objects
|
||||
*/
|
||||
class CC_DLL CCMenu : public CCLayer, public CCRGBAProtocol
|
||||
{
|
||||
|
|
|
@ -80,7 +80,7 @@ bool CCMenuItem::initWithTarget(CCObject *rec, SEL_MenuHandler selector)
|
|||
|
||||
CCMenuItem::~CCMenuItem()
|
||||
{
|
||||
unregisterScriptHandler();
|
||||
unregisterScriptTapHandler();
|
||||
}
|
||||
|
||||
void CCMenuItem::selected()
|
||||
|
@ -93,20 +93,20 @@ void CCMenuItem::unselected()
|
|||
m_bIsSelected = false;
|
||||
}
|
||||
|
||||
void CCMenuItem::registerScriptHandler(int nHandler)
|
||||
void CCMenuItem::registerScriptTapHandler(int nHandler)
|
||||
{
|
||||
unregisterScriptHandler();
|
||||
m_nScriptHandler = nHandler;
|
||||
LUALOG("[LUA] Add CCMenuItem script handler: %d", m_nScriptHandler);
|
||||
unregisterScriptTapHandler();
|
||||
m_nScriptTapHandler = nHandler;
|
||||
LUALOG("[LUA] Add CCMenuItem script handler: %d", m_nScriptTapHandler);
|
||||
}
|
||||
|
||||
void CCMenuItem::unregisterScriptHandler(void)
|
||||
void CCMenuItem::unregisterScriptTapHandler(void)
|
||||
{
|
||||
if (m_nScriptHandler)
|
||||
if (m_nScriptTapHandler)
|
||||
{
|
||||
CCScriptEngineManager::sharedManager()->getScriptEngine()->removeLuaHandler(m_nScriptHandler);
|
||||
LUALOG("[LUA] Remove CCMenuItem script handler: %d", m_nScriptHandler);
|
||||
m_nScriptHandler = 0;
|
||||
CCScriptEngineManager::sharedManager()->getScriptEngine()->removeScriptHandler(m_nScriptTapHandler);
|
||||
LUALOG("[LUA] Remove CCMenuItem script handler: %d", m_nScriptTapHandler);
|
||||
m_nScriptTapHandler = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -119,13 +119,9 @@ void CCMenuItem::activate()
|
|||
(m_pListener->*m_pfnSelector)(this);
|
||||
}
|
||||
|
||||
if (kScriptTypeJavascript == m_eScriptType)
|
||||
if (kScriptTypeNone != m_eScriptType)
|
||||
{
|
||||
CCScriptEngineManager::sharedManager()->getScriptEngine()->executeFunctionWithIntegerData(m_nScriptHandler, kCCMenuItemActivated, this);
|
||||
}
|
||||
else if( kScriptTypeLua == m_eScriptType && m_nScriptHandler != 0)
|
||||
{
|
||||
CCScriptEngineManager::sharedManager()->getScriptEngine()->executeFunctionWithIntegerData(m_nScriptHandler, getTag(), this);
|
||||
CCScriptEngineManager::sharedManager()->getScriptEngine()->executeMenuItemEvent(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -65,7 +65,7 @@ public:
|
|||
, m_bIsEnabled(false)
|
||||
, m_pListener(NULL)
|
||||
, m_pfnSelector(NULL)
|
||||
, m_nScriptHandler(0)
|
||||
, m_nScriptTapHandler(0)
|
||||
{}
|
||||
virtual ~CCMenuItem();
|
||||
/** Creates a CCMenuItem with a target/selector
|
||||
|
@ -88,9 +88,10 @@ public:
|
|||
virtual void unselected();
|
||||
|
||||
/** Register menu handler script function */
|
||||
virtual void registerScriptHandler(int nHandler);
|
||||
virtual void unregisterScriptHandler(void);
|
||||
|
||||
virtual void registerScriptTapHandler(int nHandler);
|
||||
virtual void unregisterScriptTapHandler(void);
|
||||
int getScriptTapHandler() { return m_nScriptTapHandler; };
|
||||
|
||||
virtual bool isEnabled();
|
||||
//@note: It's 'setIsEnable' in cocos2d-iphone.
|
||||
virtual void setEnabled(bool value);
|
||||
|
@ -98,10 +99,11 @@ public:
|
|||
|
||||
/** set the target/selector of the menu item*/
|
||||
void setTarget(CCObject *rec, SEL_MenuHandler selector);
|
||||
|
||||
protected:
|
||||
CCObject* m_pListener;
|
||||
SEL_MenuHandler m_pfnSelector;
|
||||
int m_nScriptHandler;
|
||||
int m_nScriptTapHandler;
|
||||
};
|
||||
|
||||
/** @brief An abstract class for "label" CCMenuItemLabel items
|
||||
|
@ -127,14 +129,14 @@ public:
|
|||
@deprecated: This interface will be deprecated sooner or later.
|
||||
*/
|
||||
CC_DEPRECATED_ATTRIBUTE static CCMenuItemLabel * itemWithLabel(CCNode*label, CCObject* target, SEL_MenuHandler selector);
|
||||
/** creates a CCMenuItemLabel with a Label. Target and selector will be nill
|
||||
/** creates a CCMenuItemLabel with a Label. Target and selector will be nil
|
||||
@deprecated: This interface will be deprecated sooner or later.
|
||||
*/
|
||||
CC_DEPRECATED_ATTRIBUTE static CCMenuItemLabel* itemWithLabel(CCNode *label);
|
||||
|
||||
/** creates a CCMenuItemLabel with a Label, target and selector */
|
||||
static CCMenuItemLabel * create(CCNode*label, CCObject* target, SEL_MenuHandler selector);
|
||||
/** creates a CCMenuItemLabel with a Label. Target and selector will be nill */
|
||||
/** creates a CCMenuItemLabel with a Label. Target and selector will be nil */
|
||||
static CCMenuItemLabel* create(CCNode *label);
|
||||
|
||||
/** initializes a CCMenuItemLabel with a Label, target and selector */
|
||||
|
@ -371,7 +373,7 @@ public:
|
|||
|
||||
/** @brief A CCMenuItemToggle
|
||||
A simple container class that "toggles" it's inner items
|
||||
The inner itmes can be any MenuItem
|
||||
The inner items can be any MenuItem
|
||||
*/
|
||||
class CC_DLL CCMenuItemToggle : public CCMenuItem, public CCRGBAProtocol
|
||||
{
|
||||
|
|
|
@ -299,7 +299,7 @@ void CCMotionStreak::update(float delta)
|
|||
m_pPointVertexes[m_uNuPoints] = m_tPositionR;
|
||||
m_pPointState[m_uNuPoints] = 1.0f;
|
||||
|
||||
// Color asignation
|
||||
// Color assignment
|
||||
const unsigned int offset = m_uNuPoints*8;
|
||||
*((ccColor3B*)(m_pColorPointer + offset)) = m_tColor;
|
||||
*((ccColor3B*)(m_pColorPointer + offset+4)) = m_tColor;
|
||||
|
|
|
@ -87,7 +87,7 @@ public:
|
|||
virtual void setOpacityModifyRGB(bool bValue);
|
||||
virtual bool isOpacityModifyRGB(void);
|
||||
|
||||
/** When fast mode is enbled, new points are added faster but with lower precision */
|
||||
/** When fast mode is enabled, new points are added faster but with lower precision */
|
||||
inline bool isFastMode() { return m_bFastMode; }
|
||||
inline void setFastMode(bool bFastMode) { m_bFastMode = bFastMode; }
|
||||
|
||||
|
|
|
@ -118,7 +118,7 @@ void CCProgressTimer::setSprite(CCSprite *pSprite)
|
|||
m_pSprite = pSprite;
|
||||
setContentSize(m_pSprite->getContentSize());
|
||||
|
||||
// Everytime we set a new sprite, we free the current vertex data
|
||||
// Every time we set a new sprite, we free the current vertex data
|
||||
if (m_pVertexData)
|
||||
{
|
||||
CC_SAFE_FREE(m_pVertexData);
|
||||
|
|
|
@ -45,7 +45,7 @@ typedef enum {
|
|||
} CCProgressTimerType;
|
||||
|
||||
/**
|
||||
@brief CCProgresstimer is a subclass of CCNode.
|
||||
@brief CCProgressTimer is a subclass of CCNode.
|
||||
It renders the inner sprite according to the percentage.
|
||||
The progress can be Radial, Horizontal or vertical.
|
||||
@since v0.99.1
|
||||
|
|
|
@ -431,7 +431,7 @@ CCImage* CCRenderTexture::newCCImage()
|
|||
const CCSize& s = m_pTexture->getContentSizeInPixels();
|
||||
|
||||
// to get the image size to save
|
||||
// if the saving image domain exeeds the buffer texture domain,
|
||||
// if the saving image domain exceeds the buffer texture domain,
|
||||
// it should be cut
|
||||
int nSavedBufferWidth = (int)s.width;
|
||||
int nSavedBufferHeight = (int)s.height;
|
||||
|
@ -458,7 +458,7 @@ CCImage* CCRenderTexture::newCCImage()
|
|||
this->end();
|
||||
|
||||
// to get the actual texture data
|
||||
// #640 the image read from rendertexture is upseted
|
||||
// #640 the image read from rendertexture is dirty
|
||||
for (int i = 0; i < nSavedBufferHeight; ++i)
|
||||
{
|
||||
memcpy(&pBuffer[i * nSavedBufferWidth * 4],
|
||||
|
|
|
@ -44,7 +44,7 @@ typedef enum eImageFormat
|
|||
/**
|
||||
@brief CCRenderTexture is a generic rendering target. To render things into it,
|
||||
simply construct a render target, call begin on it, call visit on any cocos
|
||||
scenes or objects to render them, and call end. For convienience, render texture
|
||||
scenes or objects to render them, and call end. For convenience, render texture
|
||||
adds a sprite as it's display child with the results, so you can simply add
|
||||
the render texture to your scene and treat it like any other CocosNode.
|
||||
There are also functions for saving the render texture to disk in PNG or JPG format.
|
||||
|
|
|
@ -135,7 +135,7 @@ void CCParticleBatchNode::visit()
|
|||
// with the exception that it doesn't call visit on it's children
|
||||
//
|
||||
// The alternative is to have a void CCSprite#visit, but
|
||||
// although this is less mantainable, is faster
|
||||
// although this is less maintainable, is faster
|
||||
//
|
||||
if (!m_bIsVisible)
|
||||
{
|
||||
|
@ -185,7 +185,7 @@ void CCParticleBatchNode::addChild(CCNode * child, int zOrder, int tag)
|
|||
setBlendFunc(pChild->getBlendFunc());
|
||||
}
|
||||
|
||||
CCAssert( m_tBlendFunc.src == pChild->getBlendFunc().src && m_tBlendFunc.dst == pChild->getBlendFunc().dst, "Can't add a PaticleSystem that uses a differnt blending function");
|
||||
CCAssert( m_tBlendFunc.src == pChild->getBlendFunc().src && m_tBlendFunc.dst == pChild->getBlendFunc().dst, "Can't add a PaticleSystem that uses a different blending function");
|
||||
|
||||
//no lazy sorting, so don't call super addChild, call helper instead
|
||||
unsigned int pos = addChildHelper(pChild,zOrder,tag);
|
||||
|
@ -388,7 +388,7 @@ void CCParticleBatchNode::removeChild(CCNode* child, bool cleanup)
|
|||
// after memmove of data, empty the quads at the end of array
|
||||
m_pTextureAtlas->fillWithEmptyQuadsFromIndex(m_pTextureAtlas->getTotalQuads(), pChild->getTotalParticles());
|
||||
|
||||
// paticle could be reused for self rendering
|
||||
// particle could be reused for self rendering
|
||||
pChild->setBatchNode(NULL);
|
||||
|
||||
updateAllAtlasIndexes();
|
||||
|
@ -469,7 +469,7 @@ void CCParticleBatchNode::insertChild(CCParticleSystem* pSystem, unsigned int in
|
|||
m_pTextureAtlas->moveQuadsFromIndex(index, index+pSystem->getTotalParticles());
|
||||
}
|
||||
|
||||
// increase totalParticles here for new particles, update method of particlesystem will fill the quads
|
||||
// increase totalParticles here for new particles, update method of particle-system will fill the quads
|
||||
m_pTextureAtlas->increaseTotalQuadsWith(pSystem->getTotalParticles());
|
||||
|
||||
updateAllAtlasIndexes();
|
||||
|
|
|
@ -263,7 +263,7 @@ bool CCParticleGalaxy::initWithTotalParticles(unsigned int numberOfParticles)
|
|||
modeA.radialAccel = -80;
|
||||
modeA.radialAccelVar = 0;
|
||||
|
||||
// Gravity Mode: tagential
|
||||
// Gravity Mode: tangential
|
||||
modeA.tangentialAccel = 80;
|
||||
modeA.tangentialAccelVar = 0;
|
||||
|
||||
|
@ -337,7 +337,7 @@ bool CCParticleFlower::initWithTotalParticles(unsigned int numberOfParticles)
|
|||
modeA.radialAccel = -60;
|
||||
modeA.radialAccelVar = 0;
|
||||
|
||||
// Gravity Mode: tagential
|
||||
// Gravity Mode: tangential
|
||||
modeA.tangentialAccel = 15;
|
||||
modeA.tangentialAccelVar = 0;
|
||||
|
||||
|
@ -410,7 +410,7 @@ bool CCParticleMeteor::initWithTotalParticles(unsigned int numberOfParticles)
|
|||
modeA.radialAccel = 0;
|
||||
modeA.radialAccelVar = 0;
|
||||
|
||||
// Gravity Mode: tagential
|
||||
// Gravity Mode: tangential
|
||||
modeA.tangentialAccel = 0;
|
||||
modeA.tangentialAccelVar = 0;
|
||||
|
||||
|
@ -484,7 +484,7 @@ bool CCParticleSpiral::initWithTotalParticles(unsigned int numberOfParticles)
|
|||
modeA.radialAccel = -380;
|
||||
modeA.radialAccelVar = 0;
|
||||
|
||||
// Gravity Mode: tagential
|
||||
// Gravity Mode: tangential
|
||||
modeA.tangentialAccel = 45;
|
||||
modeA.tangentialAccelVar = 0;
|
||||
|
||||
|
@ -557,7 +557,7 @@ bool CCParticleExplosion::initWithTotalParticles(unsigned int numberOfParticles)
|
|||
modeA.radialAccel = 0;
|
||||
modeA.radialAccelVar = 0;
|
||||
|
||||
// Gravity Mode: tagential
|
||||
// Gravity Mode: tangential
|
||||
modeA.tangentialAccel = 0;
|
||||
modeA.tangentialAccelVar = 0;
|
||||
|
||||
|
@ -700,7 +700,7 @@ bool CCParticleSnow::initWithTotalParticles(unsigned int numberOfParticles)
|
|||
modeA.radialAccel = 0;
|
||||
modeA.radialAccelVar = 1;
|
||||
|
||||
// Gravity mode: tagential
|
||||
// Gravity mode: tangential
|
||||
modeA.tangentialAccel = 0;
|
||||
modeA.tangentialAccelVar = 1;
|
||||
|
||||
|
@ -768,7 +768,7 @@ bool CCParticleRain::initWithTotalParticles(unsigned int numberOfParticles)
|
|||
modeA.radialAccel = 0;
|
||||
modeA.radialAccelVar = 1;
|
||||
|
||||
// Gravity Mode: tagential
|
||||
// Gravity Mode: tangential
|
||||
modeA.tangentialAccel = 0;
|
||||
modeA.tangentialAccelVar = 1;
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ THE SOFTWARE.
|
|||
// http://particledesigner.71squared.com/
|
||||
//
|
||||
// IMPORTANT: Particle Designer is supported by cocos2d, but
|
||||
// 'Radius Mode' in Particle Designer uses a fixed emit rate of 30 hz. Since that can't be guarateed in cocos2d,
|
||||
// 'Radius Mode' in Particle Designer uses a fixed emit rate of 30 hz. Since that can't be guaranteed in cocos2d,
|
||||
// cocos2d uses a another approach, but the results are almost identical.
|
||||
//
|
||||
|
||||
|
@ -73,7 +73,7 @@ NS_CC_BEGIN
|
|||
// http://particledesigner.71squared.com/
|
||||
//
|
||||
// IMPORTANT: Particle Designer is supported by cocos2d, but
|
||||
// 'Radius Mode' in Particle Designer uses a fixed emit rate of 30 hz. Since that can't be guarateed in cocos2d,
|
||||
// 'Radius Mode' in Particle Designer uses a fixed emit rate of 30 hz. Since that can't be guaranteed in cocos2d,
|
||||
// cocos2d uses a another approach, but the results are almost identical.
|
||||
//
|
||||
|
||||
|
@ -392,12 +392,12 @@ bool CCParticleSystem::initWithTotalParticles(unsigned int numberOfParticles)
|
|||
|
||||
m_bIsAutoRemoveOnFinish = false;
|
||||
|
||||
// Optimization: compile udpateParticle method
|
||||
// Optimization: compile updateParticle method
|
||||
//updateParticleSel = @selector(updateQuadWithParticle:newPosition:);
|
||||
//updateParticleImp = (CC_UPDATE_PARTICLE_IMP) [self methodForSelector:updateParticleSel];
|
||||
//for batchNode
|
||||
m_bTransformSystemDirty = false;
|
||||
// udpate after action in run!
|
||||
// update after action in run!
|
||||
this->scheduleUpdateWithPriority(1);
|
||||
|
||||
return true;
|
||||
|
@ -734,12 +734,12 @@ void CCParticleSystem::updateQuadWithParticle(tCCParticle* particle, const CCPoi
|
|||
{
|
||||
CC_UNUSED_PARAM(particle);
|
||||
CC_UNUSED_PARAM(newPosition);
|
||||
// should be overriden
|
||||
// should be overridden
|
||||
}
|
||||
|
||||
void CCParticleSystem::postStep()
|
||||
{
|
||||
// should be overriden
|
||||
// should be overridden
|
||||
}
|
||||
|
||||
// ParticleSystem - CCTexture protocol
|
||||
|
|
|
@ -131,7 +131,7 @@ class CCTexture2D;
|
|||
|
||||
/** @brief Particle System base class.
|
||||
Attributes of a Particle System:
|
||||
- emmision rate of the particles
|
||||
- emission rate of the particles
|
||||
- Gravity Mode (Mode A):
|
||||
- gravity
|
||||
- direction
|
||||
|
@ -155,7 +155,7 @@ Attributes of a Particle System:
|
|||
- texture
|
||||
|
||||
cocos2d also supports particles generated by Particle Designer (http://particledesigner.71squared.com/).
|
||||
'Radius Mode' in Particle Designer uses a fixed emit rate of 30 hz. Since that can't be guarateed in cocos2d,
|
||||
'Radius Mode' in Particle Designer uses a fixed emit rate of 30 hz. Since that can't be guaranteed in cocos2d,
|
||||
cocos2d uses a another approach, but the results are almost identical.
|
||||
|
||||
cocos2d supports all the variables used by Particle Designer plus a bit more:
|
||||
|
@ -208,7 +208,7 @@ protected:
|
|||
float endRadius;
|
||||
/** The ending radius variance of the particles. Only available in 'Radius' mode. */
|
||||
float endRadiusVar;
|
||||
/** Number of degress to rotate a particle around the source pos per second. Only available in 'Radius' mode. */
|
||||
/** Number of degrees to rotate a particle around the source pos per second. Only available in 'Radius' mode. */
|
||||
float rotatePerSecond;
|
||||
/** Variance in degrees for rotatePerSecond. Only available in 'Radius' mode. */
|
||||
float rotatePerSecondVar;
|
||||
|
@ -245,7 +245,7 @@ protected:
|
|||
bool m_bIsActive;
|
||||
/** Quantity of particles that are being simulated at the moment */
|
||||
CC_PROPERTY_READONLY(unsigned int, m_uParticleCount, ParticleCount)
|
||||
/** How many seconds the emitter wil run. -1 means 'forever' */
|
||||
/** How many seconds the emitter will run. -1 means 'forever' */
|
||||
CC_PROPERTY(float, m_fDuration, Duration)
|
||||
/** sourcePosition of the emitter */
|
||||
CC_PROPERTY_PASS_BY_REF(CCPoint, m_tSourcePosition, SourcePosition)
|
||||
|
@ -368,7 +368,7 @@ public:
|
|||
CCParticleSystem();
|
||||
virtual ~CCParticleSystem();
|
||||
/** creates an initializes a CCParticleSystem from a plist file.
|
||||
This plist files can be creted manually or with Particle Designer:
|
||||
This plist files can be created manually or with Particle Designer:
|
||||
http://particledesigner.71squared.com/
|
||||
@deprecated: This interface will be deprecated sooner or later.
|
||||
@since v0.99.3
|
||||
|
@ -376,7 +376,7 @@ public:
|
|||
CC_DEPRECATED_ATTRIBUTE static CCParticleSystem * particleWithFile(const char *plistFile);
|
||||
|
||||
/** creates an initializes a CCParticleSystem from a plist file.
|
||||
This plist files can be creted manually or with Particle Designer:
|
||||
This plist files can be created manually or with Particle Designer:
|
||||
http://particledesigner.71squared.com/
|
||||
@since v2.0
|
||||
*/
|
||||
|
@ -388,7 +388,7 @@ public:
|
|||
/** initializes a CCParticleSystem*/
|
||||
bool init();
|
||||
/** initializes a CCParticleSystem from a plist file.
|
||||
This plist files can be creted manually or with Particle Designer:
|
||||
This plist files can be created manually or with Particle Designer:
|
||||
http://particledesigner.71squared.com/
|
||||
@since v0.99.3
|
||||
*/
|
||||
|
@ -412,9 +412,9 @@ public:
|
|||
//! whether or not the system is full
|
||||
bool isFull();
|
||||
|
||||
//! should be overriden by subclasses
|
||||
//! should be overridden by subclasses
|
||||
virtual void updateQuadWithParticle(tCCParticle* particle, const CCPoint& newPosition);
|
||||
//! should be overriden by subclasses
|
||||
//! should be overridden by subclasses
|
||||
virtual void postStep();
|
||||
|
||||
virtual void update(float dt);
|
||||
|
|
|
@ -381,7 +381,7 @@ void CCParticleSystemQuad::draw()
|
|||
|
||||
void CCParticleSystemQuad::setTotalParticles(unsigned int tp)
|
||||
{
|
||||
// If we are setting the total numer of particles to a number higher
|
||||
// If we are setting the total number of particles to a number higher
|
||||
// than what is allocated, we need to allocate new arrays
|
||||
if( tp > m_uAllocatedParticles )
|
||||
{
|
||||
|
|
|
@ -67,20 +67,20 @@ public:
|
|||
virtual ~CCParticleSystemQuad();
|
||||
|
||||
/** creates an initializes a CCParticleSystemQuad from a plist file.
|
||||
This plist files can be creted manually or with Particle Designer:
|
||||
This plist files can be created manually or with Particle Designer:
|
||||
@deprecated: This interface will be deprecated sooner or later.
|
||||
*/
|
||||
CC_DEPRECATED_ATTRIBUTE static CCParticleSystemQuad * particleWithFile(const char *plistFile);
|
||||
|
||||
/** creates an initializes a CCParticleSystemQuad from a plist file.
|
||||
This plist files can be creted manually or with Particle Designer:
|
||||
This plist files can be created manually or with Particle Designer:
|
||||
*/
|
||||
static CCParticleSystemQuad * create(const char *plistFile);
|
||||
|
||||
/** initialices the indices for the vertices*/
|
||||
/** initializes the indices for the vertices*/
|
||||
void setupIndices();
|
||||
|
||||
/** initilizes the texture with a rectangle measured Points */
|
||||
/** initializes the texture with a rectangle measured Points */
|
||||
void initTexCoordsWithRect(const CCRect& rect);
|
||||
|
||||
/** Sets a new CCSpriteFrame as particle.
|
||||
|
|
|
@ -46,7 +46,7 @@ public:
|
|||
|
||||
/**
|
||||
@brief Callback by CCDirector for limit FPS.
|
||||
@interval The time, which expressed in second in second, between current frame and next.
|
||||
@interval The time, expressed in seconds, between current frame and next.
|
||||
*/
|
||||
virtual void setAnimationInterval(double interval) = 0;
|
||||
|
||||
|
|
|
@ -47,14 +47,13 @@ void CC_DLL CCLog(const char * pszFormat, ...);
|
|||
*/
|
||||
void CC_DLL CCLuaLog(const char * pszFormat);
|
||||
|
||||
|
||||
/**
|
||||
@brief Pop out a message box
|
||||
*/
|
||||
void CC_DLL CCMessageBox(const char * pszMsg, const char * pszTitle);
|
||||
|
||||
/**
|
||||
@brief Enum the language type supportted now
|
||||
@brief Enum the language type supported now
|
||||
*/
|
||||
typedef enum LanguageType
|
||||
{
|
||||
|
|
|
@ -91,7 +91,7 @@ void CCEGLViewProtocol::setDesignResolutionSize(float width, float height, Resol
|
|||
|
||||
//setViewPortInPoints(0, 0,m_obScreenSize.width, m_obScreenSize.height);
|
||||
|
||||
// reset director's member vaviables to fit visible rect
|
||||
// reset director's member variables to fit visible rect
|
||||
CCDirector::sharedDirector()->createStatsLabel();
|
||||
CCDirector::sharedDirector()->m_obWinSizeInPoints = CCDirector::sharedDirector()->m_obWinSizeInPixels = getSize();
|
||||
CCDirector::sharedDirector()->setGLDefaultValues();
|
||||
|
|
|
@ -36,7 +36,7 @@ public:
|
|||
CCEGLViewProtocol();
|
||||
virtual ~CCEGLViewProtocol();
|
||||
|
||||
/** Force destorying EGL view, subclass must implement this method. */
|
||||
/** Force destroying EGL view, subclass must implement this method. */
|
||||
virtual void end() = 0;
|
||||
|
||||
/** Get whether opengl render system is ready, subclass must implement this method. */
|
||||
|
@ -77,14 +77,14 @@ public:
|
|||
virtual CCPoint getVisibleOrigin() const;
|
||||
|
||||
/**
|
||||
* Set the design resolutin size.
|
||||
* You can't use it with enableRetina together.
|
||||
* Set the design resolution size.
|
||||
* Behavior undefined when enableRetina == true.
|
||||
* @param width Design resolution width.
|
||||
* @param height Design resolution height.
|
||||
* @param resolutionPolicy The resolution policy you need, there are:
|
||||
* [1] kCCResolutionExactFit Fill screen, if the design resolution ratio of width and height is different from the screen resolution ratio, your game view will be stretched.
|
||||
* [2] kCCResolutionNoBorder Full screen without black border, if the design resolution ratio of width and height is different from the screen resolution ratio, two areas of your game view will be cut.
|
||||
* [3] kCCResolutionShowAll Full screen with black border, if the design resolution ratio of width and height is different from the screen resolution ratio, two black border will be shown on the screen;
|
||||
* @param resolutionPolicy The resolution policy desired, you may choose:
|
||||
* [1] kCCResolutionExactFit Fill screen by stretch-to-fit: if the design resolution ratio of width to height is different from the screen resolution ratio, your game view will be stretched.
|
||||
* [2] kCCResolutionNoBorder Full screen without black border: if the design resolution ratio of width to height is different from the screen resolution ratio, two areas of your game view will be cut.
|
||||
* [3] kCCResolutionShowAll Full screen with black border: if the design resolution ratio of width to height is different from the screen resolution ratio, two black borders will be shown.
|
||||
*/
|
||||
virtual void setDesignResolutionSize(float width, float height, ResolutionPolicy resolutionPolicy);
|
||||
|
||||
|
@ -93,7 +93,7 @@ public:
|
|||
|
||||
/**
|
||||
* Set content scale factor.
|
||||
* @return If return true, it means the plaform supports retina display.
|
||||
* @return If the return value is true, the platform supports retina display mode.
|
||||
*/
|
||||
virtual bool setContentScaleFactor(float contentScaleFactor);
|
||||
|
||||
|
@ -113,30 +113,29 @@ public:
|
|||
*/
|
||||
virtual bool enableRetina();
|
||||
|
||||
/** handle touch events by default, if you want to custom your handles, please override these functions */
|
||||
/** Touch events are handled by default; if you want to customize your handlers, please override these functions: */
|
||||
virtual void handleTouchesBegin(int num, int ids[], float xs[], float ys[]);
|
||||
virtual void handleTouchesMove(int num, int ids[], float xs[], float ys[]);
|
||||
virtual void handleTouchesEnd(int num, int ids[], float xs[], float ys[]);
|
||||
virtual void handleTouchesCancel(int num, int ids[], float xs[], float ys[]);
|
||||
|
||||
/**
|
||||
* Get opengl view port rectangle.
|
||||
* Get the opengl view port rectangle.
|
||||
*/
|
||||
const CCRect& getViewPortRect() const;
|
||||
|
||||
/**
|
||||
* Get the scale factor of horizontal direction.
|
||||
*
|
||||
* Get scale factor of the horizontal direction.
|
||||
*/
|
||||
float getScaleX() const;
|
||||
|
||||
/**
|
||||
* Get the scale factor of vertical direction.
|
||||
* Get scale factor of the vertical direction.
|
||||
*/
|
||||
float getScaleY() const;
|
||||
|
||||
/**
|
||||
* Get whether the retina mode is enabled.
|
||||
* Get retina mode status (on if true).
|
||||
*/
|
||||
bool isRetinaEnabled() const;
|
||||
private:
|
||||
|
@ -145,9 +144,9 @@ private:
|
|||
protected:
|
||||
EGLTouchDelegate* m_pDelegate;
|
||||
|
||||
// real size of screen
|
||||
// real screen size
|
||||
CCSize m_obScreenSize;
|
||||
// resolution size, it is the size the app resources designed for
|
||||
// resolution size, it is the size appropriate for the app resources.
|
||||
CCSize m_obDesignResolutionSize;
|
||||
// the view port size
|
||||
CCRect m_obViewPortRect;
|
||||
|
|
|
@ -45,20 +45,20 @@ public:
|
|||
void purgeCachedEntries();
|
||||
/**
|
||||
@brief Get resource file data
|
||||
@param[in] pszFileName The resource file name which contain the path
|
||||
@param[in] pszMode The read mode of the file
|
||||
@param[out] pSize If get the file data succeed the it will be the data size,or it will be 0
|
||||
@return if success,the pointer of data will be returned,or NULL is returned
|
||||
@warning If you get the file data succeed,you must delete[] it after used.
|
||||
@param[in] pszFileName The resource file name which contains the path.
|
||||
@param[in] pszMode The read mode of the file.
|
||||
@param[out] pSize If the file read operation succeeds, it will be the data size, otherwise 0.
|
||||
@return Upon success, a pointer to the data is returned, otherwise NULL.
|
||||
@warning Recall: you are responsible for calling delete[] on any Non-NULL pointer returned.
|
||||
*/
|
||||
unsigned char* getFileData(const char* pszFileName, const char* pszMode, unsigned long * pSize);
|
||||
|
||||
/**
|
||||
@brief Get resource file data from zip file
|
||||
@param[in] pszFileName The resource file name which contain the relative path of zip file
|
||||
@param[out] pSize If get the file data succeed the it will be the data size,or it will be 0
|
||||
@return if success,the pointer of data will be returned,or NULL is returned
|
||||
@warning If you get the file data succeed,you must delete[] it after used.
|
||||
@brief Get resource file data from a zip file.
|
||||
@param[in] pszFileName The resource file name which contains the relative path of the zip file.
|
||||
@param[out] pSize If the file read operation succeeds, it will be the data size, otherwise 0.
|
||||
@return Upon success, a pointer to the data is returned, otherwise NULL.
|
||||
@warning Recall: you are responsible for calling delete[] on any Non-NULL pointer returned.
|
||||
*/
|
||||
unsigned char* getFileDataFromZip(const char* pszZipFilePath, const char* pszFileName, unsigned long * pSize);
|
||||
|
||||
|
@ -67,8 +67,8 @@ public:
|
|||
@param pszRelativePath The relative path of the file.
|
||||
@return The absolute path of the file.
|
||||
@warning We only add the ResourcePath before the relative path of the file.
|
||||
If you have not set the ResourcePath,the function add "/NEWPLUS/TDA_DATA/UserData/" as default.
|
||||
You can set ResourcePath by function void setResourcePath(const char *pszResourcePath);
|
||||
If you have not set the ResourcePath, the function appends "/NEWPLUS/TDA_DATA/UserData/" by default.
|
||||
You can set ResourcePath with void setResourcePath(const char *pszResourcePath);
|
||||
*/
|
||||
const char* fullPathFromRelativePath(const char *pszRelativePath);
|
||||
|
||||
|
@ -77,8 +77,8 @@ public:
|
|||
/// @endcond
|
||||
|
||||
/**
|
||||
@brief Set the resource directory,we will find resource relative to this directory
|
||||
@param pszDirectoryName Relative path to root
|
||||
@brief Set the resource directory; we will find resources relative to this directory.
|
||||
@param pszDirectoryName Relative path to root.
|
||||
*/
|
||||
void setResourceDirectory(const char *pszDirectoryName);
|
||||
|
||||
|
@ -100,6 +100,10 @@ public:
|
|||
bool isPopupNotify();
|
||||
|
||||
protected:
|
||||
CCFileUtils(void)
|
||||
{
|
||||
}
|
||||
|
||||
std::string m_obDirectory;
|
||||
};
|
||||
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue