mirror of https://github.com/axmolengine/axmol.git
* merge upstream/master to master
This commit is contained in:
parent
6fbf2f1d09
commit
c5fa5d75f8
|
@ -47,6 +47,7 @@
|
|||
<listOptionValue builtIn="false" value="${QNX_TARGET}/usr/include/freetype2"/>
|
||||
<listOptionValue builtIn="false" value="${QNX_TARGET}/../target-override/usr/include"/>
|
||||
<listOptionValue builtIn="false" value="../../include"/>
|
||||
<listOptionValue builtIn="false" value="../../../cocos2dx/platform/third_party/qnx"/>
|
||||
</option>
|
||||
<inputType id="com.qnx.qcc.inputType.compiler.1849571146" superClass="com.qnx.qcc.inputType.compiler"/>
|
||||
</tool>
|
||||
|
@ -118,6 +119,7 @@
|
|||
<listOptionValue builtIn="false" value="${QNX_TARGET}/usr/include/freetype2"/>
|
||||
<listOptionValue builtIn="false" value="${QNX_TARGET}/../target-override/usr/include"/>
|
||||
<listOptionValue builtIn="false" value="../../include"/>
|
||||
<listOptionValue builtIn="false" value="../../../cocos2dx/platform/third_party/qnx"/>
|
||||
</option>
|
||||
<inputType id="com.qnx.qcc.inputType.compiler.82187465" superClass="com.qnx.qcc.inputType.compiler"/>
|
||||
</tool>
|
||||
|
@ -183,6 +185,7 @@
|
|||
<listOptionValue builtIn="false" value="${QNX_TARGET}/usr/include/freetype2"/>
|
||||
<listOptionValue builtIn="false" value="${QNX_TARGET}/../target-override/usr/include"/>
|
||||
<listOptionValue builtIn="false" value="../../include"/>
|
||||
<listOptionValue builtIn="false" value="../../../cocos2dx/platform/third_party/qnx"/>
|
||||
</option>
|
||||
<inputType id="com.qnx.qcc.inputType.compiler.2036659301" superClass="com.qnx.qcc.inputType.compiler"/>
|
||||
</tool>
|
||||
|
@ -251,6 +254,7 @@
|
|||
<listOptionValue builtIn="false" value="${QNX_TARGET}/usr/include/freetype2"/>
|
||||
<listOptionValue builtIn="false" value="${QNX_TARGET}/../target-override/usr/include"/>
|
||||
<listOptionValue builtIn="false" value="../../include"/>
|
||||
<listOptionValue builtIn="false" value="../../../cocos2dx/platform/third_party/qnx"/>
|
||||
</option>
|
||||
<inputType id="com.qnx.qcc.inputType.compiler.1381169559" superClass="com.qnx.qcc.inputType.compiler"/>
|
||||
</tool>
|
||||
|
@ -317,6 +321,7 @@
|
|||
<listOptionValue builtIn="false" value="${QNX_TARGET}/usr/include/freetype2"/>
|
||||
<listOptionValue builtIn="false" value="${QNX_TARGET}/../target-override/usr/include"/>
|
||||
<listOptionValue builtIn="false" value="../../include"/>
|
||||
<listOptionValue builtIn="false" value="../../../cocos2dx/platform/third_party/qnx"/>
|
||||
</option>
|
||||
<inputType id="com.qnx.qcc.inputType.compiler.1896937509" superClass="com.qnx.qcc.inputType.compiler"/>
|
||||
</tool>
|
||||
|
@ -383,6 +388,7 @@
|
|||
<listOptionValue builtIn="false" value="${QNX_TARGET}/usr/include/freetype2"/>
|
||||
<listOptionValue builtIn="false" value="${QNX_TARGET}/../target-override/usr/include"/>
|
||||
<listOptionValue builtIn="false" value="../../include"/>
|
||||
<listOptionValue builtIn="false" value="../../../cocos2dx/platform/third_party/qnx"/>
|
||||
</option>
|
||||
<inputType id="com.qnx.qcc.inputType.compiler.746859765" superClass="com.qnx.qcc.inputType.compiler"/>
|
||||
</tool>
|
||||
|
@ -450,6 +456,7 @@
|
|||
<listOptionValue builtIn="false" value="${QNX_TARGET}/usr/include/freetype2"/>
|
||||
<listOptionValue builtIn="false" value="${QNX_TARGET}/../target-override/usr/include"/>
|
||||
<listOptionValue builtIn="false" value="../../include"/>
|
||||
<listOptionValue builtIn="false" value="../../../cocos2dx/platform/third_party/qnx"/>
|
||||
</option>
|
||||
<inputType id="com.qnx.qcc.inputType.compiler.1894319763" superClass="com.qnx.qcc.inputType.compiler"/>
|
||||
</tool>
|
||||
|
@ -511,6 +518,8 @@
|
|||
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="com.qnx.tools.ide.qde.managedbuilder.core.qccScannerInfo"/>
|
||||
</scannerConfigBuildInfo>
|
||||
</storageModule>
|
||||
<storageModule moduleId="refreshScope"/>
|
||||
<storageModule moduleId="refreshScope" versionNumber="1">
|
||||
<resource resourceType="PROJECT" workspacePath="/CocosDenshion"/>
|
||||
</storageModule>
|
||||
<storageModule moduleId="com.qnx.tools.ide.qde.core.QNXProjectProperties"/>
|
||||
</cproject>
|
||||
|
|
|
@ -30,10 +30,8 @@ THE SOFTWARE.
|
|||
#include <AL/al.h>
|
||||
#include <AL/alc.h>
|
||||
#include <AL/alut.h>
|
||||
#include <mm/renderer.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
//#include "CCFileUtils.h"
|
||||
#include <vorbis/vorbisfile.h>
|
||||
|
||||
#include "SimpleAudioEngine.h"
|
||||
|
||||
|
@ -56,115 +54,68 @@ namespace CocosDenshion
|
|||
PAUSED,
|
||||
} playStatus;
|
||||
|
||||
static int s_audioOid;
|
||||
static float s_volume = 1.0f;
|
||||
static float s_effectVolume = 1.0f;
|
||||
static bool s_isBackgroundInitialized = false;
|
||||
static std::string s_currentBackgroundStr;
|
||||
|
||||
static float s_volume = 1.0f;
|
||||
static float s_effectVolume = 1.0f;
|
||||
static bool s_isBackgroundInitialized = false;
|
||||
static bool s_hasMMRError = false;
|
||||
static playStatus s_playStatus = STOPPED;
|
||||
|
||||
static string s_currentBackgroundStr;
|
||||
static mmr_connection_t *s_mmrConnection = 0;
|
||||
static mmr_context_t *s_mmrContext = 0;
|
||||
static strm_dict_t *s_repeatDictionary = 0;
|
||||
static strm_dict_t *s_volumeDictionary = 0;
|
||||
ALuint s_backgroundBuffer;
|
||||
ALuint s_backgroundSource;
|
||||
|
||||
static SimpleAudioEngine *s_engine = 0;
|
||||
|
||||
static void printALError(int err)
|
||||
static int checkALError(const char *funcName)
|
||||
{
|
||||
switch (err)
|
||||
int err = alGetError();
|
||||
|
||||
if (err != AL_NO_ERROR)
|
||||
{
|
||||
case AL_NO_ERROR:
|
||||
fprintf(stderr, "AL_NO_ERROR");
|
||||
break;
|
||||
switch (err)
|
||||
{
|
||||
case AL_INVALID_NAME:
|
||||
fprintf(stderr, "AL_INVALID_NAME in %s\n", funcName);
|
||||
break;
|
||||
|
||||
case AL_INVALID_NAME:
|
||||
fprintf(stderr, "AL_INVALID_NAME");
|
||||
break;
|
||||
case AL_INVALID_ENUM:
|
||||
fprintf(stderr, "AL_INVALID_ENUM in %s\n", funcName);
|
||||
break;
|
||||
|
||||
case AL_INVALID_ENUM:
|
||||
fprintf(stderr, "AL_INVALID_ENUM");
|
||||
break;
|
||||
case AL_INVALID_VALUE:
|
||||
fprintf(stderr, "AL_INVALID_VALUE in %s\n", funcName);
|
||||
break;
|
||||
|
||||
case AL_INVALID_VALUE:
|
||||
fprintf(stderr, "AL_INVALID_VALUE");
|
||||
break;
|
||||
case AL_INVALID_OPERATION:
|
||||
fprintf(stderr, "AL_INVALID_OPERATION in %s\n", funcName);
|
||||
break;
|
||||
|
||||
case AL_INVALID_OPERATION:
|
||||
fprintf(stderr, "AL_INVALID_OPERATION");
|
||||
break;
|
||||
case AL_OUT_OF_MEMORY:
|
||||
fprintf(stderr, "AL_OUT_OF_MEMORY in %s\n", funcName);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
case AL_OUT_OF_MEMORY:
|
||||
fprintf(stderr, "AL_OUT_OF_MEMORY");
|
||||
break;
|
||||
};
|
||||
return err;
|
||||
}
|
||||
|
||||
static void mmrerror(mmr_context_t *ctxt, const char *msg)
|
||||
{
|
||||
const mmr_error_info_t *err = mmr_error_info( ctxt );
|
||||
unsigned errcode = (err) ? err->error_code : -1;
|
||||
const char *name;
|
||||
|
||||
fprintf(stderr, "%s: error %d \n", msg, errcode);
|
||||
s_hasMMRError = true;
|
||||
}
|
||||
|
||||
static void stopBackground(bool bReleaseData)
|
||||
{
|
||||
s_playStatus = STOPPED;
|
||||
|
||||
if (s_mmrContext)
|
||||
mmr_stop(s_mmrContext);
|
||||
alSourceStop(s_backgroundSource);
|
||||
|
||||
if (bReleaseData)
|
||||
{
|
||||
if (s_mmrContext)
|
||||
{
|
||||
mmr_input_detach(s_mmrContext);
|
||||
mmr_context_destroy(s_mmrContext);
|
||||
}
|
||||
|
||||
if (s_mmrConnection)
|
||||
mmr_disconnect(s_mmrConnection);
|
||||
|
||||
if (s_repeatDictionary)
|
||||
strm_dict_destroy(s_repeatDictionary);
|
||||
|
||||
if (s_volumeDictionary)
|
||||
strm_dict_destroy(s_volumeDictionary);
|
||||
|
||||
s_mmrContext = 0;
|
||||
s_mmrConnection = 0;
|
||||
s_repeatDictionary = 0;
|
||||
s_volumeDictionary = 0;
|
||||
s_hasMMRError = false;
|
||||
s_currentBackgroundStr = "";
|
||||
s_isBackgroundInitialized = false;
|
||||
|
||||
alDeleteBuffers(1, &s_backgroundBuffer);
|
||||
checkALError("stopBackground");
|
||||
alDeleteSources(1, &s_backgroundSource);
|
||||
checkALError("stopBackground");
|
||||
}
|
||||
}
|
||||
|
||||
static void setBackgroundVolume(float volume)
|
||||
{
|
||||
if (!s_isBackgroundInitialized)
|
||||
{
|
||||
return;
|
||||
}
|
||||
char volume_str[128];
|
||||
|
||||
// set it up the background volume
|
||||
strm_dict_t *dictionary = strm_dict_new();
|
||||
|
||||
sprintf(volume_str, "%d", (int)(volume * 100) );
|
||||
s_volumeDictionary = strm_dict_set(dictionary, "volume", volume_str);
|
||||
|
||||
if (mmr_output_parameters(s_mmrContext, s_audioOid, s_volumeDictionary) != 0)
|
||||
{
|
||||
mmrerror(s_mmrContext, "output parameters");
|
||||
return;
|
||||
}
|
||||
alSourcef(s_backgroundSource, AL_GAIN, volume);
|
||||
}
|
||||
|
||||
SimpleAudioEngine::SimpleAudioEngine()
|
||||
|
@ -187,23 +138,22 @@ namespace CocosDenshion
|
|||
|
||||
void SimpleAudioEngine::end()
|
||||
{
|
||||
checkALError("end");
|
||||
|
||||
// clear all the sounds
|
||||
EffectsMap::const_iterator end = s_effects.end();
|
||||
for (EffectsMap::iterator it = s_effects.begin(); it != end; it++)
|
||||
{
|
||||
alSourceStop(it->second->source);
|
||||
|
||||
checkALError("end");
|
||||
alDeleteBuffers(1, &it->second->buffer);
|
||||
checkALError("end");
|
||||
alDeleteSources(1, &it->second->source);
|
||||
checkALError("end");
|
||||
delete it->second;
|
||||
}
|
||||
s_effects.clear();
|
||||
|
||||
if (s_isBackgroundInitialized)
|
||||
{
|
||||
s_isBackgroundInitialized = false;
|
||||
}
|
||||
|
||||
// and the background too
|
||||
stopBackground(true);
|
||||
}
|
||||
|
@ -213,134 +163,170 @@ namespace CocosDenshion
|
|||
}
|
||||
|
||||
//
|
||||
// background audio (using mmrenderer)
|
||||
// OGG support
|
||||
//
|
||||
static bool isOGGFile(const char *pszFilePath)
|
||||
{
|
||||
FILE *file;
|
||||
OggVorbis_File ogg_file;
|
||||
int result;
|
||||
|
||||
file = fopen(pszFilePath, "rb");
|
||||
result = ov_test(file, &ogg_file, 0, 0);
|
||||
ov_clear(&ogg_file);
|
||||
|
||||
return (result == 0);
|
||||
}
|
||||
|
||||
static ALuint createBufferFromOGG(const char *pszFilePath)
|
||||
{
|
||||
ALuint buffer;
|
||||
OggVorbis_File ogg_file;
|
||||
vorbis_info* info;
|
||||
ALenum format;
|
||||
int result;
|
||||
int section;
|
||||
int err;
|
||||
unsigned int size = 0;
|
||||
|
||||
if (ov_fopen(pszFilePath, &ogg_file) < 0)
|
||||
{
|
||||
ov_clear(&ogg_file);
|
||||
fprintf(stderr, "Could not open OGG file %s\n", pszFilePath);
|
||||
return -1;
|
||||
}
|
||||
|
||||
info = ov_info(&ogg_file, -1);
|
||||
|
||||
if (info->channels == 1)
|
||||
format = AL_FORMAT_MONO16;
|
||||
else
|
||||
format = AL_FORMAT_STEREO16;
|
||||
|
||||
// size = #samples * #channels * 2 (for 16 bit)
|
||||
unsigned int data_size = ov_pcm_total(&ogg_file, -1) * info->channels * 2;
|
||||
char* data = new char[data_size];
|
||||
|
||||
while (size < data_size)
|
||||
{
|
||||
result = ov_read(&ogg_file, data + size, data_size - size, 0, 2, 1, §ion);
|
||||
if (result > 0)
|
||||
{
|
||||
size += result;
|
||||
}
|
||||
else if (result < 0)
|
||||
{
|
||||
delete [] data;
|
||||
fprintf(stderr, "OGG file problem %s\n", pszFilePath);
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (size == 0)
|
||||
{
|
||||
delete [] data;
|
||||
fprintf(stderr, "Unable to read OGG data\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// clear al errors
|
||||
checkALError("createBufferFromOGG");
|
||||
|
||||
// Load audio data into a buffer.
|
||||
alGenBuffers(1, &buffer);
|
||||
|
||||
if (checkALError("createBufferFromOGG") != AL_NO_ERROR)
|
||||
{
|
||||
fprintf(stderr, "Couldn't generate a buffer for OGG file\n");
|
||||
delete [] data;
|
||||
return buffer;
|
||||
}
|
||||
|
||||
alBufferData(buffer, format, data, data_size, info->rate);
|
||||
checkALError("createBufferFromOGG");
|
||||
|
||||
delete [] data;
|
||||
ov_clear(&ogg_file);
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// background audio
|
||||
//
|
||||
void SimpleAudioEngine::preloadBackgroundMusic(const char* pszFilePath)
|
||||
{
|
||||
if (!s_isBackgroundInitialized)
|
||||
{
|
||||
const char *mmrname = NULL;
|
||||
const char *ctxtname = "mmrplayer";
|
||||
char cwd[PATH_MAX];
|
||||
mode_t mode = S_IRUSR | S_IXUSR;
|
||||
if (!s_isBackgroundInitialized || s_currentBackgroundStr != pszFilePath)
|
||||
{
|
||||
string path = pszFilePath;
|
||||
|
||||
getcwd(cwd, PATH_MAX);
|
||||
string path = "file://";
|
||||
path += cwd;
|
||||
path += "/";
|
||||
path += pszFilePath;
|
||||
if (isOGGFile(path.data()))
|
||||
{
|
||||
s_backgroundBuffer = createBufferFromOGG(path.data());
|
||||
}
|
||||
else
|
||||
{
|
||||
s_backgroundBuffer = alutCreateBufferFromFile(path.data());
|
||||
}
|
||||
|
||||
s_mmrConnection = mmr_connect(mmrname);
|
||||
if (!s_mmrConnection)
|
||||
{
|
||||
perror("mmr_connect");
|
||||
s_hasMMRError = true;
|
||||
return;
|
||||
}
|
||||
checkALError("preloadBackgroundMusic");
|
||||
|
||||
s_mmrContext = mmr_context_create(s_mmrConnection, ctxtname, 0, mode);
|
||||
if (!s_mmrContext)
|
||||
{
|
||||
perror(ctxtname);
|
||||
s_hasMMRError = true;
|
||||
return;
|
||||
}
|
||||
if (s_backgroundBuffer == AL_NONE)
|
||||
{
|
||||
fprintf(stderr, "Error loading file: '%s'\n", path.data());
|
||||
alDeleteBuffers(1, &s_backgroundBuffer);
|
||||
return;
|
||||
}
|
||||
|
||||
if ((s_audioOid = mmr_output_attach(s_mmrContext, "audio:default", "audio")) < 0)
|
||||
{
|
||||
mmrerror(s_mmrContext, "audio:default");
|
||||
return;
|
||||
}
|
||||
alGenSources(1, &s_backgroundSource);
|
||||
checkALError("preloadBackgroundMusic");
|
||||
|
||||
if (mmr_input_attach(s_mmrContext, path.data(), "autolist") < 0)
|
||||
{
|
||||
fprintf(stderr, "unable to load %s\n", path.data());
|
||||
mmrerror(s_mmrContext, path.data());
|
||||
return;
|
||||
}
|
||||
alSourcei(s_backgroundSource, AL_BUFFER, s_backgroundBuffer);
|
||||
checkALError("preloadBackgroundMusic");
|
||||
|
||||
s_currentBackgroundStr = pszFilePath;
|
||||
s_isBackgroundInitialized = true;
|
||||
setBackgroundVolume(s_volume);
|
||||
}
|
||||
s_currentBackgroundStr = pszFilePath;
|
||||
}
|
||||
|
||||
s_currentBackgroundStr = pszFilePath;
|
||||
s_isBackgroundInitialized = true;
|
||||
}
|
||||
|
||||
void SimpleAudioEngine::playBackgroundMusic(const char* pszFilePath, bool bLoop)
|
||||
{
|
||||
if (0 != strcmp(s_currentBackgroundStr.c_str(), pszFilePath))
|
||||
{
|
||||
stopBackgroundMusic(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (s_playStatus == PAUSED)
|
||||
resumeBackgroundMusic();
|
||||
else
|
||||
rewindBackgroundMusic();
|
||||
}
|
||||
|
||||
if (!s_isBackgroundInitialized)
|
||||
preloadBackgroundMusic(pszFilePath);
|
||||
|
||||
if (bLoop)
|
||||
{
|
||||
// set it up to loop
|
||||
strm_dict_t *dictionary = strm_dict_new();
|
||||
s_repeatDictionary = strm_dict_set(dictionary, "repeat", "all");
|
||||
|
||||
if (mmr_input_parameters(s_mmrContext, s_repeatDictionary) != 0)
|
||||
{
|
||||
mmrerror(s_mmrContext, "input parameters (loop)");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (s_hasMMRError || !s_mmrContext)
|
||||
return;
|
||||
|
||||
if (mmr_play(s_mmrContext) < 0)
|
||||
{
|
||||
mmrerror(s_mmrContext, "mmr_play");
|
||||
s_hasMMRError = true;
|
||||
}
|
||||
|
||||
if (!s_hasMMRError)
|
||||
s_playStatus = PLAYING;
|
||||
alSourcei(s_backgroundSource, AL_LOOPING, bLoop ? AL_TRUE : AL_FALSE);
|
||||
alSourcePlay(s_backgroundSource);
|
||||
checkALError("playBackgroundMusic");
|
||||
}
|
||||
|
||||
void SimpleAudioEngine::stopBackgroundMusic(bool bReleaseData)
|
||||
{
|
||||
// if we were paused then we need to resume first so that we can play
|
||||
if (s_playStatus == PAUSED)
|
||||
resumeBackgroundMusic();
|
||||
|
||||
stopBackground(bReleaseData);
|
||||
}
|
||||
|
||||
void SimpleAudioEngine::pauseBackgroundMusic()
|
||||
{
|
||||
if (s_mmrContext && mmr_speed_set(s_mmrContext, 0) < 0)
|
||||
{
|
||||
mmrerror(s_mmrContext, "pause");
|
||||
}
|
||||
s_playStatus = PAUSED;
|
||||
alSourcePause(s_backgroundSource);
|
||||
checkALError("pauseBackgroundMusic");
|
||||
}
|
||||
|
||||
void SimpleAudioEngine::resumeBackgroundMusic()
|
||||
{
|
||||
if (s_mmrContext && mmr_speed_set(s_mmrContext, 1000) < 0)
|
||||
{
|
||||
mmrerror(s_mmrContext, "resume");
|
||||
}
|
||||
s_playStatus = PLAYING;
|
||||
alSourcePlay(s_backgroundSource);
|
||||
checkALError("resumeBackgroundMusic");
|
||||
}
|
||||
|
||||
void SimpleAudioEngine::rewindBackgroundMusic()
|
||||
{
|
||||
if (s_mmrContext && mmr_seek(s_mmrContext, "1:0") < 0)
|
||||
{
|
||||
mmrerror(s_mmrContext, "rewind");
|
||||
}
|
||||
alSourceRewind(s_backgroundSource);
|
||||
checkALError("rewindBackgroundMusic");
|
||||
}
|
||||
|
||||
bool SimpleAudioEngine::willPlayBackgroundMusic()
|
||||
|
@ -350,7 +336,10 @@ namespace CocosDenshion
|
|||
|
||||
bool SimpleAudioEngine::isBackgroundMusicPlaying()
|
||||
{
|
||||
return (s_playStatus == PLAYING) && s_isBackgroundInitialized;
|
||||
ALint play_status;
|
||||
alGetSourcei(s_backgroundSource, AL_SOURCE_STATE, &play_status);
|
||||
|
||||
return (play_status == AL_PLAYING);
|
||||
}
|
||||
|
||||
float SimpleAudioEngine::getBackgroundMusicVolume()
|
||||
|
@ -407,9 +396,11 @@ namespace CocosDenshion
|
|||
}
|
||||
}
|
||||
|
||||
checkALError("playEffect");
|
||||
iter->second->isLooped = bLoop;
|
||||
alSourcei(iter->second->source, AL_LOOPING, iter->second->isLooped ? AL_TRUE : AL_FALSE);
|
||||
alSourcePlay(iter->second->source);
|
||||
checkALError("playEffect");
|
||||
|
||||
return iter->second->source;
|
||||
}
|
||||
|
@ -417,6 +408,7 @@ namespace CocosDenshion
|
|||
void SimpleAudioEngine::stopEffect(unsigned int nSoundId)
|
||||
{
|
||||
alSourceStop(nSoundId);
|
||||
checkALError("stopEffect");
|
||||
}
|
||||
|
||||
void SimpleAudioEngine::preloadEffect(const char* pszFilePath)
|
||||
|
@ -429,10 +421,19 @@ namespace CocosDenshion
|
|||
ALuint buffer;
|
||||
ALuint source;
|
||||
soundData *data = new soundData;
|
||||
string path = pszFilePath;
|
||||
|
||||
string path = pszFilePath;
|
||||
checkALError("preloadEffect");
|
||||
|
||||
buffer = alutCreateBufferFromFile(path.data());
|
||||
if (isOGGFile(path.data()))
|
||||
{
|
||||
buffer = createBufferFromOGG(path.data());
|
||||
}
|
||||
else
|
||||
{
|
||||
buffer = alutCreateBufferFromFile(path.data());
|
||||
checkALError("preloadEffect");
|
||||
}
|
||||
|
||||
if (buffer == AL_NONE)
|
||||
{
|
||||
|
@ -442,7 +443,15 @@ namespace CocosDenshion
|
|||
}
|
||||
|
||||
alGenSources(1, &source);
|
||||
|
||||
if (checkALError("preloadEffect") != AL_NO_ERROR)
|
||||
{
|
||||
alDeleteBuffers(1, &buffer);
|
||||
return;
|
||||
}
|
||||
|
||||
alSourcei(source, AL_BUFFER, buffer);
|
||||
checkALError("preloadEffect");
|
||||
|
||||
data->isLooped = false;
|
||||
data->buffer = buffer;
|
||||
|
@ -458,14 +467,17 @@ namespace CocosDenshion
|
|||
|
||||
if (iter != s_effects.end())
|
||||
{
|
||||
alSourceStop(iter->second->source);
|
||||
alDeleteSources(1, &iter->second->source);
|
||||
alDeleteBuffers(1, &iter->second->buffer);
|
||||
delete iter->second;
|
||||
checkALError("unloadEffect");
|
||||
|
||||
int err = alGetError();
|
||||
if (err != AL_NO_ERROR)
|
||||
printALError(err);
|
||||
alSourceStop(iter->second->source);
|
||||
checkALError("unloadEffect");
|
||||
|
||||
alDeleteSources(1, &iter->second->source);
|
||||
checkALError("unloadEffect");
|
||||
|
||||
alDeleteBuffers(1, &iter->second->buffer);
|
||||
checkALError("unloadEffect");
|
||||
delete iter->second;
|
||||
|
||||
s_effects.erase(iter);
|
||||
}
|
||||
|
@ -474,6 +486,7 @@ namespace CocosDenshion
|
|||
void SimpleAudioEngine::pauseEffect(unsigned int nSoundId)
|
||||
{
|
||||
alSourcePause(nSoundId);
|
||||
checkALError("pauseEffect");
|
||||
}
|
||||
|
||||
void SimpleAudioEngine::pauseAllEffects()
|
||||
|
@ -483,15 +496,14 @@ namespace CocosDenshion
|
|||
if (iter != s_effects.end())
|
||||
{
|
||||
alSourcePause(iter->second->source);
|
||||
int err = alGetError();
|
||||
if (err != AL_NO_ERROR)
|
||||
printALError(err);
|
||||
checkALError("pauseAllEffects");
|
||||
}
|
||||
}
|
||||
|
||||
void SimpleAudioEngine::resumeEffect(unsigned int nSoundId)
|
||||
{
|
||||
alSourcePlay(nSoundId);
|
||||
checkALError("resumeEffect");
|
||||
}
|
||||
|
||||
void SimpleAudioEngine::resumeAllEffects()
|
||||
|
@ -500,10 +512,9 @@ namespace CocosDenshion
|
|||
|
||||
if (iter != s_effects.end())
|
||||
{
|
||||
checkALError("resumeAllEffects");
|
||||
alSourcePlay(iter->second->source);
|
||||
int err = alGetError();
|
||||
if (err != AL_NO_ERROR)
|
||||
printALError(err);
|
||||
checkALError("resumeAllEffects");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -513,10 +524,9 @@ namespace CocosDenshion
|
|||
|
||||
if (iter != s_effects.end())
|
||||
{
|
||||
checkALError("stopAllEffects");
|
||||
alSourceStop(iter->second->source);
|
||||
int err = alGetError();
|
||||
if (err != AL_NO_ERROR)
|
||||
printALError(err);
|
||||
checkALError("stopAllEffects");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,166 +1,180 @@
|
|||
require "hello2"
|
||||
|
||||
cocos2d.CCLuaLog("result is " .. myadd(3, 5))
|
||||
|
||||
-- create scene & layer
|
||||
layerFarm = cocos2d.CCLayer:node()
|
||||
layerFarm:setIsTouchEnabled(true)
|
||||
|
||||
layerMenu = cocos2d.CCLayer:node()
|
||||
|
||||
sceneGame = cocos2d.CCScene:node()
|
||||
sceneGame:addChild(layerFarm)
|
||||
sceneGame:addChild(layerMenu)
|
||||
|
||||
winSize = cocos2d.CCDirector:sharedDirector():getWinSize()
|
||||
|
||||
-- add in farm background
|
||||
spriteFarm = cocos2d.CCSprite:spriteWithFile("farm.jpg")
|
||||
spriteFarm:setPosition(cocos2d.CCPoint(winSize.width/2 + 80, winSize.height/2))
|
||||
layerFarm:addChild(spriteFarm)
|
||||
|
||||
-- touch handers
|
||||
pointBegin = nil
|
||||
|
||||
function btnTouchMove(e)
|
||||
cocos2d.CCLuaLog("btnTouchMove")
|
||||
if pointBegin ~= nil then
|
||||
local v = e[1]
|
||||
local pointMove = v:locationInView(v:view())
|
||||
pointMove = cocos2d.CCDirector:sharedDirector():convertToGL(pointMove)
|
||||
local positionCurrent = layerFarm:getPosition()
|
||||
layerFarm:setPosition(cocos2d.CCPoint(positionCurrent.x + pointMove.x - pointBegin.x, positionCurrent.y + pointMove.y - pointBegin.y))
|
||||
pointBegin = pointMove
|
||||
end
|
||||
end
|
||||
|
||||
function btnTouchBegin(e)
|
||||
cocos2d.CCScheduler:sharedScheduler():unscheduleScriptFunc("tick")
|
||||
cocos2d.CCLuaLog("btnTouchBegin")
|
||||
for k,v in ipairs(e) do
|
||||
pointBegin = v:locationInView(v:view())
|
||||
pointBegin = cocos2d.CCDirector:sharedDirector():convertToGL(pointBegin)
|
||||
end
|
||||
end
|
||||
|
||||
function btnTouchEnd(e)
|
||||
cocos2d.CCLuaLog("btnTouchEnd")
|
||||
touchStart = nil
|
||||
end
|
||||
|
||||
-- regiester touch handlers
|
||||
layerFarm.__CCTouchDelegate__:registerScriptTouchHandler(cocos2d.CCTOUCHBEGAN, "btnTouchBegin")
|
||||
layerFarm.__CCTouchDelegate__:registerScriptTouchHandler(cocos2d.CCTOUCHMOVED, "btnTouchMove")
|
||||
layerFarm.__CCTouchDelegate__:registerScriptTouchHandler(cocos2d.CCTOUCHENDED, "btnTouchEnd")
|
||||
|
||||
|
||||
-- add land sprite
|
||||
for i=0,3,1 do
|
||||
for j=0,1,1 do
|
||||
spriteLand = cocos2d.CCSprite:spriteWithFile("land.png")
|
||||
layerFarm:addChild(spriteLand)
|
||||
spriteLand:setPosition(cocos2d.CCPoint(200+j*180 - i%2*90, 10+i*95/2))
|
||||
end
|
||||
end
|
||||
|
||||
-- add crop
|
||||
|
||||
for i=0,3,1 do
|
||||
for j=0,1,1 do
|
||||
|
||||
textureCrop = cocos2d.CCTextureCache:sharedTextureCache():addImage("crop.png")
|
||||
frameCrop = cocos2d.CCSpriteFrame:frameWithTexture(textureCrop, cocos2d.CCRectMake(0, 0, 105, 95))
|
||||
spriteCrop = cocos2d.CCSprite:spriteWithSpriteFrame(frameCrop);
|
||||
|
||||
layerFarm:addChild(spriteCrop)
|
||||
|
||||
spriteCrop:setPosition(cocos2d.CCPoint(10+200+j*180 - i%2*90, 30+10+i*95/2))
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
-- add the moving dog
|
||||
|
||||
FrameWidth = 105
|
||||
FrameHeight = 95
|
||||
|
||||
textureDog = cocos2d.CCTextureCache:sharedTextureCache():addImage("dog.png")
|
||||
frame0 = cocos2d.CCSpriteFrame:frameWithTexture(textureDog, cocos2d.CCRectMake(0, 0, FrameWidth, FrameHeight))
|
||||
frame1 = cocos2d.CCSpriteFrame:frameWithTexture(textureDog, cocos2d.CCRectMake(FrameWidth*1, 0, FrameWidth, FrameHeight))
|
||||
|
||||
spriteDog = cocos2d.CCSprite:spriteWithSpriteFrame(frame0)
|
||||
spriteDog:setPosition(cocos2d.CCPoint(0, winSize.height/4*3))
|
||||
layerFarm:addChild(spriteDog)
|
||||
|
||||
animation = cocos2d.CCAnimation:animation()
|
||||
|
||||
animFrames = cocos2d.CCMutableArray_CCSpriteFrame__:new(2)
|
||||
animFrames:addObject(frame0)
|
||||
animFrames:addObject(frame1)
|
||||
|
||||
animation = cocos2d.CCAnimation:animationWithFrames(animFrames,0.5)
|
||||
|
||||
animate = cocos2d.CCAnimate:actionWithAnimation(animation, false);
|
||||
spriteDog:runAction(cocos2d.CCRepeatForever:actionWithAction(animate))
|
||||
|
||||
|
||||
-- add a popup menu
|
||||
|
||||
function menuCallbackClosePopup()
|
||||
-- stop test sound effect
|
||||
CocosDenshion.SimpleAudioEngine:sharedEngine():stopEffect(effectID)
|
||||
menuPopup:setIsVisible(false)
|
||||
end
|
||||
|
||||
menuPopupItem = cocos2d.CCMenuItemImage:itemFromNormalImage("menu2.png", "menu2.png")
|
||||
menuPopupItem:setPosition( cocos2d.CCPoint(0, 0) )
|
||||
menuPopupItem:registerScriptHandler("menuCallbackClosePopup")
|
||||
menuPopup = cocos2d.CCMenu:menuWithItem(menuPopupItem)
|
||||
menuPopup:setPosition( cocos2d.CCPoint(winSize.width/2, winSize.height/2) )
|
||||
menuPopup:setIsVisible(false)
|
||||
layerMenu:addChild(menuPopup)
|
||||
|
||||
-- add the left-bottom "tools" menu to invoke menuPopup
|
||||
|
||||
function menuCallbackOpenPopup()
|
||||
-- loop test sound effect
|
||||
-- NOTE: effectID is global, so it can be used to stop
|
||||
effectID = CocosDenshion.SimpleAudioEngine:sharedEngine():playEffect("effect1.wav")
|
||||
menuPopup:setIsVisible(true)
|
||||
end
|
||||
|
||||
menuToolsItem = cocos2d.CCMenuItemImage:itemFromNormalImage("menu1.png","menu1.png")
|
||||
menuToolsItem:setPosition( cocos2d.CCPoint(0, 0) )
|
||||
menuToolsItem:registerScriptHandler("menuCallbackOpenPopup")
|
||||
menuTools = cocos2d.CCMenu:menuWithItem(menuToolsItem)
|
||||
menuTools:setPosition( cocos2d.CCPoint(30, 40) )
|
||||
layerMenu:addChild(menuTools)
|
||||
|
||||
|
||||
function tick()
|
||||
|
||||
local point = spriteDog:getPosition();
|
||||
|
||||
if point.x > winSize.width then
|
||||
point.x = 0
|
||||
spriteDog:setPosition(point)
|
||||
else
|
||||
point.x = point.x + 1
|
||||
spriteDog:setPosition(point)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
-- avoid memory leak
|
||||
collectgarbage( "setpause", 100)
|
||||
collectgarbage( "setstepmul", 5000)
|
||||
collectgarbage("setpause", 100)
|
||||
collectgarbage("setstepmul", 5000)
|
||||
|
||||
local cclog = function(...)
|
||||
print(string.format(...))
|
||||
end
|
||||
|
||||
require "hello2"
|
||||
cclog("result is " .. myadd(3, 5))
|
||||
|
||||
---------------
|
||||
|
||||
local winSize = CCDirector:sharedDirector():getWinSize()
|
||||
|
||||
-- add the moving dog
|
||||
local function creatDog()
|
||||
local frameWidth = 105
|
||||
local frameHeight = 95
|
||||
|
||||
-- create dog animate
|
||||
local textureDog = CCTextureCache:sharedTextureCache():addImage("dog.png")
|
||||
local rect = CCRectMake(0, 0, frameWidth, frameHeight)
|
||||
local frame0 = CCSpriteFrame:frameWithTexture(textureDog, rect)
|
||||
rect = CCRectMake(frameWidth, 0, frameWidth, frameHeight)
|
||||
local frame1 = CCSpriteFrame:frameWithTexture(textureDog, rect)
|
||||
|
||||
local spriteDog = CCSprite:spriteWithSpriteFrame(frame0)
|
||||
spriteDog.isPaused = false
|
||||
spriteDog:setPosition(0, winSize.height / 4 * 3)
|
||||
|
||||
local animFrames = CCMutableArray_CCSpriteFrame__:new(2)
|
||||
animFrames:addObject(frame0)
|
||||
animFrames:addObject(frame1)
|
||||
|
||||
local animation = CCAnimation:animationWithFrames(animFrames, 0.5)
|
||||
local animate = CCAnimate:actionWithAnimation(animation, false);
|
||||
spriteDog:runAction(CCRepeatForever:actionWithAction(animate))
|
||||
|
||||
-- moving dog at every frame
|
||||
local function tick()
|
||||
if spriteDog.isPaused then return end
|
||||
local x, y = spriteDog:getPosition()
|
||||
if x > winSize.width then
|
||||
x = 0
|
||||
else
|
||||
x = x + 1
|
||||
end
|
||||
spriteDog:setPositionX(x)
|
||||
end
|
||||
|
||||
CCScheduler:sharedScheduler():scheduleScriptFunc(tick, 0, false)
|
||||
|
||||
return spriteDog
|
||||
end
|
||||
|
||||
-- create farm
|
||||
local function createLayerFram()
|
||||
local layerFarm = CCLayer:node()
|
||||
|
||||
-- add in farm background
|
||||
local bg = CCSprite:spriteWithFile("farm.jpg")
|
||||
bg:setPosition(winSize.width / 2 + 80, winSize.height / 2)
|
||||
layerFarm:addChild(bg)
|
||||
|
||||
-- add land sprite
|
||||
for i = 0, 3 do
|
||||
for j = 0, 1 do
|
||||
local spriteLand = CCSprite:spriteWithFile("land.png")
|
||||
spriteLand:setPosition(200 + j * 180 - i % 2 * 90, 10 + i * 95 / 2)
|
||||
layerFarm:addChild(spriteLand)
|
||||
end
|
||||
end
|
||||
|
||||
-- add crop
|
||||
local textureCrop = CCTextureCache:sharedTextureCache():addImage("crop.png")
|
||||
local frameCrop = CCSpriteFrame:frameWithTexture(textureCrop, CCRectMake(0, 0, 105, 95))
|
||||
for i = 0, 3 do
|
||||
for j = 0, 1 do
|
||||
local spriteCrop = CCSprite:spriteWithSpriteFrame(frameCrop);
|
||||
spriteCrop:setPosition(10 + 200 + j * 180 - i % 2 * 90, 30 + 10 + i * 95 / 2)
|
||||
layerFarm:addChild(spriteCrop)
|
||||
end
|
||||
end
|
||||
|
||||
-- add moving dog
|
||||
local spriteDog = creatDog()
|
||||
layerFarm:addChild(spriteDog)
|
||||
|
||||
-- handing touch events
|
||||
local touchBeginPoint = nil
|
||||
|
||||
local function onTouchBegan(x, y)
|
||||
cclog("onTouchBegan: %0.2f, %0.2f", x, y)
|
||||
touchBeginPoint = {x = x, y = y}
|
||||
spriteDog.isPaused = true
|
||||
-- CCTOUCHBEGAN event must return true
|
||||
return true
|
||||
end
|
||||
|
||||
local function onTouchMoved(x, y)
|
||||
cclog("onTouchMoved: %0.2f, %0.2f", x, y)
|
||||
if touchBeginPoint then
|
||||
local cx, cy = layerFarm:getPosition()
|
||||
layerFarm:setPosition(cx + x - touchBeginPoint.x,
|
||||
cy + y - touchBeginPoint.y)
|
||||
touchBeginPoint = {x = x, y = y}
|
||||
end
|
||||
end
|
||||
|
||||
local function onTouchEnded(x, y)
|
||||
cclog("onTouchEnded")
|
||||
touchBeginPoint = nil
|
||||
spriteDog.isPaused = false
|
||||
end
|
||||
|
||||
local function onTouch(eventType, x, y)
|
||||
if eventType == CCTOUCHBEGAN then
|
||||
return onTouchBegan(x, y)
|
||||
elseif eventType == CCTOUCHMOVED then
|
||||
return onTouchMoved(x, y)
|
||||
else
|
||||
return onTouchEnded(x, y)
|
||||
end
|
||||
end
|
||||
|
||||
layerFarm:registerScriptTouchHandler(onTouch)
|
||||
|
||||
return layerFarm
|
||||
end
|
||||
|
||||
|
||||
cocos2d.CCScheduler:sharedScheduler():scheduleScriptFunc("tick", 0.01, false)
|
||||
-- create menu
|
||||
local function createLayerMenu()
|
||||
local layerMenu = CCLayer:node()
|
||||
|
||||
-- play background music
|
||||
CocosDenshion.SimpleAudioEngine:sharedEngine():playBackgroundMusic("background.mp3", true);
|
||||
-- preload effect
|
||||
CocosDenshion.SimpleAudioEngine:sharedEngine():preloadEffect("effect1.wav");
|
||||
-- run
|
||||
cocos2d.CCDirector:sharedDirector():runWithScene(sceneGame)
|
||||
local menuPopup, menuTools, effectID
|
||||
|
||||
local function menuCallbackClosePopup()
|
||||
-- stop test sound effect
|
||||
SimpleAudioEngine:sharedEngine():stopEffect(effectID)
|
||||
menuPopup:setIsVisible(false)
|
||||
end
|
||||
|
||||
local function menuCallbackOpenPopup()
|
||||
-- loop test sound effect
|
||||
effectID = SimpleAudioEngine:sharedEngine():playEffect("effect1.wav")
|
||||
menuPopup:setIsVisible(true)
|
||||
end
|
||||
|
||||
-- add a popup menu
|
||||
local menuPopupItem = CCMenuItemImage:itemFromNormalImage("menu2.png", "menu2.png")
|
||||
menuPopupItem:setPosition(0, 0)
|
||||
menuPopupItem:registerScriptHandler(menuCallbackClosePopup)
|
||||
menuPopup = CCMenu:menuWithItem(menuPopupItem)
|
||||
menuPopup:setPosition(winSize.width / 2, winSize.height / 2)
|
||||
menuPopup:setIsVisible(false)
|
||||
layerMenu:addChild(menuPopup)
|
||||
|
||||
-- add the left-bottom "tools" menu to invoke menuPopup
|
||||
local menuToolsItem = CCMenuItemImage:itemFromNormalImage("menu1.png", "menu1.png")
|
||||
menuToolsItem:setPosition(0, 0)
|
||||
menuToolsItem:registerScriptHandler(menuCallbackOpenPopup)
|
||||
menuTools = CCMenu:menuWithItem(menuToolsItem)
|
||||
menuTools:setPosition(30, 40)
|
||||
layerMenu:addChild(menuTools)
|
||||
|
||||
return layerMenu
|
||||
end
|
||||
|
||||
-- play background music, preload effect
|
||||
SimpleAudioEngine:sharedEngine():playBackgroundMusic("background.mp3", true);
|
||||
SimpleAudioEngine:sharedEngine():preloadEffect("effect1.wav");
|
||||
|
||||
-- run
|
||||
local sceneGame = CCScene:node()
|
||||
sceneGame:addChild(createLayerFram())
|
||||
sceneGame:addChild(createLayerMenu())
|
||||
CCDirector:sharedDirector():runWithScene(sceneGame)
|
||||
|
|
|
@ -74,8 +74,8 @@ public class Cocos2dxBitmap{
|
|||
// Draw string
|
||||
FontMetricsInt fm = paint.getFontMetricsInt();
|
||||
int x = 0;
|
||||
int y = height == 0 ?(-fm.ascent):
|
||||
(-fm.ascent + (height - textProperty.totalHeight)/2);
|
||||
int y = height == 0 ?(-fm.top):
|
||||
(-fm.top + (height - textProperty.totalHeight)/2);
|
||||
String[] lines = textProperty.lines;
|
||||
for (String line : lines){
|
||||
x = computeX(paint, line, textProperty.maxWidth, alignment);
|
||||
|
@ -132,7 +132,7 @@ public class Cocos2dxBitmap{
|
|||
private static TextProperty computeTextProperty(String content, Paint paint,
|
||||
int maxWidth, int maxHeight){
|
||||
FontMetricsInt fm = paint.getFontMetricsInt();
|
||||
int h = (int)Math.ceil(fm.descent - fm.ascent);
|
||||
int h = (int)Math.ceil(fm.bottom - fm.top);
|
||||
int maxContentWidth = 0;
|
||||
|
||||
String[] lines = splitString(content, maxHeight, maxWidth, paint);
|
||||
|
@ -165,7 +165,7 @@ public class Cocos2dxBitmap{
|
|||
String[] lines = content.split("\\n");
|
||||
String[] ret = null;
|
||||
FontMetricsInt fm = paint.getFontMetricsInt();
|
||||
int heightPerLine = (int)Math.ceil(fm.descent - fm.ascent);
|
||||
int heightPerLine = (int)Math.ceil(fm.bottom - fm.top);
|
||||
int maxLines = maxHeight / heightPerLine;
|
||||
|
||||
if (maxWidth != 0){
|
||||
|
@ -236,7 +236,7 @@ public class Cocos2dxBitmap{
|
|||
if (tempWidth >= width){
|
||||
int lastIndexOfSpace = content.substring(0, i).lastIndexOf(" ");
|
||||
|
||||
if (lastIndexOfSpace != -1){
|
||||
if (lastIndexOfSpace != -1 && lastIndexOfSpace > start){
|
||||
/**
|
||||
* Should wrap the word
|
||||
*/
|
||||
|
|
|
@ -282,9 +282,10 @@ public class Cocos2dxGLSurfaceView extends GLSurfaceView {
|
|||
|
||||
switch (event.getAction() & MotionEvent.ACTION_MASK) {
|
||||
case MotionEvent.ACTION_POINTER_DOWN:
|
||||
final int idPointerDown = event.getAction() >> MotionEvent.ACTION_POINTER_ID_SHIFT;
|
||||
final float xPointerDown = event.getX(idPointerDown);
|
||||
final float yPointerDown = event.getY(idPointerDown);
|
||||
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
|
||||
|
@ -318,9 +319,10 @@ public class Cocos2dxGLSurfaceView extends GLSurfaceView {
|
|||
break;
|
||||
|
||||
case MotionEvent.ACTION_POINTER_UP:
|
||||
final int idPointerUp = event.getAction() >> MotionEvent.ACTION_POINTER_ID_SHIFT;
|
||||
final float xPointerUp = event.getX(idPointerUp);
|
||||
final float yPointerUp = event.getY(idPointerUp);
|
||||
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
|
||||
|
|
|
@ -1 +1 @@
|
|||
d1f0ba1c97add6d33ba2628f3a35ad1ed676c4f5
|
||||
0a874bd51db1bbbd82d2c0ed77650a0ac0f323f6
|
|
@ -0,0 +1 @@
|
|||
abc899cd55086105f439df7a6d01db84168aebb5
|
|
@ -74,8 +74,8 @@ public class Cocos2dxBitmap{
|
|||
// Draw string
|
||||
FontMetricsInt fm = paint.getFontMetricsInt();
|
||||
int x = 0;
|
||||
int y = height == 0 ?(-fm.ascent):
|
||||
(-fm.ascent + (height - textProperty.totalHeight)/2);
|
||||
int y = height == 0 ?(-fm.top):
|
||||
(-fm.top + (height - textProperty.totalHeight)/2);
|
||||
String[] lines = textProperty.lines;
|
||||
for (String line : lines){
|
||||
x = computeX(paint, line, textProperty.maxWidth, alignment);
|
||||
|
@ -132,7 +132,7 @@ public class Cocos2dxBitmap{
|
|||
private static TextProperty computeTextProperty(String content, Paint paint,
|
||||
int maxWidth, int maxHeight){
|
||||
FontMetricsInt fm = paint.getFontMetricsInt();
|
||||
int h = (int)Math.ceil(fm.descent - fm.ascent);
|
||||
int h = (int)Math.ceil(fm.bottom - fm.top);
|
||||
int maxContentWidth = 0;
|
||||
|
||||
String[] lines = splitString(content, maxHeight, maxWidth, paint);
|
||||
|
@ -165,7 +165,7 @@ public class Cocos2dxBitmap{
|
|||
String[] lines = content.split("\\n");
|
||||
String[] ret = null;
|
||||
FontMetricsInt fm = paint.getFontMetricsInt();
|
||||
int heightPerLine = (int)Math.ceil(fm.descent - fm.ascent);
|
||||
int heightPerLine = (int)Math.ceil(fm.bottom - fm.top);
|
||||
int maxLines = maxHeight / heightPerLine;
|
||||
|
||||
if (maxWidth != 0){
|
||||
|
@ -236,7 +236,7 @@ public class Cocos2dxBitmap{
|
|||
if (tempWidth >= width){
|
||||
int lastIndexOfSpace = content.substring(0, i).lastIndexOf(" ");
|
||||
|
||||
if (lastIndexOfSpace != -1){
|
||||
if (lastIndexOfSpace != -1 && lastIndexOfSpace > start){
|
||||
/**
|
||||
* Should wrap the word
|
||||
*/
|
||||
|
|
|
@ -282,9 +282,10 @@ public class Cocos2dxGLSurfaceView extends GLSurfaceView {
|
|||
|
||||
switch (event.getAction() & MotionEvent.ACTION_MASK) {
|
||||
case MotionEvent.ACTION_POINTER_DOWN:
|
||||
final int idPointerDown = event.getAction() >> MotionEvent.ACTION_POINTER_ID_SHIFT;
|
||||
final float xPointerDown = event.getX(idPointerDown);
|
||||
final float yPointerDown = event.getY(idPointerDown);
|
||||
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
|
||||
|
@ -318,9 +319,10 @@ public class Cocos2dxGLSurfaceView extends GLSurfaceView {
|
|||
break;
|
||||
|
||||
case MotionEvent.ACTION_POINTER_UP:
|
||||
final int idPointerUp = event.getAction() >> MotionEvent.ACTION_POINTER_ID_SHIFT;
|
||||
final float xPointerUp = event.getX(idPointerUp);
|
||||
final float yPointerUp = event.getY(idPointerUp);
|
||||
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
|
||||
|
|
|
@ -1 +1 @@
|
|||
0bf2e5e584ed953f8de4c1594175403a1d14abd0
|
||||
27ae070112e44d08eaf37af409452a684dcb4185
|
122
README.mdown
122
README.mdown
|
@ -2,7 +2,7 @@ cocos2d-x multiplatform
|
|||
==================
|
||||
|
||||
[cocos2d-x][1] is a multi-platform 2D game engine in C++, based on [cocos2d-iphone][2] and licensed under MIT.
|
||||
Now this engine has been ported to WOPhone, iOS 4.1, Android 2.1 and higher, WindowsXP & Windows7.
|
||||
Now this engine has been ported to WOPhone, iOS 4.1, Android 2.1 and higher, WindowsXP & Windows7.
|
||||
|
||||
Multi Platform
|
||||
-------------
|
||||
|
@ -16,14 +16,14 @@ Multi Platform
|
|||
Document
|
||||
------------------
|
||||
* Website: [www.cocos2d-x.org][7]
|
||||
* [Online API References][8]
|
||||
|
||||
* [Online API References][8]
|
||||
|
||||
Contact us
|
||||
------------------
|
||||
* Forum: [http://forum.cocos2d-x.org][9]
|
||||
* Twitter: [http://www.twitter.com/cocos2dx][10]
|
||||
* Sina mini-blog: [http://t.sina.com.cn/cocos2dx][11]
|
||||
|
||||
|
||||
[1]: http://www.cocos2d-x.org "cocos2d-x"
|
||||
[2]: http://www.cocos2d-iphone.org "cocos2d for iPhone"
|
||||
[3]: http://www.cocos2d-x.org/wiki/cocos2d-x/Cocos2d-iphone-cpp "cocos2d-iphone-cpp"
|
||||
|
@ -35,117 +35,3 @@ Contact us
|
|||
[9]: http://forum.cocos2d-x.org "http://forum.cocos2d-x.org"
|
||||
[10]: http://www.twitter.com/cocos2dx "http://www.twitter.com/cocos2dx"
|
||||
[11]: http://t.sina.com.cn/cocos2dx "http://t.sina.com.cn/cocos2dx"
|
||||
|
||||
|
||||
|
||||
Lua Support FIX Readme
|
||||
------------------
|
||||
* CCScheduler support local function
|
||||
* Support autorelease C++ object
|
||||
* When C++ object deleted, set Lua object userdata to nil
|
||||
* Add CCNode:setPosition(x, y), CCNode::getPosition(), huge performance boost
|
||||
* Remove needless class and functions from tolua++ .pkg files, improved performance
|
||||
* CCMenuItem support script function
|
||||
* CCScene script callback
|
||||
* CCLayer touch & multi-touches events handler
|
||||
|
||||
**How to use:**
|
||||
|
||||
-- use CCSchedule::scheduleScriptFunc()
|
||||
|
||||
local scheduler = CCScheduler:sharedScheduler()
|
||||
|
||||
local handle -- save script callback handle
|
||||
|
||||
local frameCount = 0
|
||||
local function onEnterFrame(dt)
|
||||
print("onEnterFrame:", frameCount, dt)
|
||||
frameCount = frameCount + 1
|
||||
if frameCount >= 60 then
|
||||
-- remove script callback
|
||||
scheduler:unscheduleScriptFunc(handle)
|
||||
end
|
||||
end
|
||||
|
||||
handle = scheduler:scheduleScriptFunc(onEnterFrame, 1.0 / 60, false)
|
||||
|
||||
- - -
|
||||
|
||||
-- use CCMenuItem:registerScriptHandler()
|
||||
|
||||
local function onMenuItemTap(menuItemTag)
|
||||
print(menuItemTag) -- output "1"
|
||||
end
|
||||
|
||||
local menuItem = CCMenuItemImage:itemFromNormalImage("button.png", "button.png")
|
||||
menuItem:registerScriptHandler(onMenuItemTap)
|
||||
|
||||
local menu = CCMenu:node()
|
||||
menu:addChild(menuItem)
|
||||
menuItem:setTag(1) -- menuItemTag
|
||||
|
||||
scene:addChild(menu)
|
||||
|
||||
- - -
|
||||
|
||||
-- use CCScene script callback
|
||||
|
||||
local function newScene()
|
||||
local scene = CCScene:node()
|
||||
|
||||
local function sceneEventHandler(isOnEnter)
|
||||
if isOnEnter then
|
||||
if scene.onEnter then scene:onEnter() end
|
||||
else
|
||||
if scene.onExit then scene:onExit() end
|
||||
scene:unregisterScriptEventsHandler()
|
||||
end
|
||||
end
|
||||
|
||||
scene:registerScriptEventsHandler(sceneEventHandler)
|
||||
return scene
|
||||
end
|
||||
|
||||
local myScene = newScene("MyScene")
|
||||
function myScene:onEnter()
|
||||
print("MyScene:onEnter()")
|
||||
end
|
||||
|
||||
function myScene:onExit()
|
||||
print("MyScene:onExit()")
|
||||
end
|
||||
|
||||
CCDirector:sharedDirector():runWithScene(myScene)
|
||||
|
||||
- - -
|
||||
|
||||
-- use CCLayer touch event handler
|
||||
|
||||
local layer = CCLayer:node()
|
||||
local function onTouch(event, x, y)
|
||||
-- event: CCTOUCHBEGAN, CCTOUCHMOVED, CCTOUCHENDED, CCTOUCHCANCELLED
|
||||
print(event, x, y)
|
||||
if event == CCTOUCHBEGAN then return true end
|
||||
end
|
||||
|
||||
layer:registerScriptTouchHandler(onTouch, false)
|
||||
|
||||
- - -
|
||||
|
||||
-- use CCLayer multi-touches event handler
|
||||
|
||||
local layer = CCLayer:node()
|
||||
local function onTouches(event, points)
|
||||
-- event: CCTOUCHBEGAN, CCTOUCHMOVED, CCTOUCHENDED, CCTOUCHCANCELLED
|
||||
print(event)
|
||||
|
||||
for i = 1, #points, 2 do
|
||||
print(string.format("x: 0.2f, y: 0.2f", points[i], points[i + 1]))
|
||||
end
|
||||
end
|
||||
|
||||
layer:registerScriptTouchHandler(onTouches, true)
|
||||
|
||||
**TODO:**
|
||||
|
||||
* When C++ object deleted, remove Lua object userdata
|
||||
|
|
|
@ -9,6 +9,12 @@ using namespace CocosDenshion;
|
|||
[! if !CC_USE_LUA]
|
||||
|
||||
#include "HelloWorldScene.h"
|
||||
[! else]
|
||||
|
||||
#if CC_LUA_ENGINE_ENABLED
|
||||
#include "CCLuaEngine.h"
|
||||
#endif
|
||||
|
||||
[! endif]
|
||||
|
||||
#include "CCEGLView.h"
|
||||
|
@ -16,11 +22,7 @@ using namespace CocosDenshion;
|
|||
USING_NS_CC;
|
||||
|
||||
AppDelegate::AppDelegate()
|
||||
[! if CC_USE_LUA]
|
||||
:m_pLuaEngine(NULL)
|
||||
[! endif]
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
AppDelegate::~AppDelegate()
|
||||
|
@ -29,16 +31,16 @@ AppDelegate::~AppDelegate()
|
|||
SimpleAudioEngine::end();
|
||||
[! endif]
|
||||
[! if CC_USE_LUA]
|
||||
|
||||
CCScriptEngineManager::sharedScriptEngineManager()->removeScriptEngine();
|
||||
CC_SAFE_DELETE(m_pLuaEngine);
|
||||
#if CC_LUA_ENGINE_ENABLED
|
||||
CCLuaEngine::purgeSharedEngine();
|
||||
#endif
|
||||
[! endif]
|
||||
}
|
||||
|
||||
bool AppDelegate::initInstance()
|
||||
{
|
||||
bool bRet = false;
|
||||
do
|
||||
do
|
||||
{
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
|
||||
|
||||
|
@ -55,7 +57,7 @@ bool AppDelegate::initInstance()
|
|||
// OpenGLView initialized in testsAppDelegate.mm on ios platform, nothing need to do here.
|
||||
|
||||
#endif // CC_PLATFORM_IOS
|
||||
|
||||
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
|
||||
|
||||
// OpenGLView initialized in HelloWorld/android/jni/helloworld/main.cpp
|
||||
|
@ -74,7 +76,7 @@ bool AppDelegate::initInstance()
|
|||
CCEGLView* pMainWnd = new CCEGLView(this);
|
||||
CC_BREAK_IF(! pMainWnd || ! pMainWnd->Create(320,480, WM_WINDOW_ROTATE_MODE_CW));
|
||||
|
||||
#ifndef _TRANZDA_VM_
|
||||
#ifndef _TRANZDA_VM_
|
||||
// on wophone emulator, we copy resources files to Work7/NEWPLUS/TDA_DATA/Data/ folder instead of zip file
|
||||
cocos2d::CCFileUtils::setResource("HelloWorld.zip");
|
||||
#endif
|
||||
|
@ -131,9 +133,8 @@ bool AppDelegate::applicationDidFinishLaunching()
|
|||
pDirector->setAnimationInterval(1.0 / 60);
|
||||
|
||||
[! if CC_USE_LUA]
|
||||
// register lua engine
|
||||
m_pLuaEngine = new LuaEngine;
|
||||
CCScriptEngineManager::sharedScriptEngineManager()->setScriptEngine(m_pLuaEngine);
|
||||
// init lua engine
|
||||
CCLuaEngine* pEngine = CCLuaEngine::sharedEngine();
|
||||
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
|
||||
unsigned long size;
|
||||
|
@ -147,15 +148,15 @@ bool AppDelegate::applicationDidFinishLaunching()
|
|||
memcpy(pCodes, pFileContent, size);
|
||||
delete[] pFileContent;
|
||||
|
||||
CCScriptEngineManager::sharedScriptEngineManager()->getScriptEngine()->executeString(pCodes);
|
||||
pEngine->executeString(pCodes);
|
||||
delete []pCodes;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
|
||||
string path = CCFileUtils::fullPathFromRelativePath("hello.lua");
|
||||
CCScriptEngineManager::sharedScriptEngineManager()->getScriptEngine()->executeScriptFile(path.c_str());
|
||||
#endif
|
||||
pEngine->executeScriptFile(path.c_str());
|
||||
#endif
|
||||
[! else]
|
||||
// create a scene. it's an autorelease object
|
||||
CCScene *pScene = HelloWorld::scene();
|
||||
|
|
|
@ -1 +1 @@
|
|||
84d1a5cd21bd26c8e2f08241d504b59fe40defc9
|
||||
60686646874bc76241984a6df8beeaa3673f934e
|
|
@ -1 +1 @@
|
|||
1a854b530b8894d2453fe8777d2d83b8bc68ab91
|
||||
b8d0b27908d823a2687767793e04c64fe1541def
|
|
@ -1 +1 @@
|
|||
866c5fd880bbb121951818d47d13a4ee914279ad
|
||||
4df124f68856ca5915635b8392bb8aa85c79259f
|
|
@ -1,24 +1,27 @@
|
|||
#include "AppDelegate.h"
|
||||
|
||||
#include "AppDelegate.h"
|
||||
#include "cocos2d.h"
|
||||
#include "SimpleAudioEngine.h"
|
||||
#include "CCLuaEngine.h"
|
||||
|
||||
USING_NS_CC;
|
||||
using namespace CocosDenshion;
|
||||
|
||||
AppDelegate::AppDelegate()
|
||||
:m_pLuaEngine(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
AppDelegate::~AppDelegate()
|
||||
{
|
||||
CCScriptEngineManager::sharedScriptEngineManager()->removeScriptEngine();
|
||||
CC_SAFE_DELETE(m_pLuaEngine);
|
||||
// end simple audio engine here, or it may crashed on win32
|
||||
SimpleAudioEngine::sharedEngine()->end();
|
||||
CCLuaEngine::purgeSharedEngine();
|
||||
}
|
||||
|
||||
bool AppDelegate::initInstance()
|
||||
{
|
||||
bool bRet = false;
|
||||
do
|
||||
do
|
||||
{
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
|
||||
|
||||
|
@ -29,13 +32,13 @@ bool AppDelegate::initInstance()
|
|||
|| ! pMainWnd->Create(TEXT("cocos2d: Hello World"), 480, 320));
|
||||
|
||||
#endif // CC_PLATFORM_WIN32
|
||||
|
||||
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
|
||||
|
||||
// OpenGLView initialized in testsAppDelegate.mm on ios platform, nothing need to do here.
|
||||
|
||||
#endif // CC_PLATFORM_IOS
|
||||
|
||||
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
|
||||
|
||||
// OpenGLView initialized in HelloWorld/android/jni/helloworld/main.cpp
|
||||
|
@ -51,7 +54,7 @@ bool AppDelegate::initInstance()
|
|||
CCEGLView* pMainWnd = new CCEGLView(this);
|
||||
CC_BREAK_IF(! pMainWnd || ! pMainWnd->Create(320,480, WM_WINDOW_ROTATE_MODE_CW));
|
||||
|
||||
#ifndef _TRANZDA_VM_
|
||||
#ifndef _TRANZDA_VM_
|
||||
// on wophone emulator, we copy resources files to Work7/NEWPLUS/TDA_DATA/Data/ folder instead of zip file
|
||||
cocos2d::CCFileUtils::setResource("HelloWorld.zip");
|
||||
#endif
|
||||
|
@ -84,9 +87,8 @@ bool AppDelegate::applicationDidFinishLaunching()
|
|||
// set FPS. the default value is 1.0/60 if you don't call this
|
||||
pDirector->setAnimationInterval(1.0 / 60);
|
||||
|
||||
// register lua engine
|
||||
m_pLuaEngine = new LuaEngine;
|
||||
CCScriptEngineManager::sharedScriptEngineManager()->setScriptEngine(m_pLuaEngine);
|
||||
// init lua engine
|
||||
CCLuaEngine* pEngine = CCLuaEngine::sharedEngine();
|
||||
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
|
||||
unsigned long size;
|
||||
|
@ -100,42 +102,16 @@ bool AppDelegate::applicationDidFinishLaunching()
|
|||
memcpy(pCodes, pFileContent, size);
|
||||
delete[] pFileContent;
|
||||
|
||||
CCScriptEngineManager::sharedScriptEngineManager()->getScriptEngine()->executeString(pCodes);
|
||||
pEngine->executeString(pCodes);
|
||||
delete []pCodes;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
|
||||
// CCLuaScriptModule::sharedLuaScriptModule()->executeScriptFile("./../../HelloLua/Resource/hello.lua");
|
||||
CCScriptEngineManager::sharedScriptEngineManager()->getScriptEngine()->executeScriptFile("./../../HelloLua/Resource/hello.lua");
|
||||
|
||||
/*
|
||||
* Another way to run lua script.
|
||||
* Load the file into memory and run it.
|
||||
*
|
||||
unsigned long size;
|
||||
char *pFileContent = (char*)CCFileUtils::getFileData("./../../HelloLua/Resource/hello.lua", "r", &size);
|
||||
if (pFileContent)
|
||||
{
|
||||
// copy the file contents and add '\0' at the end, or the lua parser can not parse it
|
||||
char *pTmp = new char[size + 1];
|
||||
pTmp[size] = '\0';
|
||||
memcpy(pTmp, pFileContent, size);
|
||||
delete[] pFileContent;
|
||||
|
||||
string code(pTmp);
|
||||
CCScriptEngineManager::sharedScriptEngineManager()->getScriptEngine()->excuteScriptFile(code);
|
||||
delete []pTmp;
|
||||
}
|
||||
*/
|
||||
|
||||
#endif
|
||||
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
|
||||
string path = CCFileUtils::fullPathFromRelativePath("hello.lua");
|
||||
CCScriptEngineManager::sharedScriptEngineManager()->getScriptEngine()->addSearchPath(path.substr(0, path.find_last_of("/")).c_str());
|
||||
CCScriptEngineManager::sharedScriptEngineManager()->getScriptEngine()->executeScriptFile(path.c_str());
|
||||
#endif
|
||||
pEngine->addSearchPath(path.substr(0, path.find_last_of("/")).c_str());
|
||||
pEngine->executeScriptFile(path.c_str());
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -153,7 +129,7 @@ void AppDelegate::applicationDidEnterBackground()
|
|||
void AppDelegate::applicationWillEnterForeground()
|
||||
{
|
||||
CCDirector::sharedDirector()->resume();
|
||||
|
||||
|
||||
// if you use SimpleAudioEngine, it must resume here
|
||||
// SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic();
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
#define _APP_DELEGATE_H_
|
||||
|
||||
#include "CCApplication.h"
|
||||
#include "LuaEngine.h"
|
||||
|
||||
/**
|
||||
@brief The cocos2d Application.
|
||||
|
@ -38,9 +37,6 @@ public:
|
|||
@param the pointer of the application
|
||||
*/
|
||||
virtual void applicationWillEnterForeground();
|
||||
|
||||
private:
|
||||
LuaEngine* m_pLuaEngine;
|
||||
};
|
||||
|
||||
#endif // _APP_DELEGATE_H_
|
||||
|
|
|
@ -1 +1 @@
|
|||
6b542917dfd2180ff6c55bca6cd7b30c64c4a300
|
||||
23cd0723f3707e7fc8c77d718bf3fc0b81b105f6
|
|
@ -1,28 +1,27 @@
|
|||
#include "AppDelegate.h"
|
||||
|
||||
#include "AppDelegate.h"
|
||||
#include "cocos2d.h"
|
||||
#include "SimpleAudioEngine.h"
|
||||
#include "CCLuaEngine.h"
|
||||
|
||||
USING_NS_CC;
|
||||
using namespace CocosDenshion;
|
||||
|
||||
AppDelegate::AppDelegate()
|
||||
:m_pLuaEngine(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
AppDelegate::~AppDelegate()
|
||||
{
|
||||
// end simple audio engine here, or it may crashed on win32
|
||||
SimpleAudioEngine::sharedEngine()->end();
|
||||
CCScriptEngineManager::sharedScriptEngineManager()->removeScriptEngine();
|
||||
CC_SAFE_DELETE(m_pLuaEngine);
|
||||
// end simple audio engine here, or it may crashed on win32
|
||||
SimpleAudioEngine::sharedEngine()->end();
|
||||
CCLuaEngine::purgeSharedEngine();
|
||||
}
|
||||
|
||||
bool AppDelegate::initInstance()
|
||||
{
|
||||
bool bRet = false;
|
||||
do
|
||||
do
|
||||
{
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
|
||||
|
||||
|
@ -33,13 +32,13 @@ bool AppDelegate::initInstance()
|
|||
|| ! pMainWnd->Create(TEXT("cocos2d: Hello World"), 480, 320));
|
||||
|
||||
#endif // CC_PLATFORM_WIN32
|
||||
|
||||
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
|
||||
|
||||
// OpenGLView initialized in testsAppDelegate.mm on ios platform, nothing need to do here.
|
||||
|
||||
#endif // CC_PLATFORM_IOS
|
||||
|
||||
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
|
||||
|
||||
// OpenGLView initialized in HelloWorld/android/jni/helloworld/main.cpp
|
||||
|
@ -55,7 +54,7 @@ bool AppDelegate::initInstance()
|
|||
CCEGLView* pMainWnd = new CCEGLView(this);
|
||||
CC_BREAK_IF(! pMainWnd || ! pMainWnd->Create(320,480, WM_WINDOW_ROTATE_MODE_CW));
|
||||
|
||||
#ifndef _TRANZDA_VM_
|
||||
#ifndef _TRANZDA_VM_
|
||||
// on wophone emulator, we copy resources files to Work7/NEWPLUS/TDA_DATA/Data/ folder instead of zip file
|
||||
cocos2d::CCFileUtils::setResource("HelloWorld.zip");
|
||||
#endif
|
||||
|
@ -88,32 +87,31 @@ bool AppDelegate::applicationDidFinishLaunching()
|
|||
// set FPS. the default value is 1.0/60 if you don't call this
|
||||
pDirector->setAnimationInterval(1.0 / 60);
|
||||
|
||||
// register lua engine
|
||||
m_pLuaEngine = new LuaEngine;
|
||||
CCScriptEngineManager::sharedScriptEngineManager()->setScriptEngine(m_pLuaEngine);
|
||||
// init lua engine
|
||||
CCLuaEngine* pEngine = CCLuaEngine::sharedEngine();
|
||||
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
|
||||
unsigned long size;
|
||||
char *pFileContent = (char*)CCFileUtils::getFileData("hello.lua", "r", &size);
|
||||
unsigned long size;
|
||||
char *pFileContent = (char*)CCFileUtils::getFileData("hello.lua", "r", &size);
|
||||
|
||||
if (pFileContent)
|
||||
{
|
||||
// copy the file contents and add '\0' at the end, or the lua parser can not parse it
|
||||
char *pCodes = new char[size + 1];
|
||||
pCodes[size] = '\0';
|
||||
memcpy(pCodes, pFileContent, size);
|
||||
delete[] pFileContent;
|
||||
if (pFileContent)
|
||||
{
|
||||
// copy the file contents and add '\0' at the end, or the lua parser can not parse it
|
||||
char *pCodes = new char[size + 1];
|
||||
pCodes[size] = '\0';
|
||||
memcpy(pCodes, pFileContent, size);
|
||||
delete[] pFileContent;
|
||||
|
||||
CCScriptEngineManager::sharedScriptEngineManager()->getScriptEngine()->executeString(pCodes);
|
||||
delete []pCodes;
|
||||
}
|
||||
pEngine->executeString(pCodes);
|
||||
delete []pCodes;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
|
||||
string path = CCFileUtils::fullPathFromRelativePath("hello.lua");
|
||||
CCScriptEngineManager::sharedScriptEngineManager()->getScriptEngine()->addSearchPath(path.substr(0, path.find_last_of("/")).c_str());
|
||||
CCScriptEngineManager::sharedScriptEngineManager()->getScriptEngine()->executeScriptFile(path.c_str());
|
||||
#endif
|
||||
string path = CCFileUtils::fullPathFromRelativePath("hello.lua");
|
||||
pEngine->addSearchPath(path.substr(0, path.find_last_of("/")).c_str());
|
||||
pEngine->executeScriptFile(path.c_str());
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -131,7 +129,7 @@ void AppDelegate::applicationDidEnterBackground()
|
|||
void AppDelegate::applicationWillEnterForeground()
|
||||
{
|
||||
CCDirector::sharedDirector()->resume();
|
||||
|
||||
|
||||
// if you use SimpleAudioEngine, it must resume here
|
||||
// SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic();
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
#define _APP_DELEGATE_H_
|
||||
|
||||
#include "CCApplication.h"
|
||||
#include "LuaEngine.h"
|
||||
|
||||
/**
|
||||
@brief The cocos2d Application.
|
||||
|
@ -38,9 +37,6 @@ public:
|
|||
@param the pointer of the application
|
||||
*/
|
||||
virtual void applicationWillEnterForeground();
|
||||
|
||||
private:
|
||||
LuaEngine* m_pLuaEngine;
|
||||
};
|
||||
|
||||
#endif // _APP_DELEGATE_H_
|
||||
|
|
|
@ -1,164 +1,180 @@
|
|||
require "hello2"
|
||||
|
||||
cocos2d.CCLuaLog("result is " .. myadd(3, 5))
|
||||
|
||||
-- create scene & layer
|
||||
layerFarm = cocos2d.CCLayer:node()
|
||||
layerFarm:setIsTouchEnabled(true)
|
||||
|
||||
layerMenu = cocos2d.CCLayer:node()
|
||||
|
||||
sceneGame = cocos2d.CCScene:node()
|
||||
sceneGame:addChild(layerFarm)
|
||||
sceneGame:addChild(layerMenu)
|
||||
|
||||
winSize = cocos2d.CCDirector:sharedDirector():getWinSize()
|
||||
|
||||
-- add in farm background
|
||||
spriteFarm = cocos2d.CCSprite:spriteWithFile("farm.jpg")
|
||||
spriteFarm:setPosition(cocos2d.CCPoint(winSize.width/2 + 80, winSize.height/2))
|
||||
layerFarm:addChild(spriteFarm)
|
||||
|
||||
-- touch handers
|
||||
pointBegin = nil
|
||||
|
||||
function btnTouchMove(e)
|
||||
cocos2d.CCLuaLog("btnTouchMove")
|
||||
if pointBegin ~= nil then
|
||||
local v = e[1]
|
||||
local pointMove = v:locationInView(v:view())
|
||||
pointMove = cocos2d.CCDirector:sharedDirector():convertToGL(pointMove)
|
||||
local positionCurrent = layerFarm:getPosition()
|
||||
layerFarm:setPosition(cocos2d.CCPoint(positionCurrent.x + pointMove.x - pointBegin.x, positionCurrent.y + pointMove.y - pointBegin.y))
|
||||
pointBegin = pointMove
|
||||
end
|
||||
end
|
||||
|
||||
function btnTouchBegin(e)
|
||||
cocos2d.CCScheduler:sharedScheduler():unscheduleScriptFunc("tick")
|
||||
cocos2d.CCLuaLog("btnTouchBegin")
|
||||
for k,v in ipairs(e) do
|
||||
pointBegin = v:locationInView(v:view())
|
||||
pointBegin = cocos2d.CCDirector:sharedDirector():convertToGL(pointBegin)
|
||||
end
|
||||
end
|
||||
|
||||
function btnTouchEnd(e)
|
||||
cocos2d.CCLuaLog("btnTouchEnd")
|
||||
touchStart = nil
|
||||
end
|
||||
|
||||
-- regiester touch handlers
|
||||
layerFarm.__CCTouchDelegate__:registerScriptTouchHandler(cocos2d.CCTOUCHBEGAN, "btnTouchBegin")
|
||||
layerFarm.__CCTouchDelegate__:registerScriptTouchHandler(cocos2d.CCTOUCHMOVED, "btnTouchMove")
|
||||
layerFarm.__CCTouchDelegate__:registerScriptTouchHandler(cocos2d.CCTOUCHENDED, "btnTouchEnd")
|
||||
|
||||
|
||||
-- add land sprite
|
||||
for i=0,3,1 do
|
||||
for j=0,1,1 do
|
||||
spriteLand = cocos2d.CCSprite:spriteWithFile("land.png")
|
||||
layerFarm:addChild(spriteLand)
|
||||
spriteLand:setPosition(cocos2d.CCPoint(200+j*180 - i%2*90, 10+i*95/2))
|
||||
end
|
||||
end
|
||||
|
||||
-- add crop
|
||||
|
||||
for i=0,3,1 do
|
||||
for j=0,1,1 do
|
||||
|
||||
textureCrop = cocos2d.CCTextureCache:sharedTextureCache():addImage("crop.png")
|
||||
frameCrop = cocos2d.CCSpriteFrame:frameWithTexture(textureCrop, cocos2d.CCRectMake(0, 0, 105, 95))
|
||||
spriteCrop = cocos2d.CCSprite:spriteWithSpriteFrame(frameCrop);
|
||||
|
||||
layerFarm:addChild(spriteCrop)
|
||||
|
||||
spriteCrop:setPosition(cocos2d.CCPoint(10+200+j*180 - i%2*90, 30+10+i*95/2))
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
-- add the moving dog
|
||||
|
||||
FrameWidth = 105
|
||||
FrameHeight = 95
|
||||
|
||||
textureDog = cocos2d.CCTextureCache:sharedTextureCache():addImage("dog.png")
|
||||
frame0 = cocos2d.CCSpriteFrame:frameWithTexture(textureDog, cocos2d.CCRectMake(0, 0, FrameWidth, FrameHeight))
|
||||
frame1 = cocos2d.CCSpriteFrame:frameWithTexture(textureDog, cocos2d.CCRectMake(FrameWidth*1, 0, FrameWidth, FrameHeight))
|
||||
|
||||
spriteDog = cocos2d.CCSprite:spriteWithSpriteFrame(frame0)
|
||||
spriteDog:setPosition(cocos2d.CCPoint(0, winSize.height/4*3))
|
||||
layerFarm:addChild(spriteDog)
|
||||
|
||||
animFrames = cocos2d.CCMutableArray_CCSpriteFrame__:new(2)
|
||||
animFrames:addObject(frame0)
|
||||
animFrames:addObject(frame1)
|
||||
|
||||
animation = cocos2d.CCAnimation:animationWithFrames(animFrames, 0.5)
|
||||
|
||||
animate = cocos2d.CCAnimate:actionWithAnimation(animation, false);
|
||||
spriteDog:runAction(cocos2d.CCRepeatForever:actionWithAction(animate))
|
||||
|
||||
|
||||
-- add a popup menu
|
||||
|
||||
function menuCallbackClosePopup()
|
||||
-- stop test sound effect
|
||||
CocosDenshion.SimpleAudioEngine:sharedEngine():stopEffect(effectID)
|
||||
menuPopup:setIsVisible(false)
|
||||
end
|
||||
|
||||
menuPopupItem = cocos2d.CCMenuItemImage:itemFromNormalImage("menu2.png", "menu2.png")
|
||||
menuPopupItem:setPosition( cocos2d.CCPoint(0, 0) )
|
||||
menuPopupItem:registerScriptHandler("menuCallbackClosePopup")
|
||||
menuPopup = cocos2d.CCMenu:menuWithItem(menuPopupItem)
|
||||
menuPopup:setPosition( cocos2d.CCPoint(winSize.width/2, winSize.height/2) )
|
||||
menuPopup:setIsVisible(false)
|
||||
layerMenu:addChild(menuPopup)
|
||||
|
||||
-- add the left-bottom "tools" menu to invoke menuPopup
|
||||
|
||||
function menuCallbackOpenPopup()
|
||||
-- loop test sound effect
|
||||
-- NOTE: effectID is global, so it can be used to stop
|
||||
effectID = CocosDenshion.SimpleAudioEngine:sharedEngine():playEffect("effect1.wav")
|
||||
menuPopup:setIsVisible(true)
|
||||
end
|
||||
|
||||
menuToolsItem = cocos2d.CCMenuItemImage:itemFromNormalImage("menu1.png","menu1.png")
|
||||
menuToolsItem:setPosition( cocos2d.CCPoint(0, 0) )
|
||||
menuToolsItem:registerScriptHandler("menuCallbackOpenPopup")
|
||||
menuTools = cocos2d.CCMenu:menuWithItem(menuToolsItem)
|
||||
menuTools:setPosition( cocos2d.CCPoint(30, 40) )
|
||||
layerMenu:addChild(menuTools)
|
||||
|
||||
|
||||
function tick()
|
||||
|
||||
local point = spriteDog:getPosition();
|
||||
|
||||
if point.x > winSize.width then
|
||||
point.x = 0
|
||||
spriteDog:setPosition(point)
|
||||
else
|
||||
point.x = point.x + 1
|
||||
spriteDog:setPosition(point)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
-- avoid memory leak
|
||||
collectgarbage( "setpause", 100)
|
||||
collectgarbage( "setstepmul", 5000)
|
||||
collectgarbage("setpause", 100)
|
||||
collectgarbage("setstepmul", 5000)
|
||||
|
||||
local cclog = function(...)
|
||||
print(string.format(...))
|
||||
end
|
||||
|
||||
require "hello2"
|
||||
cclog("result is " .. myadd(3, 5))
|
||||
|
||||
---------------
|
||||
|
||||
local winSize = CCDirector:sharedDirector():getWinSize()
|
||||
|
||||
-- add the moving dog
|
||||
local function creatDog()
|
||||
local frameWidth = 105
|
||||
local frameHeight = 95
|
||||
|
||||
-- create dog animate
|
||||
local textureDog = CCTextureCache:sharedTextureCache():addImage("dog.png")
|
||||
local rect = CCRectMake(0, 0, frameWidth, frameHeight)
|
||||
local frame0 = CCSpriteFrame:frameWithTexture(textureDog, rect)
|
||||
rect = CCRectMake(frameWidth, 0, frameWidth, frameHeight)
|
||||
local frame1 = CCSpriteFrame:frameWithTexture(textureDog, rect)
|
||||
|
||||
local spriteDog = CCSprite:spriteWithSpriteFrame(frame0)
|
||||
spriteDog.isPaused = false
|
||||
spriteDog:setPosition(0, winSize.height / 4 * 3)
|
||||
|
||||
local animFrames = CCMutableArray_CCSpriteFrame__:new(2)
|
||||
animFrames:addObject(frame0)
|
||||
animFrames:addObject(frame1)
|
||||
|
||||
local animation = CCAnimation:animationWithFrames(animFrames, 0.5)
|
||||
local animate = CCAnimate:actionWithAnimation(animation, false);
|
||||
spriteDog:runAction(CCRepeatForever:actionWithAction(animate))
|
||||
|
||||
-- moving dog at every frame
|
||||
local function tick()
|
||||
if spriteDog.isPaused then return end
|
||||
local x, y = spriteDog:getPosition()
|
||||
if x > winSize.width then
|
||||
x = 0
|
||||
else
|
||||
x = x + 1
|
||||
end
|
||||
spriteDog:setPositionX(x)
|
||||
end
|
||||
|
||||
CCScheduler:sharedScheduler():scheduleScriptFunc(tick, 0, false)
|
||||
|
||||
return spriteDog
|
||||
end
|
||||
|
||||
-- create farm
|
||||
local function createLayerFram()
|
||||
local layerFarm = CCLayer:node()
|
||||
|
||||
-- add in farm background
|
||||
local bg = CCSprite:spriteWithFile("farm.jpg")
|
||||
bg:setPosition(winSize.width / 2 + 80, winSize.height / 2)
|
||||
layerFarm:addChild(bg)
|
||||
|
||||
-- add land sprite
|
||||
for i = 0, 3 do
|
||||
for j = 0, 1 do
|
||||
local spriteLand = CCSprite:spriteWithFile("land.png")
|
||||
spriteLand:setPosition(200 + j * 180 - i % 2 * 90, 10 + i * 95 / 2)
|
||||
layerFarm:addChild(spriteLand)
|
||||
end
|
||||
end
|
||||
|
||||
-- add crop
|
||||
local textureCrop = CCTextureCache:sharedTextureCache():addImage("crop.png")
|
||||
local frameCrop = CCSpriteFrame:frameWithTexture(textureCrop, CCRectMake(0, 0, 105, 95))
|
||||
for i = 0, 3 do
|
||||
for j = 0, 1 do
|
||||
local spriteCrop = CCSprite:spriteWithSpriteFrame(frameCrop);
|
||||
spriteCrop:setPosition(10 + 200 + j * 180 - i % 2 * 90, 30 + 10 + i * 95 / 2)
|
||||
layerFarm:addChild(spriteCrop)
|
||||
end
|
||||
end
|
||||
|
||||
-- add moving dog
|
||||
local spriteDog = creatDog()
|
||||
layerFarm:addChild(spriteDog)
|
||||
|
||||
-- handing touch events
|
||||
local touchBeginPoint = nil
|
||||
|
||||
local function onTouchBegan(x, y)
|
||||
cclog("onTouchBegan: %0.2f, %0.2f", x, y)
|
||||
touchBeginPoint = {x = x, y = y}
|
||||
spriteDog.isPaused = true
|
||||
-- CCTOUCHBEGAN event must return true
|
||||
return true
|
||||
end
|
||||
|
||||
local function onTouchMoved(x, y)
|
||||
cclog("onTouchMoved: %0.2f, %0.2f", x, y)
|
||||
if touchBeginPoint then
|
||||
local cx, cy = layerFarm:getPosition()
|
||||
layerFarm:setPosition(cx + x - touchBeginPoint.x,
|
||||
cy + y - touchBeginPoint.y)
|
||||
touchBeginPoint = {x = x, y = y}
|
||||
end
|
||||
end
|
||||
|
||||
local function onTouchEnded(x, y)
|
||||
cclog("onTouchEnded")
|
||||
touchBeginPoint = nil
|
||||
spriteDog.isPaused = false
|
||||
end
|
||||
|
||||
local function onTouch(eventType, x, y)
|
||||
if eventType == CCTOUCHBEGAN then
|
||||
return onTouchBegan(x, y)
|
||||
elseif eventType == CCTOUCHMOVED then
|
||||
return onTouchMoved(x, y)
|
||||
else
|
||||
return onTouchEnded(x, y)
|
||||
end
|
||||
end
|
||||
|
||||
layerFarm:registerScriptTouchHandler(onTouch)
|
||||
|
||||
return layerFarm
|
||||
end
|
||||
|
||||
|
||||
cocos2d.CCScheduler:sharedScheduler():scheduleScriptFunc("tick", 0.01, false)
|
||||
-- create menu
|
||||
local function createLayerMenu()
|
||||
local layerMenu = CCLayer:node()
|
||||
|
||||
-- play background music
|
||||
CocosDenshion.SimpleAudioEngine:sharedEngine():playBackgroundMusic("background.mp3", true);
|
||||
-- preload effect
|
||||
CocosDenshion.SimpleAudioEngine:sharedEngine():preloadEffect("effect1.wav");
|
||||
-- run
|
||||
cocos2d.CCDirector:sharedDirector():runWithScene(sceneGame)
|
||||
local menuPopup, menuTools, effectID
|
||||
|
||||
local function menuCallbackClosePopup()
|
||||
-- stop test sound effect
|
||||
SimpleAudioEngine:sharedEngine():stopEffect(effectID)
|
||||
menuPopup:setIsVisible(false)
|
||||
end
|
||||
|
||||
local function menuCallbackOpenPopup()
|
||||
-- loop test sound effect
|
||||
effectID = SimpleAudioEngine:sharedEngine():playEffect("effect1.wav")
|
||||
menuPopup:setIsVisible(true)
|
||||
end
|
||||
|
||||
-- add a popup menu
|
||||
local menuPopupItem = CCMenuItemImage:itemFromNormalImage("menu2.png", "menu2.png")
|
||||
menuPopupItem:setPosition(0, 0)
|
||||
menuPopupItem:registerScriptHandler(menuCallbackClosePopup)
|
||||
menuPopup = CCMenu:menuWithItem(menuPopupItem)
|
||||
menuPopup:setPosition(winSize.width / 2, winSize.height / 2)
|
||||
menuPopup:setIsVisible(false)
|
||||
layerMenu:addChild(menuPopup)
|
||||
|
||||
-- add the left-bottom "tools" menu to invoke menuPopup
|
||||
local menuToolsItem = CCMenuItemImage:itemFromNormalImage("menu1.png", "menu1.png")
|
||||
menuToolsItem:setPosition(0, 0)
|
||||
menuToolsItem:registerScriptHandler(menuCallbackOpenPopup)
|
||||
menuTools = CCMenu:menuWithItem(menuToolsItem)
|
||||
menuTools:setPosition(30, 40)
|
||||
layerMenu:addChild(menuTools)
|
||||
|
||||
return layerMenu
|
||||
end
|
||||
|
||||
-- play background music, preload effect
|
||||
SimpleAudioEngine:sharedEngine():playBackgroundMusic("background.mp3", true);
|
||||
SimpleAudioEngine:sharedEngine():preloadEffect("effect1.wav");
|
||||
|
||||
-- run
|
||||
local sceneGame = CCScene:node()
|
||||
sceneGame:addChild(createLayerFram())
|
||||
sceneGame:addChild(createLayerMenu())
|
||||
CCDirector:sharedDirector():runWithScene(sceneGame)
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
ebb3361a7a53d63ab60931a48bedc3ec8ccfe206
|
|
@ -0,0 +1 @@
|
|||
ab579da81872bb45c6e102dc2dbf6ee9e8082f75
|
|
@ -0,0 +1 @@
|
|||
cce195a8ee10fc4fd7b5acf048ab3e04b0750685
|
|
@ -0,0 +1 @@
|
|||
abc899cd55086105f439df7a6d01db84168aebb5
|
|
@ -0,0 +1 @@
|
|||
3f8554bba4214706aafc933d057de89351197eb4
|
|
@ -74,8 +74,8 @@ public class Cocos2dxBitmap{
|
|||
// Draw string
|
||||
FontMetricsInt fm = paint.getFontMetricsInt();
|
||||
int x = 0;
|
||||
int y = height == 0 ?(-fm.ascent):
|
||||
(-fm.ascent + (height - textProperty.totalHeight)/2);
|
||||
int y = height == 0 ?(-fm.top):
|
||||
(-fm.top + (height - textProperty.totalHeight)/2);
|
||||
String[] lines = textProperty.lines;
|
||||
for (String line : lines){
|
||||
x = computeX(paint, line, textProperty.maxWidth, alignment);
|
||||
|
@ -132,7 +132,7 @@ public class Cocos2dxBitmap{
|
|||
private static TextProperty computeTextProperty(String content, Paint paint,
|
||||
int maxWidth, int maxHeight){
|
||||
FontMetricsInt fm = paint.getFontMetricsInt();
|
||||
int h = (int)Math.ceil(fm.descent - fm.ascent);
|
||||
int h = (int)Math.ceil(fm.bottom - fm.top);
|
||||
int maxContentWidth = 0;
|
||||
|
||||
String[] lines = splitString(content, maxHeight, maxWidth, paint);
|
||||
|
@ -165,7 +165,7 @@ public class Cocos2dxBitmap{
|
|||
String[] lines = content.split("\\n");
|
||||
String[] ret = null;
|
||||
FontMetricsInt fm = paint.getFontMetricsInt();
|
||||
int heightPerLine = (int)Math.ceil(fm.descent - fm.ascent);
|
||||
int heightPerLine = (int)Math.ceil(fm.bottom - fm.top);
|
||||
int maxLines = maxHeight / heightPerLine;
|
||||
|
||||
if (maxWidth != 0){
|
||||
|
@ -236,7 +236,7 @@ public class Cocos2dxBitmap{
|
|||
if (tempWidth >= width){
|
||||
int lastIndexOfSpace = content.substring(0, i).lastIndexOf(" ");
|
||||
|
||||
if (lastIndexOfSpace != -1){
|
||||
if (lastIndexOfSpace != -1 && lastIndexOfSpace > start){
|
||||
/**
|
||||
* Should wrap the word
|
||||
*/
|
||||
|
|
|
@ -282,9 +282,10 @@ public class Cocos2dxGLSurfaceView extends GLSurfaceView {
|
|||
|
||||
switch (event.getAction() & MotionEvent.ACTION_MASK) {
|
||||
case MotionEvent.ACTION_POINTER_DOWN:
|
||||
final int idPointerDown = event.getAction() >> MotionEvent.ACTION_POINTER_ID_SHIFT;
|
||||
final float xPointerDown = event.getX(idPointerDown);
|
||||
final float yPointerDown = event.getY(idPointerDown);
|
||||
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
|
||||
|
@ -318,9 +319,10 @@ public class Cocos2dxGLSurfaceView extends GLSurfaceView {
|
|||
break;
|
||||
|
||||
case MotionEvent.ACTION_POINTER_UP:
|
||||
final int idPointerUp = event.getAction() >> MotionEvent.ACTION_POINTER_ID_SHIFT;
|
||||
final float xPointerUp = event.getX(idPointerUp);
|
||||
final float yPointerUp = event.getY(idPointerUp);
|
||||
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
|
||||
|
|
|
@ -1 +1 @@
|
|||
da69ff183d2f96f95b8b1f8aec196130ba76a193
|
||||
6f3595799e6b2dd55a7666a9a191c04093559b7f
|
|
@ -53,14 +53,13 @@
|
|||
<listOptionValue builtIn="false" value="GLESv1_CM"/>
|
||||
<listOptionValue builtIn="false" value="bps"/>
|
||||
<listOptionValue builtIn="false" value="curl"/>
|
||||
<listOptionValue builtIn="false" value="mmrndclient"/>
|
||||
<listOptionValue builtIn="false" value="strm"/>
|
||||
<listOptionValue builtIn="false" value="grskia"/>
|
||||
<listOptionValue builtIn="false" value="OpenAL"/>
|
||||
<listOptionValue builtIn="false" value="alut"/>
|
||||
<listOptionValue builtIn="false" value="curl"/>
|
||||
<listOptionValue builtIn="false" value="asound"/>
|
||||
<listOptionValue builtIn="false" value="xml2"/>
|
||||
<listOptionValue builtIn="false" value="vorbis"/>
|
||||
</option>
|
||||
<option id="com.qnx.qcc.option.linker.security.670341600" name="Enhanced Security (-Wl,-z,relro -Wl,-z,now)" superClass="com.qnx.qcc.option.linker.security" value="true" valueType="boolean"/>
|
||||
<option id="com.qnx.qcc.option.linker.libraryPaths.1640397005" name="Library Paths (-L)" superClass="com.qnx.qcc.option.linker.libraryPaths" valueType="libPaths">
|
||||
|
@ -140,14 +139,13 @@
|
|||
<listOptionValue builtIn="false" value="GLESv1_CM"/>
|
||||
<listOptionValue builtIn="false" value="bps"/>
|
||||
<listOptionValue builtIn="false" value="curl"/>
|
||||
<listOptionValue builtIn="false" value="mmrndclient"/>
|
||||
<listOptionValue builtIn="false" value="strm"/>
|
||||
<listOptionValue builtIn="false" value="grskia"/>
|
||||
<listOptionValue builtIn="false" value="OpenAL"/>
|
||||
<listOptionValue builtIn="false" value="alut"/>
|
||||
<listOptionValue builtIn="false" value="curl"/>
|
||||
<listOptionValue builtIn="false" value="asound"/>
|
||||
<listOptionValue builtIn="false" value="xml2"/>
|
||||
<listOptionValue builtIn="false" value="vorbis"/>
|
||||
</option>
|
||||
<option id="com.qnx.qcc.option.linker.security.982628496" name="Enhanced Security (-Wl,-z,relro -Wl,-z,now)" superClass="com.qnx.qcc.option.linker.security" value="true" valueType="boolean"/>
|
||||
<option id="com.qnx.qcc.option.linker.pie.196284652" name="Position Independent Executable (-pie)" superClass="com.qnx.qcc.option.linker.pie" value="true" valueType="boolean"/>
|
||||
|
@ -231,14 +229,13 @@
|
|||
<listOptionValue builtIn="false" value="GLESv1_CM"/>
|
||||
<listOptionValue builtIn="false" value="bps"/>
|
||||
<listOptionValue builtIn="false" value="curl"/>
|
||||
<listOptionValue builtIn="false" value="mmrndclient"/>
|
||||
<listOptionValue builtIn="false" value="strm"/>
|
||||
<listOptionValue builtIn="false" value="grskia"/>
|
||||
<listOptionValue builtIn="false" value="OpenAL"/>
|
||||
<listOptionValue builtIn="false" value="alut"/>
|
||||
<listOptionValue builtIn="false" value="curl"/>
|
||||
<listOptionValue builtIn="false" value="asound"/>
|
||||
<listOptionValue builtIn="false" value="xml2"/>
|
||||
<listOptionValue builtIn="false" value="vorbis"/>
|
||||
</option>
|
||||
<option id="com.qnx.qcc.option.linker.security.1905389687" name="Enhanced Security (-Wl,-z,relro -Wl,-z,now)" superClass="com.qnx.qcc.option.linker.security" value="true" valueType="boolean"/>
|
||||
<option id="com.qnx.qcc.option.linker.libraryPaths.1615583479" name="Library Paths (-L)" superClass="com.qnx.qcc.option.linker.libraryPaths" valueType="libPaths">
|
||||
|
@ -321,14 +318,13 @@
|
|||
<listOptionValue builtIn="false" value="GLESv1_CM"/>
|
||||
<listOptionValue builtIn="false" value="bps"/>
|
||||
<listOptionValue builtIn="false" value="curl"/>
|
||||
<listOptionValue builtIn="false" value="mmrndclient"/>
|
||||
<listOptionValue builtIn="false" value="strm"/>
|
||||
<listOptionValue builtIn="false" value="grskia"/>
|
||||
<listOptionValue builtIn="false" value="OpenAL"/>
|
||||
<listOptionValue builtIn="false" value="alut"/>
|
||||
<listOptionValue builtIn="false" value="curl"/>
|
||||
<listOptionValue builtIn="false" value="asound"/>
|
||||
<listOptionValue builtIn="false" value="xml2"/>
|
||||
<listOptionValue builtIn="false" value="vorbis"/>
|
||||
</option>
|
||||
<option id="com.qnx.qcc.option.linker.security.1324953478" name="Enhanced Security (-Wl,-z,relro -Wl,-z,now)" superClass="com.qnx.qcc.option.linker.security" value="true" valueType="boolean"/>
|
||||
<option id="com.qnx.qcc.option.linker.libraryPaths.172097509" name="Library Paths (-L)" superClass="com.qnx.qcc.option.linker.libraryPaths" valueType="libPaths">
|
||||
|
@ -408,14 +404,13 @@
|
|||
<listOptionValue builtIn="false" value="GLESv1_CM"/>
|
||||
<listOptionValue builtIn="false" value="bps"/>
|
||||
<listOptionValue builtIn="false" value="curl"/>
|
||||
<listOptionValue builtIn="false" value="mmrndclient"/>
|
||||
<listOptionValue builtIn="false" value="strm"/>
|
||||
<listOptionValue builtIn="false" value="grskia"/>
|
||||
<listOptionValue builtIn="false" value="OpenAL"/>
|
||||
<listOptionValue builtIn="false" value="alut"/>
|
||||
<listOptionValue builtIn="false" value="curl"/>
|
||||
<listOptionValue builtIn="false" value="asound"/>
|
||||
<listOptionValue builtIn="false" value="xml2"/>
|
||||
<listOptionValue builtIn="false" value="vorbis"/>
|
||||
</option>
|
||||
<option id="com.qnx.qcc.option.linker.security.886524253" name="Enhanced Security (-Wl,-z,relro -Wl,-z,now)" superClass="com.qnx.qcc.option.linker.security" value="true" valueType="boolean"/>
|
||||
<option id="com.qnx.qcc.option.linker.libraryPaths.880489672" name="Library Paths (-L)" superClass="com.qnx.qcc.option.linker.libraryPaths" valueType="libPaths">
|
||||
|
@ -497,14 +492,13 @@
|
|||
<listOptionValue builtIn="false" value="GLESv1_CM"/>
|
||||
<listOptionValue builtIn="false" value="bps"/>
|
||||
<listOptionValue builtIn="false" value="curl"/>
|
||||
<listOptionValue builtIn="false" value="mmrndclient"/>
|
||||
<listOptionValue builtIn="false" value="strm"/>
|
||||
<listOptionValue builtIn="false" value="grskia"/>
|
||||
<listOptionValue builtIn="false" value="OpenAL"/>
|
||||
<listOptionValue builtIn="false" value="alut"/>
|
||||
<listOptionValue builtIn="false" value="curl"/>
|
||||
<listOptionValue builtIn="false" value="asound"/>
|
||||
<listOptionValue builtIn="false" value="xml2"/>
|
||||
<listOptionValue builtIn="false" value="vorbis"/>
|
||||
</option>
|
||||
<option id="com.qnx.qcc.option.linker.security.1780600507" name="Enhanced Security (-Wl,-z,relro -Wl,-z,now)" superClass="com.qnx.qcc.option.linker.security" value="true" valueType="boolean"/>
|
||||
<option id="com.qnx.qcc.option.linker.libraryPaths.1204179500" name="Library Paths (-L)" superClass="com.qnx.qcc.option.linker.libraryPaths" valueType="libPaths">
|
||||
|
@ -586,14 +580,13 @@
|
|||
<listOptionValue builtIn="false" value="GLESv1_CM"/>
|
||||
<listOptionValue builtIn="false" value="bps"/>
|
||||
<listOptionValue builtIn="false" value="curl"/>
|
||||
<listOptionValue builtIn="false" value="mmrndclient"/>
|
||||
<listOptionValue builtIn="false" value="strm"/>
|
||||
<listOptionValue builtIn="false" value="grskia"/>
|
||||
<listOptionValue builtIn="false" value="OpenAL"/>
|
||||
<listOptionValue builtIn="false" value="alut"/>
|
||||
<listOptionValue builtIn="false" value="curl"/>
|
||||
<listOptionValue builtIn="false" value="asound"/>
|
||||
<listOptionValue builtIn="false" value="xml2"/>
|
||||
<listOptionValue builtIn="false" value="vorbis"/>
|
||||
</option>
|
||||
<option id="com.qnx.qcc.option.linker.security.1136026548" name="Enhanced Security (-Wl,-z,relro -Wl,-z,now)" superClass="com.qnx.qcc.option.linker.security" value="true" valueType="boolean"/>
|
||||
<option id="com.qnx.qcc.option.linker.libraryPaths.1949291872" name="Library Paths (-L)" superClass="com.qnx.qcc.option.linker.libraryPaths" valueType="libPaths">
|
||||
|
@ -653,5 +646,7 @@
|
|||
</scannerConfigBuildInfo>
|
||||
</storageModule>
|
||||
<storageModule moduleId="com.qnx.tools.ide.qde.core.QNXProjectProperties"/>
|
||||
<storageModule moduleId="refreshScope"/>
|
||||
<storageModule moduleId="refreshScope" versionNumber="1">
|
||||
<resource resourceType="PROJECT" workspacePath="/TestCocos2dx"/>
|
||||
</storageModule>
|
||||
</cproject>
|
||||
|
|
|
@ -13,6 +13,8 @@
|
|||
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
|
||||
#define MUSIC_FILE "music.mid"
|
||||
#elif (CC_TARGET_PLATFORM == CC_PLATFORM_QNX)
|
||||
#define MUSIC_FILE "background.ogg"
|
||||
#else
|
||||
#define MUSIC_FILE "background.mp3"
|
||||
#endif // CC_PLATFORM_WIN32
|
||||
|
|
|
@ -50,6 +50,8 @@ void UserDefaultTest::doTest()
|
|||
{
|
||||
CCLOG("bool is false");
|
||||
}
|
||||
|
||||
//CCUserDefault::sharedUserDefault()->flush();
|
||||
|
||||
CCLOG("********************** after change value ***********************");
|
||||
|
||||
|
@ -61,6 +63,8 @@ void UserDefaultTest::doTest()
|
|||
CCUserDefault::sharedUserDefault()->setDoubleForKey("double", 2.6);
|
||||
CCUserDefault::sharedUserDefault()->setBoolForKey("bool", false);
|
||||
|
||||
CCUserDefault::sharedUserDefault()->flush();
|
||||
|
||||
// print value
|
||||
|
||||
ret = CCUserDefault::sharedUserDefault()->getStringForKey("string");
|
||||
|
|
Loading…
Reference in New Issue