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}/usr/include/freetype2"/>
|
||||||
<listOptionValue builtIn="false" value="${QNX_TARGET}/../target-override/usr/include"/>
|
<listOptionValue builtIn="false" value="${QNX_TARGET}/../target-override/usr/include"/>
|
||||||
<listOptionValue builtIn="false" value="../../include"/>
|
<listOptionValue builtIn="false" value="../../include"/>
|
||||||
|
<listOptionValue builtIn="false" value="../../../cocos2dx/platform/third_party/qnx"/>
|
||||||
</option>
|
</option>
|
||||||
<inputType id="com.qnx.qcc.inputType.compiler.1849571146" superClass="com.qnx.qcc.inputType.compiler"/>
|
<inputType id="com.qnx.qcc.inputType.compiler.1849571146" superClass="com.qnx.qcc.inputType.compiler"/>
|
||||||
</tool>
|
</tool>
|
||||||
|
@ -118,6 +119,7 @@
|
||||||
<listOptionValue builtIn="false" value="${QNX_TARGET}/usr/include/freetype2"/>
|
<listOptionValue builtIn="false" value="${QNX_TARGET}/usr/include/freetype2"/>
|
||||||
<listOptionValue builtIn="false" value="${QNX_TARGET}/../target-override/usr/include"/>
|
<listOptionValue builtIn="false" value="${QNX_TARGET}/../target-override/usr/include"/>
|
||||||
<listOptionValue builtIn="false" value="../../include"/>
|
<listOptionValue builtIn="false" value="../../include"/>
|
||||||
|
<listOptionValue builtIn="false" value="../../../cocos2dx/platform/third_party/qnx"/>
|
||||||
</option>
|
</option>
|
||||||
<inputType id="com.qnx.qcc.inputType.compiler.82187465" superClass="com.qnx.qcc.inputType.compiler"/>
|
<inputType id="com.qnx.qcc.inputType.compiler.82187465" superClass="com.qnx.qcc.inputType.compiler"/>
|
||||||
</tool>
|
</tool>
|
||||||
|
@ -183,6 +185,7 @@
|
||||||
<listOptionValue builtIn="false" value="${QNX_TARGET}/usr/include/freetype2"/>
|
<listOptionValue builtIn="false" value="${QNX_TARGET}/usr/include/freetype2"/>
|
||||||
<listOptionValue builtIn="false" value="${QNX_TARGET}/../target-override/usr/include"/>
|
<listOptionValue builtIn="false" value="${QNX_TARGET}/../target-override/usr/include"/>
|
||||||
<listOptionValue builtIn="false" value="../../include"/>
|
<listOptionValue builtIn="false" value="../../include"/>
|
||||||
|
<listOptionValue builtIn="false" value="../../../cocos2dx/platform/third_party/qnx"/>
|
||||||
</option>
|
</option>
|
||||||
<inputType id="com.qnx.qcc.inputType.compiler.2036659301" superClass="com.qnx.qcc.inputType.compiler"/>
|
<inputType id="com.qnx.qcc.inputType.compiler.2036659301" superClass="com.qnx.qcc.inputType.compiler"/>
|
||||||
</tool>
|
</tool>
|
||||||
|
@ -251,6 +254,7 @@
|
||||||
<listOptionValue builtIn="false" value="${QNX_TARGET}/usr/include/freetype2"/>
|
<listOptionValue builtIn="false" value="${QNX_TARGET}/usr/include/freetype2"/>
|
||||||
<listOptionValue builtIn="false" value="${QNX_TARGET}/../target-override/usr/include"/>
|
<listOptionValue builtIn="false" value="${QNX_TARGET}/../target-override/usr/include"/>
|
||||||
<listOptionValue builtIn="false" value="../../include"/>
|
<listOptionValue builtIn="false" value="../../include"/>
|
||||||
|
<listOptionValue builtIn="false" value="../../../cocos2dx/platform/third_party/qnx"/>
|
||||||
</option>
|
</option>
|
||||||
<inputType id="com.qnx.qcc.inputType.compiler.1381169559" superClass="com.qnx.qcc.inputType.compiler"/>
|
<inputType id="com.qnx.qcc.inputType.compiler.1381169559" superClass="com.qnx.qcc.inputType.compiler"/>
|
||||||
</tool>
|
</tool>
|
||||||
|
@ -317,6 +321,7 @@
|
||||||
<listOptionValue builtIn="false" value="${QNX_TARGET}/usr/include/freetype2"/>
|
<listOptionValue builtIn="false" value="${QNX_TARGET}/usr/include/freetype2"/>
|
||||||
<listOptionValue builtIn="false" value="${QNX_TARGET}/../target-override/usr/include"/>
|
<listOptionValue builtIn="false" value="${QNX_TARGET}/../target-override/usr/include"/>
|
||||||
<listOptionValue builtIn="false" value="../../include"/>
|
<listOptionValue builtIn="false" value="../../include"/>
|
||||||
|
<listOptionValue builtIn="false" value="../../../cocos2dx/platform/third_party/qnx"/>
|
||||||
</option>
|
</option>
|
||||||
<inputType id="com.qnx.qcc.inputType.compiler.1896937509" superClass="com.qnx.qcc.inputType.compiler"/>
|
<inputType id="com.qnx.qcc.inputType.compiler.1896937509" superClass="com.qnx.qcc.inputType.compiler"/>
|
||||||
</tool>
|
</tool>
|
||||||
|
@ -383,6 +388,7 @@
|
||||||
<listOptionValue builtIn="false" value="${QNX_TARGET}/usr/include/freetype2"/>
|
<listOptionValue builtIn="false" value="${QNX_TARGET}/usr/include/freetype2"/>
|
||||||
<listOptionValue builtIn="false" value="${QNX_TARGET}/../target-override/usr/include"/>
|
<listOptionValue builtIn="false" value="${QNX_TARGET}/../target-override/usr/include"/>
|
||||||
<listOptionValue builtIn="false" value="../../include"/>
|
<listOptionValue builtIn="false" value="../../include"/>
|
||||||
|
<listOptionValue builtIn="false" value="../../../cocos2dx/platform/third_party/qnx"/>
|
||||||
</option>
|
</option>
|
||||||
<inputType id="com.qnx.qcc.inputType.compiler.746859765" superClass="com.qnx.qcc.inputType.compiler"/>
|
<inputType id="com.qnx.qcc.inputType.compiler.746859765" superClass="com.qnx.qcc.inputType.compiler"/>
|
||||||
</tool>
|
</tool>
|
||||||
|
@ -450,6 +456,7 @@
|
||||||
<listOptionValue builtIn="false" value="${QNX_TARGET}/usr/include/freetype2"/>
|
<listOptionValue builtIn="false" value="${QNX_TARGET}/usr/include/freetype2"/>
|
||||||
<listOptionValue builtIn="false" value="${QNX_TARGET}/../target-override/usr/include"/>
|
<listOptionValue builtIn="false" value="${QNX_TARGET}/../target-override/usr/include"/>
|
||||||
<listOptionValue builtIn="false" value="../../include"/>
|
<listOptionValue builtIn="false" value="../../include"/>
|
||||||
|
<listOptionValue builtIn="false" value="../../../cocos2dx/platform/third_party/qnx"/>
|
||||||
</option>
|
</option>
|
||||||
<inputType id="com.qnx.qcc.inputType.compiler.1894319763" superClass="com.qnx.qcc.inputType.compiler"/>
|
<inputType id="com.qnx.qcc.inputType.compiler.1894319763" superClass="com.qnx.qcc.inputType.compiler"/>
|
||||||
</tool>
|
</tool>
|
||||||
|
@ -511,6 +518,8 @@
|
||||||
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="com.qnx.tools.ide.qde.managedbuilder.core.qccScannerInfo"/>
|
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="com.qnx.tools.ide.qde.managedbuilder.core.qccScannerInfo"/>
|
||||||
</scannerConfigBuildInfo>
|
</scannerConfigBuildInfo>
|
||||||
</storageModule>
|
</storageModule>
|
||||||
<storageModule moduleId="refreshScope"/>
|
<storageModule moduleId="refreshScope" versionNumber="1">
|
||||||
|
<resource resourceType="PROJECT" workspacePath="/CocosDenshion"/>
|
||||||
|
</storageModule>
|
||||||
<storageModule moduleId="com.qnx.tools.ide.qde.core.QNXProjectProperties"/>
|
<storageModule moduleId="com.qnx.tools.ide.qde.core.QNXProjectProperties"/>
|
||||||
</cproject>
|
</cproject>
|
||||||
|
|
|
@ -30,10 +30,8 @@ THE SOFTWARE.
|
||||||
#include <AL/al.h>
|
#include <AL/al.h>
|
||||||
#include <AL/alc.h>
|
#include <AL/alc.h>
|
||||||
#include <AL/alut.h>
|
#include <AL/alut.h>
|
||||||
#include <mm/renderer.h>
|
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
#include <vorbis/vorbisfile.h>
|
||||||
//#include "CCFileUtils.h"
|
|
||||||
|
|
||||||
#include "SimpleAudioEngine.h"
|
#include "SimpleAudioEngine.h"
|
||||||
|
|
||||||
|
@ -56,115 +54,68 @@ namespace CocosDenshion
|
||||||
PAUSED,
|
PAUSED,
|
||||||
} playStatus;
|
} playStatus;
|
||||||
|
|
||||||
static int s_audioOid;
|
|
||||||
|
|
||||||
static float s_volume = 1.0f;
|
static float s_volume = 1.0f;
|
||||||
static float s_effectVolume = 1.0f;
|
static float s_effectVolume = 1.0f;
|
||||||
static bool s_isBackgroundInitialized = false;
|
static bool s_isBackgroundInitialized = false;
|
||||||
static bool s_hasMMRError = false;
|
static std::string s_currentBackgroundStr;
|
||||||
static playStatus s_playStatus = STOPPED;
|
|
||||||
|
|
||||||
static string s_currentBackgroundStr;
|
ALuint s_backgroundBuffer;
|
||||||
static mmr_connection_t *s_mmrConnection = 0;
|
ALuint s_backgroundSource;
|
||||||
static mmr_context_t *s_mmrContext = 0;
|
|
||||||
static strm_dict_t *s_repeatDictionary = 0;
|
|
||||||
static strm_dict_t *s_volumeDictionary = 0;
|
|
||||||
|
|
||||||
static SimpleAudioEngine *s_engine = 0;
|
static SimpleAudioEngine *s_engine = 0;
|
||||||
|
|
||||||
static void printALError(int err)
|
static int checkALError(const char *funcName)
|
||||||
|
{
|
||||||
|
int err = alGetError();
|
||||||
|
|
||||||
|
if (err != AL_NO_ERROR)
|
||||||
{
|
{
|
||||||
switch (err)
|
switch (err)
|
||||||
{
|
{
|
||||||
case AL_NO_ERROR:
|
|
||||||
fprintf(stderr, "AL_NO_ERROR");
|
|
||||||
break;
|
|
||||||
|
|
||||||
case AL_INVALID_NAME:
|
case AL_INVALID_NAME:
|
||||||
fprintf(stderr, "AL_INVALID_NAME");
|
fprintf(stderr, "AL_INVALID_NAME in %s\n", funcName);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case AL_INVALID_ENUM:
|
case AL_INVALID_ENUM:
|
||||||
fprintf(stderr, "AL_INVALID_ENUM");
|
fprintf(stderr, "AL_INVALID_ENUM in %s\n", funcName);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case AL_INVALID_VALUE:
|
case AL_INVALID_VALUE:
|
||||||
fprintf(stderr, "AL_INVALID_VALUE");
|
fprintf(stderr, "AL_INVALID_VALUE in %s\n", funcName);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case AL_INVALID_OPERATION:
|
case AL_INVALID_OPERATION:
|
||||||
fprintf(stderr, "AL_INVALID_OPERATION");
|
fprintf(stderr, "AL_INVALID_OPERATION in %s\n", funcName);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case AL_OUT_OF_MEMORY:
|
case AL_OUT_OF_MEMORY:
|
||||||
fprintf(stderr, "AL_OUT_OF_MEMORY");
|
fprintf(stderr, "AL_OUT_OF_MEMORY in %s\n", funcName);
|
||||||
break;
|
break;
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void mmrerror(mmr_context_t *ctxt, const char *msg)
|
return err;
|
||||||
{
|
|
||||||
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)
|
static void stopBackground(bool bReleaseData)
|
||||||
{
|
{
|
||||||
s_playStatus = STOPPED;
|
alSourceStop(s_backgroundSource);
|
||||||
|
|
||||||
if (s_mmrContext)
|
|
||||||
mmr_stop(s_mmrContext);
|
|
||||||
|
|
||||||
if (bReleaseData)
|
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_currentBackgroundStr = "";
|
||||||
s_isBackgroundInitialized = false;
|
s_isBackgroundInitialized = false;
|
||||||
|
|
||||||
|
alDeleteBuffers(1, &s_backgroundBuffer);
|
||||||
|
checkALError("stopBackground");
|
||||||
|
alDeleteSources(1, &s_backgroundSource);
|
||||||
|
checkALError("stopBackground");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void setBackgroundVolume(float volume)
|
static void setBackgroundVolume(float volume)
|
||||||
{
|
{
|
||||||
if (!s_isBackgroundInitialized)
|
alSourcef(s_backgroundSource, AL_GAIN, volume);
|
||||||
{
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SimpleAudioEngine::SimpleAudioEngine()
|
SimpleAudioEngine::SimpleAudioEngine()
|
||||||
|
@ -187,23 +138,22 @@ namespace CocosDenshion
|
||||||
|
|
||||||
void SimpleAudioEngine::end()
|
void SimpleAudioEngine::end()
|
||||||
{
|
{
|
||||||
|
checkALError("end");
|
||||||
|
|
||||||
// clear all the sounds
|
// clear all the sounds
|
||||||
EffectsMap::const_iterator end = s_effects.end();
|
EffectsMap::const_iterator end = s_effects.end();
|
||||||
for (EffectsMap::iterator it = s_effects.begin(); it != end; it++)
|
for (EffectsMap::iterator it = s_effects.begin(); it != end; it++)
|
||||||
{
|
{
|
||||||
alSourceStop(it->second->source);
|
alSourceStop(it->second->source);
|
||||||
|
checkALError("end");
|
||||||
alDeleteBuffers(1, &it->second->buffer);
|
alDeleteBuffers(1, &it->second->buffer);
|
||||||
|
checkALError("end");
|
||||||
alDeleteSources(1, &it->second->source);
|
alDeleteSources(1, &it->second->source);
|
||||||
|
checkALError("end");
|
||||||
delete it->second;
|
delete it->second;
|
||||||
}
|
}
|
||||||
s_effects.clear();
|
s_effects.clear();
|
||||||
|
|
||||||
if (s_isBackgroundInitialized)
|
|
||||||
{
|
|
||||||
s_isBackgroundInitialized = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// and the background too
|
// and the background too
|
||||||
stopBackground(true);
|
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)
|
void SimpleAudioEngine::preloadBackgroundMusic(const char* pszFilePath)
|
||||||
{
|
{
|
||||||
if (!s_isBackgroundInitialized)
|
if (!s_isBackgroundInitialized || s_currentBackgroundStr != pszFilePath)
|
||||||
{
|
{
|
||||||
const char *mmrname = NULL;
|
string path = pszFilePath;
|
||||||
const char *ctxtname = "mmrplayer";
|
|
||||||
char cwd[PATH_MAX];
|
|
||||||
mode_t mode = S_IRUSR | S_IXUSR;
|
|
||||||
|
|
||||||
getcwd(cwd, PATH_MAX);
|
if (isOGGFile(path.data()))
|
||||||
string path = "file://";
|
|
||||||
path += cwd;
|
|
||||||
path += "/";
|
|
||||||
path += pszFilePath;
|
|
||||||
|
|
||||||
s_mmrConnection = mmr_connect(mmrname);
|
|
||||||
if (!s_mmrConnection)
|
|
||||||
{
|
{
|
||||||
perror("mmr_connect");
|
s_backgroundBuffer = createBufferFromOGG(path.data());
|
||||||
s_hasMMRError = true;
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
s_backgroundBuffer = alutCreateBufferFromFile(path.data());
|
||||||
|
}
|
||||||
|
|
||||||
|
checkALError("preloadBackgroundMusic");
|
||||||
|
|
||||||
|
if (s_backgroundBuffer == AL_NONE)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Error loading file: '%s'\n", path.data());
|
||||||
|
alDeleteBuffers(1, &s_backgroundBuffer);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
s_mmrContext = mmr_context_create(s_mmrConnection, ctxtname, 0, mode);
|
alGenSources(1, &s_backgroundSource);
|
||||||
if (!s_mmrContext)
|
checkALError("preloadBackgroundMusic");
|
||||||
{
|
|
||||||
perror(ctxtname);
|
|
||||||
s_hasMMRError = true;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((s_audioOid = mmr_output_attach(s_mmrContext, "audio:default", "audio")) < 0)
|
alSourcei(s_backgroundSource, AL_BUFFER, s_backgroundBuffer);
|
||||||
{
|
checkALError("preloadBackgroundMusic");
|
||||||
mmrerror(s_mmrContext, "audio:default");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mmr_input_attach(s_mmrContext, path.data(), "autolist") < 0)
|
s_currentBackgroundStr = pszFilePath;
|
||||||
{
|
|
||||||
fprintf(stderr, "unable to load %s\n", path.data());
|
|
||||||
mmrerror(s_mmrContext, path.data());
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
s_currentBackgroundStr = pszFilePath;
|
s_currentBackgroundStr = pszFilePath;
|
||||||
s_isBackgroundInitialized = true;
|
s_isBackgroundInitialized = true;
|
||||||
setBackgroundVolume(s_volume);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SimpleAudioEngine::playBackgroundMusic(const char* pszFilePath, bool bLoop)
|
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)
|
if (!s_isBackgroundInitialized)
|
||||||
preloadBackgroundMusic(pszFilePath);
|
preloadBackgroundMusic(pszFilePath);
|
||||||
|
|
||||||
if (bLoop)
|
alSourcei(s_backgroundSource, AL_LOOPING, bLoop ? AL_TRUE : AL_FALSE);
|
||||||
{
|
alSourcePlay(s_backgroundSource);
|
||||||
// set it up to loop
|
checkALError("playBackgroundMusic");
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SimpleAudioEngine::stopBackgroundMusic(bool bReleaseData)
|
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);
|
stopBackground(bReleaseData);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SimpleAudioEngine::pauseBackgroundMusic()
|
void SimpleAudioEngine::pauseBackgroundMusic()
|
||||||
{
|
{
|
||||||
if (s_mmrContext && mmr_speed_set(s_mmrContext, 0) < 0)
|
alSourcePause(s_backgroundSource);
|
||||||
{
|
checkALError("pauseBackgroundMusic");
|
||||||
mmrerror(s_mmrContext, "pause");
|
|
||||||
}
|
|
||||||
s_playStatus = PAUSED;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SimpleAudioEngine::resumeBackgroundMusic()
|
void SimpleAudioEngine::resumeBackgroundMusic()
|
||||||
{
|
{
|
||||||
if (s_mmrContext && mmr_speed_set(s_mmrContext, 1000) < 0)
|
alSourcePlay(s_backgroundSource);
|
||||||
{
|
checkALError("resumeBackgroundMusic");
|
||||||
mmrerror(s_mmrContext, "resume");
|
|
||||||
}
|
|
||||||
s_playStatus = PLAYING;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SimpleAudioEngine::rewindBackgroundMusic()
|
void SimpleAudioEngine::rewindBackgroundMusic()
|
||||||
{
|
{
|
||||||
if (s_mmrContext && mmr_seek(s_mmrContext, "1:0") < 0)
|
alSourceRewind(s_backgroundSource);
|
||||||
{
|
checkALError("rewindBackgroundMusic");
|
||||||
mmrerror(s_mmrContext, "rewind");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SimpleAudioEngine::willPlayBackgroundMusic()
|
bool SimpleAudioEngine::willPlayBackgroundMusic()
|
||||||
|
@ -350,7 +336,10 @@ namespace CocosDenshion
|
||||||
|
|
||||||
bool SimpleAudioEngine::isBackgroundMusicPlaying()
|
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()
|
float SimpleAudioEngine::getBackgroundMusicVolume()
|
||||||
|
@ -407,9 +396,11 @@ namespace CocosDenshion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
checkALError("playEffect");
|
||||||
iter->second->isLooped = bLoop;
|
iter->second->isLooped = bLoop;
|
||||||
alSourcei(iter->second->source, AL_LOOPING, iter->second->isLooped ? AL_TRUE : AL_FALSE);
|
alSourcei(iter->second->source, AL_LOOPING, iter->second->isLooped ? AL_TRUE : AL_FALSE);
|
||||||
alSourcePlay(iter->second->source);
|
alSourcePlay(iter->second->source);
|
||||||
|
checkALError("playEffect");
|
||||||
|
|
||||||
return iter->second->source;
|
return iter->second->source;
|
||||||
}
|
}
|
||||||
|
@ -417,6 +408,7 @@ namespace CocosDenshion
|
||||||
void SimpleAudioEngine::stopEffect(unsigned int nSoundId)
|
void SimpleAudioEngine::stopEffect(unsigned int nSoundId)
|
||||||
{
|
{
|
||||||
alSourceStop(nSoundId);
|
alSourceStop(nSoundId);
|
||||||
|
checkALError("stopEffect");
|
||||||
}
|
}
|
||||||
|
|
||||||
void SimpleAudioEngine::preloadEffect(const char* pszFilePath)
|
void SimpleAudioEngine::preloadEffect(const char* pszFilePath)
|
||||||
|
@ -429,10 +421,19 @@ namespace CocosDenshion
|
||||||
ALuint buffer;
|
ALuint buffer;
|
||||||
ALuint source;
|
ALuint source;
|
||||||
soundData *data = new soundData;
|
soundData *data = new soundData;
|
||||||
|
|
||||||
string path = pszFilePath;
|
string path = pszFilePath;
|
||||||
|
|
||||||
|
checkALError("preloadEffect");
|
||||||
|
|
||||||
|
if (isOGGFile(path.data()))
|
||||||
|
{
|
||||||
|
buffer = createBufferFromOGG(path.data());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
buffer = alutCreateBufferFromFile(path.data());
|
buffer = alutCreateBufferFromFile(path.data());
|
||||||
|
checkALError("preloadEffect");
|
||||||
|
}
|
||||||
|
|
||||||
if (buffer == AL_NONE)
|
if (buffer == AL_NONE)
|
||||||
{
|
{
|
||||||
|
@ -442,7 +443,15 @@ namespace CocosDenshion
|
||||||
}
|
}
|
||||||
|
|
||||||
alGenSources(1, &source);
|
alGenSources(1, &source);
|
||||||
|
|
||||||
|
if (checkALError("preloadEffect") != AL_NO_ERROR)
|
||||||
|
{
|
||||||
|
alDeleteBuffers(1, &buffer);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
alSourcei(source, AL_BUFFER, buffer);
|
alSourcei(source, AL_BUFFER, buffer);
|
||||||
|
checkALError("preloadEffect");
|
||||||
|
|
||||||
data->isLooped = false;
|
data->isLooped = false;
|
||||||
data->buffer = buffer;
|
data->buffer = buffer;
|
||||||
|
@ -458,14 +467,17 @@ namespace CocosDenshion
|
||||||
|
|
||||||
if (iter != s_effects.end())
|
if (iter != s_effects.end())
|
||||||
{
|
{
|
||||||
alSourceStop(iter->second->source);
|
checkALError("unloadEffect");
|
||||||
alDeleteSources(1, &iter->second->source);
|
|
||||||
alDeleteBuffers(1, &iter->second->buffer);
|
|
||||||
delete iter->second;
|
|
||||||
|
|
||||||
int err = alGetError();
|
alSourceStop(iter->second->source);
|
||||||
if (err != AL_NO_ERROR)
|
checkALError("unloadEffect");
|
||||||
printALError(err);
|
|
||||||
|
alDeleteSources(1, &iter->second->source);
|
||||||
|
checkALError("unloadEffect");
|
||||||
|
|
||||||
|
alDeleteBuffers(1, &iter->second->buffer);
|
||||||
|
checkALError("unloadEffect");
|
||||||
|
delete iter->second;
|
||||||
|
|
||||||
s_effects.erase(iter);
|
s_effects.erase(iter);
|
||||||
}
|
}
|
||||||
|
@ -474,6 +486,7 @@ namespace CocosDenshion
|
||||||
void SimpleAudioEngine::pauseEffect(unsigned int nSoundId)
|
void SimpleAudioEngine::pauseEffect(unsigned int nSoundId)
|
||||||
{
|
{
|
||||||
alSourcePause(nSoundId);
|
alSourcePause(nSoundId);
|
||||||
|
checkALError("pauseEffect");
|
||||||
}
|
}
|
||||||
|
|
||||||
void SimpleAudioEngine::pauseAllEffects()
|
void SimpleAudioEngine::pauseAllEffects()
|
||||||
|
@ -483,15 +496,14 @@ namespace CocosDenshion
|
||||||
if (iter != s_effects.end())
|
if (iter != s_effects.end())
|
||||||
{
|
{
|
||||||
alSourcePause(iter->second->source);
|
alSourcePause(iter->second->source);
|
||||||
int err = alGetError();
|
checkALError("pauseAllEffects");
|
||||||
if (err != AL_NO_ERROR)
|
|
||||||
printALError(err);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SimpleAudioEngine::resumeEffect(unsigned int nSoundId)
|
void SimpleAudioEngine::resumeEffect(unsigned int nSoundId)
|
||||||
{
|
{
|
||||||
alSourcePlay(nSoundId);
|
alSourcePlay(nSoundId);
|
||||||
|
checkALError("resumeEffect");
|
||||||
}
|
}
|
||||||
|
|
||||||
void SimpleAudioEngine::resumeAllEffects()
|
void SimpleAudioEngine::resumeAllEffects()
|
||||||
|
@ -500,10 +512,9 @@ namespace CocosDenshion
|
||||||
|
|
||||||
if (iter != s_effects.end())
|
if (iter != s_effects.end())
|
||||||
{
|
{
|
||||||
|
checkALError("resumeAllEffects");
|
||||||
alSourcePlay(iter->second->source);
|
alSourcePlay(iter->second->source);
|
||||||
int err = alGetError();
|
checkALError("resumeAllEffects");
|
||||||
if (err != AL_NO_ERROR)
|
|
||||||
printALError(err);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -513,10 +524,9 @@ namespace CocosDenshion
|
||||||
|
|
||||||
if (iter != s_effects.end())
|
if (iter != s_effects.end())
|
||||||
{
|
{
|
||||||
|
checkALError("stopAllEffects");
|
||||||
alSourceStop(iter->second->source);
|
alSourceStop(iter->second->source);
|
||||||
int err = alGetError();
|
checkALError("stopAllEffects");
|
||||||
if (err != AL_NO_ERROR)
|
|
||||||
printALError(err);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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
|
-- avoid memory leak
|
||||||
collectgarbage( "setpause", 100)
|
collectgarbage("setpause", 100)
|
||||||
collectgarbage( "setstepmul", 5000)
|
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()
|
||||||
|
|
||||||
|
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");
|
||||||
|
|
||||||
-- play background music
|
|
||||||
CocosDenshion.SimpleAudioEngine:sharedEngine():playBackgroundMusic("background.mp3", true);
|
|
||||||
-- preload effect
|
|
||||||
CocosDenshion.SimpleAudioEngine:sharedEngine():preloadEffect("effect1.wav");
|
|
||||||
-- run
|
-- run
|
||||||
cocos2d.CCDirector:sharedDirector():runWithScene(sceneGame)
|
local sceneGame = CCScene:node()
|
||||||
|
sceneGame:addChild(createLayerFram())
|
||||||
|
sceneGame:addChild(createLayerMenu())
|
||||||
|
CCDirector:sharedDirector():runWithScene(sceneGame)
|
||||||
|
|
|
@ -74,8 +74,8 @@ public class Cocos2dxBitmap{
|
||||||
// Draw string
|
// Draw string
|
||||||
FontMetricsInt fm = paint.getFontMetricsInt();
|
FontMetricsInt fm = paint.getFontMetricsInt();
|
||||||
int x = 0;
|
int x = 0;
|
||||||
int y = height == 0 ?(-fm.ascent):
|
int y = height == 0 ?(-fm.top):
|
||||||
(-fm.ascent + (height - textProperty.totalHeight)/2);
|
(-fm.top + (height - textProperty.totalHeight)/2);
|
||||||
String[] lines = textProperty.lines;
|
String[] lines = textProperty.lines;
|
||||||
for (String line : lines){
|
for (String line : lines){
|
||||||
x = computeX(paint, line, textProperty.maxWidth, alignment);
|
x = computeX(paint, line, textProperty.maxWidth, alignment);
|
||||||
|
@ -132,7 +132,7 @@ public class Cocos2dxBitmap{
|
||||||
private static TextProperty computeTextProperty(String content, Paint paint,
|
private static TextProperty computeTextProperty(String content, Paint paint,
|
||||||
int maxWidth, int maxHeight){
|
int maxWidth, int maxHeight){
|
||||||
FontMetricsInt fm = paint.getFontMetricsInt();
|
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;
|
int maxContentWidth = 0;
|
||||||
|
|
||||||
String[] lines = splitString(content, maxHeight, maxWidth, paint);
|
String[] lines = splitString(content, maxHeight, maxWidth, paint);
|
||||||
|
@ -165,7 +165,7 @@ public class Cocos2dxBitmap{
|
||||||
String[] lines = content.split("\\n");
|
String[] lines = content.split("\\n");
|
||||||
String[] ret = null;
|
String[] ret = null;
|
||||||
FontMetricsInt fm = paint.getFontMetricsInt();
|
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;
|
int maxLines = maxHeight / heightPerLine;
|
||||||
|
|
||||||
if (maxWidth != 0){
|
if (maxWidth != 0){
|
||||||
|
@ -236,7 +236,7 @@ public class Cocos2dxBitmap{
|
||||||
if (tempWidth >= width){
|
if (tempWidth >= width){
|
||||||
int lastIndexOfSpace = content.substring(0, i).lastIndexOf(" ");
|
int lastIndexOfSpace = content.substring(0, i).lastIndexOf(" ");
|
||||||
|
|
||||||
if (lastIndexOfSpace != -1){
|
if (lastIndexOfSpace != -1 && lastIndexOfSpace > start){
|
||||||
/**
|
/**
|
||||||
* Should wrap the word
|
* Should wrap the word
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -282,9 +282,10 @@ public class Cocos2dxGLSurfaceView extends GLSurfaceView {
|
||||||
|
|
||||||
switch (event.getAction() & MotionEvent.ACTION_MASK) {
|
switch (event.getAction() & MotionEvent.ACTION_MASK) {
|
||||||
case MotionEvent.ACTION_POINTER_DOWN:
|
case MotionEvent.ACTION_POINTER_DOWN:
|
||||||
final int idPointerDown = event.getAction() >> MotionEvent.ACTION_POINTER_ID_SHIFT;
|
final int indexPointerDown = event.getAction() >> MotionEvent.ACTION_POINTER_ID_SHIFT;
|
||||||
final float xPointerDown = event.getX(idPointerDown);
|
final int idPointerDown = event.getPointerId(indexPointerDown);
|
||||||
final float yPointerDown = event.getY(idPointerDown);
|
final float xPointerDown = event.getX(indexPointerDown);
|
||||||
|
final float yPointerDown = event.getY(indexPointerDown);
|
||||||
|
|
||||||
queueEvent(new Runnable() {
|
queueEvent(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -318,9 +319,10 @@ public class Cocos2dxGLSurfaceView extends GLSurfaceView {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MotionEvent.ACTION_POINTER_UP:
|
case MotionEvent.ACTION_POINTER_UP:
|
||||||
final int idPointerUp = event.getAction() >> MotionEvent.ACTION_POINTER_ID_SHIFT;
|
final int indexPointUp = event.getAction() >> MotionEvent.ACTION_POINTER_ID_SHIFT;
|
||||||
final float xPointerUp = event.getX(idPointerUp);
|
final int idPointerUp = event.getPointerId(indexPointUp);
|
||||||
final float yPointerUp = event.getY(idPointerUp);
|
final float xPointerUp = event.getX(indexPointUp);
|
||||||
|
final float yPointerUp = event.getY(indexPointUp);
|
||||||
|
|
||||||
queueEvent(new Runnable() {
|
queueEvent(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
d1f0ba1c97add6d33ba2628f3a35ad1ed676c4f5
|
0a874bd51db1bbbd82d2c0ed77650a0ac0f323f6
|
|
@ -0,0 +1 @@
|
||||||
|
abc899cd55086105f439df7a6d01db84168aebb5
|
|
@ -74,8 +74,8 @@ public class Cocos2dxBitmap{
|
||||||
// Draw string
|
// Draw string
|
||||||
FontMetricsInt fm = paint.getFontMetricsInt();
|
FontMetricsInt fm = paint.getFontMetricsInt();
|
||||||
int x = 0;
|
int x = 0;
|
||||||
int y = height == 0 ?(-fm.ascent):
|
int y = height == 0 ?(-fm.top):
|
||||||
(-fm.ascent + (height - textProperty.totalHeight)/2);
|
(-fm.top + (height - textProperty.totalHeight)/2);
|
||||||
String[] lines = textProperty.lines;
|
String[] lines = textProperty.lines;
|
||||||
for (String line : lines){
|
for (String line : lines){
|
||||||
x = computeX(paint, line, textProperty.maxWidth, alignment);
|
x = computeX(paint, line, textProperty.maxWidth, alignment);
|
||||||
|
@ -132,7 +132,7 @@ public class Cocos2dxBitmap{
|
||||||
private static TextProperty computeTextProperty(String content, Paint paint,
|
private static TextProperty computeTextProperty(String content, Paint paint,
|
||||||
int maxWidth, int maxHeight){
|
int maxWidth, int maxHeight){
|
||||||
FontMetricsInt fm = paint.getFontMetricsInt();
|
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;
|
int maxContentWidth = 0;
|
||||||
|
|
||||||
String[] lines = splitString(content, maxHeight, maxWidth, paint);
|
String[] lines = splitString(content, maxHeight, maxWidth, paint);
|
||||||
|
@ -165,7 +165,7 @@ public class Cocos2dxBitmap{
|
||||||
String[] lines = content.split("\\n");
|
String[] lines = content.split("\\n");
|
||||||
String[] ret = null;
|
String[] ret = null;
|
||||||
FontMetricsInt fm = paint.getFontMetricsInt();
|
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;
|
int maxLines = maxHeight / heightPerLine;
|
||||||
|
|
||||||
if (maxWidth != 0){
|
if (maxWidth != 0){
|
||||||
|
@ -236,7 +236,7 @@ public class Cocos2dxBitmap{
|
||||||
if (tempWidth >= width){
|
if (tempWidth >= width){
|
||||||
int lastIndexOfSpace = content.substring(0, i).lastIndexOf(" ");
|
int lastIndexOfSpace = content.substring(0, i).lastIndexOf(" ");
|
||||||
|
|
||||||
if (lastIndexOfSpace != -1){
|
if (lastIndexOfSpace != -1 && lastIndexOfSpace > start){
|
||||||
/**
|
/**
|
||||||
* Should wrap the word
|
* Should wrap the word
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -282,9 +282,10 @@ public class Cocos2dxGLSurfaceView extends GLSurfaceView {
|
||||||
|
|
||||||
switch (event.getAction() & MotionEvent.ACTION_MASK) {
|
switch (event.getAction() & MotionEvent.ACTION_MASK) {
|
||||||
case MotionEvent.ACTION_POINTER_DOWN:
|
case MotionEvent.ACTION_POINTER_DOWN:
|
||||||
final int idPointerDown = event.getAction() >> MotionEvent.ACTION_POINTER_ID_SHIFT;
|
final int indexPointerDown = event.getAction() >> MotionEvent.ACTION_POINTER_ID_SHIFT;
|
||||||
final float xPointerDown = event.getX(idPointerDown);
|
final int idPointerDown = event.getPointerId(indexPointerDown);
|
||||||
final float yPointerDown = event.getY(idPointerDown);
|
final float xPointerDown = event.getX(indexPointerDown);
|
||||||
|
final float yPointerDown = event.getY(indexPointerDown);
|
||||||
|
|
||||||
queueEvent(new Runnable() {
|
queueEvent(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -318,9 +319,10 @@ public class Cocos2dxGLSurfaceView extends GLSurfaceView {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MotionEvent.ACTION_POINTER_UP:
|
case MotionEvent.ACTION_POINTER_UP:
|
||||||
final int idPointerUp = event.getAction() >> MotionEvent.ACTION_POINTER_ID_SHIFT;
|
final int indexPointUp = event.getAction() >> MotionEvent.ACTION_POINTER_ID_SHIFT;
|
||||||
final float xPointerUp = event.getX(idPointerUp);
|
final int idPointerUp = event.getPointerId(indexPointUp);
|
||||||
final float yPointerUp = event.getY(idPointerUp);
|
final float xPointerUp = event.getX(indexPointUp);
|
||||||
|
final float yPointerUp = event.getY(indexPointUp);
|
||||||
|
|
||||||
queueEvent(new Runnable() {
|
queueEvent(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
0bf2e5e584ed953f8de4c1594175403a1d14abd0
|
27ae070112e44d08eaf37af409452a684dcb4185
|
114
README.mdown
114
README.mdown
|
@ -35,117 +35,3 @@ Contact us
|
||||||
[9]: http://forum.cocos2d-x.org "http://forum.cocos2d-x.org"
|
[9]: http://forum.cocos2d-x.org "http://forum.cocos2d-x.org"
|
||||||
[10]: http://www.twitter.com/cocos2dx "http://www.twitter.com/cocos2dx"
|
[10]: http://www.twitter.com/cocos2dx "http://www.twitter.com/cocos2dx"
|
||||||
[11]: http://t.sina.com.cn/cocos2dx "http://t.sina.com.cn/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]
|
[! if !CC_USE_LUA]
|
||||||
|
|
||||||
#include "HelloWorldScene.h"
|
#include "HelloWorldScene.h"
|
||||||
|
[! else]
|
||||||
|
|
||||||
|
#if CC_LUA_ENGINE_ENABLED
|
||||||
|
#include "CCLuaEngine.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
[! endif]
|
[! endif]
|
||||||
|
|
||||||
#include "CCEGLView.h"
|
#include "CCEGLView.h"
|
||||||
|
@ -16,11 +22,7 @@ using namespace CocosDenshion;
|
||||||
USING_NS_CC;
|
USING_NS_CC;
|
||||||
|
|
||||||
AppDelegate::AppDelegate()
|
AppDelegate::AppDelegate()
|
||||||
[! if CC_USE_LUA]
|
|
||||||
:m_pLuaEngine(NULL)
|
|
||||||
[! endif]
|
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
AppDelegate::~AppDelegate()
|
AppDelegate::~AppDelegate()
|
||||||
|
@ -29,9 +31,9 @@ AppDelegate::~AppDelegate()
|
||||||
SimpleAudioEngine::end();
|
SimpleAudioEngine::end();
|
||||||
[! endif]
|
[! endif]
|
||||||
[! if CC_USE_LUA]
|
[! if CC_USE_LUA]
|
||||||
|
#if CC_LUA_ENGINE_ENABLED
|
||||||
CCScriptEngineManager::sharedScriptEngineManager()->removeScriptEngine();
|
CCLuaEngine::purgeSharedEngine();
|
||||||
CC_SAFE_DELETE(m_pLuaEngine);
|
#endif
|
||||||
[! endif]
|
[! endif]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -131,9 +133,8 @@ bool AppDelegate::applicationDidFinishLaunching()
|
||||||
pDirector->setAnimationInterval(1.0 / 60);
|
pDirector->setAnimationInterval(1.0 / 60);
|
||||||
|
|
||||||
[! if CC_USE_LUA]
|
[! if CC_USE_LUA]
|
||||||
// register lua engine
|
// init lua engine
|
||||||
m_pLuaEngine = new LuaEngine;
|
CCLuaEngine* pEngine = CCLuaEngine::sharedEngine();
|
||||||
CCScriptEngineManager::sharedScriptEngineManager()->setScriptEngine(m_pLuaEngine);
|
|
||||||
|
|
||||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
|
||||||
unsigned long size;
|
unsigned long size;
|
||||||
|
@ -147,14 +148,14 @@ bool AppDelegate::applicationDidFinishLaunching()
|
||||||
memcpy(pCodes, pFileContent, size);
|
memcpy(pCodes, pFileContent, size);
|
||||||
delete[] pFileContent;
|
delete[] pFileContent;
|
||||||
|
|
||||||
CCScriptEngineManager::sharedScriptEngineManager()->getScriptEngine()->executeString(pCodes);
|
pEngine->executeString(pCodes);
|
||||||
delete []pCodes;
|
delete []pCodes;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (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");
|
string path = CCFileUtils::fullPathFromRelativePath("hello.lua");
|
||||||
CCScriptEngineManager::sharedScriptEngineManager()->getScriptEngine()->executeScriptFile(path.c_str());
|
pEngine->executeScriptFile(path.c_str());
|
||||||
#endif
|
#endif
|
||||||
[! else]
|
[! else]
|
||||||
// create a scene. it's an autorelease object
|
// create a scene. it's an autorelease object
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
84d1a5cd21bd26c8e2f08241d504b59fe40defc9
|
60686646874bc76241984a6df8beeaa3673f934e
|
|
@ -1 +1 @@
|
||||||
1a854b530b8894d2453fe8777d2d83b8bc68ab91
|
b8d0b27908d823a2687767793e04c64fe1541def
|
|
@ -1 +1 @@
|
||||||
866c5fd880bbb121951818d47d13a4ee914279ad
|
4df124f68856ca5915635b8392bb8aa85c79259f
|
|
@ -1,18 +1,21 @@
|
||||||
#include "AppDelegate.h"
|
|
||||||
|
|
||||||
|
#include "AppDelegate.h"
|
||||||
#include "cocos2d.h"
|
#include "cocos2d.h"
|
||||||
|
#include "SimpleAudioEngine.h"
|
||||||
|
#include "CCLuaEngine.h"
|
||||||
|
|
||||||
USING_NS_CC;
|
USING_NS_CC;
|
||||||
|
using namespace CocosDenshion;
|
||||||
|
|
||||||
AppDelegate::AppDelegate()
|
AppDelegate::AppDelegate()
|
||||||
:m_pLuaEngine(NULL)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
AppDelegate::~AppDelegate()
|
AppDelegate::~AppDelegate()
|
||||||
{
|
{
|
||||||
CCScriptEngineManager::sharedScriptEngineManager()->removeScriptEngine();
|
// end simple audio engine here, or it may crashed on win32
|
||||||
CC_SAFE_DELETE(m_pLuaEngine);
|
SimpleAudioEngine::sharedEngine()->end();
|
||||||
|
CCLuaEngine::purgeSharedEngine();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AppDelegate::initInstance()
|
bool AppDelegate::initInstance()
|
||||||
|
@ -84,9 +87,8 @@ bool AppDelegate::applicationDidFinishLaunching()
|
||||||
// set FPS. the default value is 1.0/60 if you don't call this
|
// set FPS. the default value is 1.0/60 if you don't call this
|
||||||
pDirector->setAnimationInterval(1.0 / 60);
|
pDirector->setAnimationInterval(1.0 / 60);
|
||||||
|
|
||||||
// register lua engine
|
// init lua engine
|
||||||
m_pLuaEngine = new LuaEngine;
|
CCLuaEngine* pEngine = CCLuaEngine::sharedEngine();
|
||||||
CCScriptEngineManager::sharedScriptEngineManager()->setScriptEngine(m_pLuaEngine);
|
|
||||||
|
|
||||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
|
||||||
unsigned long size;
|
unsigned long size;
|
||||||
|
@ -100,41 +102,15 @@ bool AppDelegate::applicationDidFinishLaunching()
|
||||||
memcpy(pCodes, pFileContent, size);
|
memcpy(pCodes, pFileContent, size);
|
||||||
delete[] pFileContent;
|
delete[] pFileContent;
|
||||||
|
|
||||||
CCScriptEngineManager::sharedScriptEngineManager()->getScriptEngine()->executeString(pCodes);
|
pEngine->executeString(pCodes);
|
||||||
delete []pCodes;
|
delete []pCodes;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
|
||||||
// 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)
|
|
||||||
string path = CCFileUtils::fullPathFromRelativePath("hello.lua");
|
string path = CCFileUtils::fullPathFromRelativePath("hello.lua");
|
||||||
CCScriptEngineManager::sharedScriptEngineManager()->getScriptEngine()->addSearchPath(path.substr(0, path.find_last_of("/")).c_str());
|
pEngine->addSearchPath(path.substr(0, path.find_last_of("/")).c_str());
|
||||||
CCScriptEngineManager::sharedScriptEngineManager()->getScriptEngine()->executeScriptFile(path.c_str());
|
pEngine->executeScriptFile(path.c_str());
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
#define _APP_DELEGATE_H_
|
#define _APP_DELEGATE_H_
|
||||||
|
|
||||||
#include "CCApplication.h"
|
#include "CCApplication.h"
|
||||||
#include "LuaEngine.h"
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@brief The cocos2d Application.
|
@brief The cocos2d Application.
|
||||||
|
@ -38,9 +37,6 @@ public:
|
||||||
@param the pointer of the application
|
@param the pointer of the application
|
||||||
*/
|
*/
|
||||||
virtual void applicationWillEnterForeground();
|
virtual void applicationWillEnterForeground();
|
||||||
|
|
||||||
private:
|
|
||||||
LuaEngine* m_pLuaEngine;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // _APP_DELEGATE_H_
|
#endif // _APP_DELEGATE_H_
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
6b542917dfd2180ff6c55bca6cd7b30c64c4a300
|
23cd0723f3707e7fc8c77d718bf3fc0b81b105f6
|
|
@ -1,13 +1,13 @@
|
||||||
#include "AppDelegate.h"
|
|
||||||
|
|
||||||
|
#include "AppDelegate.h"
|
||||||
#include "cocos2d.h"
|
#include "cocos2d.h"
|
||||||
#include "SimpleAudioEngine.h"
|
#include "SimpleAudioEngine.h"
|
||||||
|
#include "CCLuaEngine.h"
|
||||||
|
|
||||||
USING_NS_CC;
|
USING_NS_CC;
|
||||||
using namespace CocosDenshion;
|
using namespace CocosDenshion;
|
||||||
|
|
||||||
AppDelegate::AppDelegate()
|
AppDelegate::AppDelegate()
|
||||||
:m_pLuaEngine(NULL)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,8 +15,7 @@ AppDelegate::~AppDelegate()
|
||||||
{
|
{
|
||||||
// end simple audio engine here, or it may crashed on win32
|
// end simple audio engine here, or it may crashed on win32
|
||||||
SimpleAudioEngine::sharedEngine()->end();
|
SimpleAudioEngine::sharedEngine()->end();
|
||||||
CCScriptEngineManager::sharedScriptEngineManager()->removeScriptEngine();
|
CCLuaEngine::purgeSharedEngine();
|
||||||
CC_SAFE_DELETE(m_pLuaEngine);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AppDelegate::initInstance()
|
bool AppDelegate::initInstance()
|
||||||
|
@ -88,9 +87,8 @@ bool AppDelegate::applicationDidFinishLaunching()
|
||||||
// set FPS. the default value is 1.0/60 if you don't call this
|
// set FPS. the default value is 1.0/60 if you don't call this
|
||||||
pDirector->setAnimationInterval(1.0 / 60);
|
pDirector->setAnimationInterval(1.0 / 60);
|
||||||
|
|
||||||
// register lua engine
|
// init lua engine
|
||||||
m_pLuaEngine = new LuaEngine;
|
CCLuaEngine* pEngine = CCLuaEngine::sharedEngine();
|
||||||
CCScriptEngineManager::sharedScriptEngineManager()->setScriptEngine(m_pLuaEngine);
|
|
||||||
|
|
||||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
|
||||||
unsigned long size;
|
unsigned long size;
|
||||||
|
@ -104,15 +102,15 @@ bool AppDelegate::applicationDidFinishLaunching()
|
||||||
memcpy(pCodes, pFileContent, size);
|
memcpy(pCodes, pFileContent, size);
|
||||||
delete[] pFileContent;
|
delete[] pFileContent;
|
||||||
|
|
||||||
CCScriptEngineManager::sharedScriptEngineManager()->getScriptEngine()->executeString(pCodes);
|
pEngine->executeString(pCodes);
|
||||||
delete []pCodes;
|
delete []pCodes;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (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");
|
string path = CCFileUtils::fullPathFromRelativePath("hello.lua");
|
||||||
CCScriptEngineManager::sharedScriptEngineManager()->getScriptEngine()->addSearchPath(path.substr(0, path.find_last_of("/")).c_str());
|
pEngine->addSearchPath(path.substr(0, path.find_last_of("/")).c_str());
|
||||||
CCScriptEngineManager::sharedScriptEngineManager()->getScriptEngine()->executeScriptFile(path.c_str());
|
pEngine->executeScriptFile(path.c_str());
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
#define _APP_DELEGATE_H_
|
#define _APP_DELEGATE_H_
|
||||||
|
|
||||||
#include "CCApplication.h"
|
#include "CCApplication.h"
|
||||||
#include "LuaEngine.h"
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@brief The cocos2d Application.
|
@brief The cocos2d Application.
|
||||||
|
@ -38,9 +37,6 @@ public:
|
||||||
@param the pointer of the application
|
@param the pointer of the application
|
||||||
*/
|
*/
|
||||||
virtual void applicationWillEnterForeground();
|
virtual void applicationWillEnterForeground();
|
||||||
|
|
||||||
private:
|
|
||||||
LuaEngine* m_pLuaEngine;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // _APP_DELEGATE_H_
|
#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
|
-- avoid memory leak
|
||||||
collectgarbage( "setpause", 100)
|
collectgarbage("setpause", 100)
|
||||||
collectgarbage( "setstepmul", 5000)
|
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()
|
||||||
|
|
||||||
|
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");
|
||||||
|
|
||||||
-- play background music
|
|
||||||
CocosDenshion.SimpleAudioEngine:sharedEngine():playBackgroundMusic("background.mp3", true);
|
|
||||||
-- preload effect
|
|
||||||
CocosDenshion.SimpleAudioEngine:sharedEngine():preloadEffect("effect1.wav");
|
|
||||||
-- run
|
-- run
|
||||||
cocos2d.CCDirector:sharedDirector():runWithScene(sceneGame)
|
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
|
// Draw string
|
||||||
FontMetricsInt fm = paint.getFontMetricsInt();
|
FontMetricsInt fm = paint.getFontMetricsInt();
|
||||||
int x = 0;
|
int x = 0;
|
||||||
int y = height == 0 ?(-fm.ascent):
|
int y = height == 0 ?(-fm.top):
|
||||||
(-fm.ascent + (height - textProperty.totalHeight)/2);
|
(-fm.top + (height - textProperty.totalHeight)/2);
|
||||||
String[] lines = textProperty.lines;
|
String[] lines = textProperty.lines;
|
||||||
for (String line : lines){
|
for (String line : lines){
|
||||||
x = computeX(paint, line, textProperty.maxWidth, alignment);
|
x = computeX(paint, line, textProperty.maxWidth, alignment);
|
||||||
|
@ -132,7 +132,7 @@ public class Cocos2dxBitmap{
|
||||||
private static TextProperty computeTextProperty(String content, Paint paint,
|
private static TextProperty computeTextProperty(String content, Paint paint,
|
||||||
int maxWidth, int maxHeight){
|
int maxWidth, int maxHeight){
|
||||||
FontMetricsInt fm = paint.getFontMetricsInt();
|
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;
|
int maxContentWidth = 0;
|
||||||
|
|
||||||
String[] lines = splitString(content, maxHeight, maxWidth, paint);
|
String[] lines = splitString(content, maxHeight, maxWidth, paint);
|
||||||
|
@ -165,7 +165,7 @@ public class Cocos2dxBitmap{
|
||||||
String[] lines = content.split("\\n");
|
String[] lines = content.split("\\n");
|
||||||
String[] ret = null;
|
String[] ret = null;
|
||||||
FontMetricsInt fm = paint.getFontMetricsInt();
|
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;
|
int maxLines = maxHeight / heightPerLine;
|
||||||
|
|
||||||
if (maxWidth != 0){
|
if (maxWidth != 0){
|
||||||
|
@ -236,7 +236,7 @@ public class Cocos2dxBitmap{
|
||||||
if (tempWidth >= width){
|
if (tempWidth >= width){
|
||||||
int lastIndexOfSpace = content.substring(0, i).lastIndexOf(" ");
|
int lastIndexOfSpace = content.substring(0, i).lastIndexOf(" ");
|
||||||
|
|
||||||
if (lastIndexOfSpace != -1){
|
if (lastIndexOfSpace != -1 && lastIndexOfSpace > start){
|
||||||
/**
|
/**
|
||||||
* Should wrap the word
|
* Should wrap the word
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -282,9 +282,10 @@ public class Cocos2dxGLSurfaceView extends GLSurfaceView {
|
||||||
|
|
||||||
switch (event.getAction() & MotionEvent.ACTION_MASK) {
|
switch (event.getAction() & MotionEvent.ACTION_MASK) {
|
||||||
case MotionEvent.ACTION_POINTER_DOWN:
|
case MotionEvent.ACTION_POINTER_DOWN:
|
||||||
final int idPointerDown = event.getAction() >> MotionEvent.ACTION_POINTER_ID_SHIFT;
|
final int indexPointerDown = event.getAction() >> MotionEvent.ACTION_POINTER_ID_SHIFT;
|
||||||
final float xPointerDown = event.getX(idPointerDown);
|
final int idPointerDown = event.getPointerId(indexPointerDown);
|
||||||
final float yPointerDown = event.getY(idPointerDown);
|
final float xPointerDown = event.getX(indexPointerDown);
|
||||||
|
final float yPointerDown = event.getY(indexPointerDown);
|
||||||
|
|
||||||
queueEvent(new Runnable() {
|
queueEvent(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -318,9 +319,10 @@ public class Cocos2dxGLSurfaceView extends GLSurfaceView {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MotionEvent.ACTION_POINTER_UP:
|
case MotionEvent.ACTION_POINTER_UP:
|
||||||
final int idPointerUp = event.getAction() >> MotionEvent.ACTION_POINTER_ID_SHIFT;
|
final int indexPointUp = event.getAction() >> MotionEvent.ACTION_POINTER_ID_SHIFT;
|
||||||
final float xPointerUp = event.getX(idPointerUp);
|
final int idPointerUp = event.getPointerId(indexPointUp);
|
||||||
final float yPointerUp = event.getY(idPointerUp);
|
final float xPointerUp = event.getX(indexPointUp);
|
||||||
|
final float yPointerUp = event.getY(indexPointUp);
|
||||||
|
|
||||||
queueEvent(new Runnable() {
|
queueEvent(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
da69ff183d2f96f95b8b1f8aec196130ba76a193
|
6f3595799e6b2dd55a7666a9a191c04093559b7f
|
|
@ -53,14 +53,13 @@
|
||||||
<listOptionValue builtIn="false" value="GLESv1_CM"/>
|
<listOptionValue builtIn="false" value="GLESv1_CM"/>
|
||||||
<listOptionValue builtIn="false" value="bps"/>
|
<listOptionValue builtIn="false" value="bps"/>
|
||||||
<listOptionValue builtIn="false" value="curl"/>
|
<listOptionValue builtIn="false" value="curl"/>
|
||||||
<listOptionValue builtIn="false" value="mmrndclient"/>
|
|
||||||
<listOptionValue builtIn="false" value="strm"/>
|
|
||||||
<listOptionValue builtIn="false" value="grskia"/>
|
<listOptionValue builtIn="false" value="grskia"/>
|
||||||
<listOptionValue builtIn="false" value="OpenAL"/>
|
<listOptionValue builtIn="false" value="OpenAL"/>
|
||||||
<listOptionValue builtIn="false" value="alut"/>
|
<listOptionValue builtIn="false" value="alut"/>
|
||||||
<listOptionValue builtIn="false" value="curl"/>
|
<listOptionValue builtIn="false" value="curl"/>
|
||||||
<listOptionValue builtIn="false" value="asound"/>
|
<listOptionValue builtIn="false" value="asound"/>
|
||||||
<listOptionValue builtIn="false" value="xml2"/>
|
<listOptionValue builtIn="false" value="xml2"/>
|
||||||
|
<listOptionValue builtIn="false" value="vorbis"/>
|
||||||
</option>
|
</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.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">
|
<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="GLESv1_CM"/>
|
||||||
<listOptionValue builtIn="false" value="bps"/>
|
<listOptionValue builtIn="false" value="bps"/>
|
||||||
<listOptionValue builtIn="false" value="curl"/>
|
<listOptionValue builtIn="false" value="curl"/>
|
||||||
<listOptionValue builtIn="false" value="mmrndclient"/>
|
|
||||||
<listOptionValue builtIn="false" value="strm"/>
|
|
||||||
<listOptionValue builtIn="false" value="grskia"/>
|
<listOptionValue builtIn="false" value="grskia"/>
|
||||||
<listOptionValue builtIn="false" value="OpenAL"/>
|
<listOptionValue builtIn="false" value="OpenAL"/>
|
||||||
<listOptionValue builtIn="false" value="alut"/>
|
<listOptionValue builtIn="false" value="alut"/>
|
||||||
<listOptionValue builtIn="false" value="curl"/>
|
<listOptionValue builtIn="false" value="curl"/>
|
||||||
<listOptionValue builtIn="false" value="asound"/>
|
<listOptionValue builtIn="false" value="asound"/>
|
||||||
<listOptionValue builtIn="false" value="xml2"/>
|
<listOptionValue builtIn="false" value="xml2"/>
|
||||||
|
<listOptionValue builtIn="false" value="vorbis"/>
|
||||||
</option>
|
</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.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"/>
|
<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="GLESv1_CM"/>
|
||||||
<listOptionValue builtIn="false" value="bps"/>
|
<listOptionValue builtIn="false" value="bps"/>
|
||||||
<listOptionValue builtIn="false" value="curl"/>
|
<listOptionValue builtIn="false" value="curl"/>
|
||||||
<listOptionValue builtIn="false" value="mmrndclient"/>
|
|
||||||
<listOptionValue builtIn="false" value="strm"/>
|
|
||||||
<listOptionValue builtIn="false" value="grskia"/>
|
<listOptionValue builtIn="false" value="grskia"/>
|
||||||
<listOptionValue builtIn="false" value="OpenAL"/>
|
<listOptionValue builtIn="false" value="OpenAL"/>
|
||||||
<listOptionValue builtIn="false" value="alut"/>
|
<listOptionValue builtIn="false" value="alut"/>
|
||||||
<listOptionValue builtIn="false" value="curl"/>
|
<listOptionValue builtIn="false" value="curl"/>
|
||||||
<listOptionValue builtIn="false" value="asound"/>
|
<listOptionValue builtIn="false" value="asound"/>
|
||||||
<listOptionValue builtIn="false" value="xml2"/>
|
<listOptionValue builtIn="false" value="xml2"/>
|
||||||
|
<listOptionValue builtIn="false" value="vorbis"/>
|
||||||
</option>
|
</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.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">
|
<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="GLESv1_CM"/>
|
||||||
<listOptionValue builtIn="false" value="bps"/>
|
<listOptionValue builtIn="false" value="bps"/>
|
||||||
<listOptionValue builtIn="false" value="curl"/>
|
<listOptionValue builtIn="false" value="curl"/>
|
||||||
<listOptionValue builtIn="false" value="mmrndclient"/>
|
|
||||||
<listOptionValue builtIn="false" value="strm"/>
|
|
||||||
<listOptionValue builtIn="false" value="grskia"/>
|
<listOptionValue builtIn="false" value="grskia"/>
|
||||||
<listOptionValue builtIn="false" value="OpenAL"/>
|
<listOptionValue builtIn="false" value="OpenAL"/>
|
||||||
<listOptionValue builtIn="false" value="alut"/>
|
<listOptionValue builtIn="false" value="alut"/>
|
||||||
<listOptionValue builtIn="false" value="curl"/>
|
<listOptionValue builtIn="false" value="curl"/>
|
||||||
<listOptionValue builtIn="false" value="asound"/>
|
<listOptionValue builtIn="false" value="asound"/>
|
||||||
<listOptionValue builtIn="false" value="xml2"/>
|
<listOptionValue builtIn="false" value="xml2"/>
|
||||||
|
<listOptionValue builtIn="false" value="vorbis"/>
|
||||||
</option>
|
</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.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">
|
<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="GLESv1_CM"/>
|
||||||
<listOptionValue builtIn="false" value="bps"/>
|
<listOptionValue builtIn="false" value="bps"/>
|
||||||
<listOptionValue builtIn="false" value="curl"/>
|
<listOptionValue builtIn="false" value="curl"/>
|
||||||
<listOptionValue builtIn="false" value="mmrndclient"/>
|
|
||||||
<listOptionValue builtIn="false" value="strm"/>
|
|
||||||
<listOptionValue builtIn="false" value="grskia"/>
|
<listOptionValue builtIn="false" value="grskia"/>
|
||||||
<listOptionValue builtIn="false" value="OpenAL"/>
|
<listOptionValue builtIn="false" value="OpenAL"/>
|
||||||
<listOptionValue builtIn="false" value="alut"/>
|
<listOptionValue builtIn="false" value="alut"/>
|
||||||
<listOptionValue builtIn="false" value="curl"/>
|
<listOptionValue builtIn="false" value="curl"/>
|
||||||
<listOptionValue builtIn="false" value="asound"/>
|
<listOptionValue builtIn="false" value="asound"/>
|
||||||
<listOptionValue builtIn="false" value="xml2"/>
|
<listOptionValue builtIn="false" value="xml2"/>
|
||||||
|
<listOptionValue builtIn="false" value="vorbis"/>
|
||||||
</option>
|
</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.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">
|
<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="GLESv1_CM"/>
|
||||||
<listOptionValue builtIn="false" value="bps"/>
|
<listOptionValue builtIn="false" value="bps"/>
|
||||||
<listOptionValue builtIn="false" value="curl"/>
|
<listOptionValue builtIn="false" value="curl"/>
|
||||||
<listOptionValue builtIn="false" value="mmrndclient"/>
|
|
||||||
<listOptionValue builtIn="false" value="strm"/>
|
|
||||||
<listOptionValue builtIn="false" value="grskia"/>
|
<listOptionValue builtIn="false" value="grskia"/>
|
||||||
<listOptionValue builtIn="false" value="OpenAL"/>
|
<listOptionValue builtIn="false" value="OpenAL"/>
|
||||||
<listOptionValue builtIn="false" value="alut"/>
|
<listOptionValue builtIn="false" value="alut"/>
|
||||||
<listOptionValue builtIn="false" value="curl"/>
|
<listOptionValue builtIn="false" value="curl"/>
|
||||||
<listOptionValue builtIn="false" value="asound"/>
|
<listOptionValue builtIn="false" value="asound"/>
|
||||||
<listOptionValue builtIn="false" value="xml2"/>
|
<listOptionValue builtIn="false" value="xml2"/>
|
||||||
|
<listOptionValue builtIn="false" value="vorbis"/>
|
||||||
</option>
|
</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.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">
|
<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="GLESv1_CM"/>
|
||||||
<listOptionValue builtIn="false" value="bps"/>
|
<listOptionValue builtIn="false" value="bps"/>
|
||||||
<listOptionValue builtIn="false" value="curl"/>
|
<listOptionValue builtIn="false" value="curl"/>
|
||||||
<listOptionValue builtIn="false" value="mmrndclient"/>
|
|
||||||
<listOptionValue builtIn="false" value="strm"/>
|
|
||||||
<listOptionValue builtIn="false" value="grskia"/>
|
<listOptionValue builtIn="false" value="grskia"/>
|
||||||
<listOptionValue builtIn="false" value="OpenAL"/>
|
<listOptionValue builtIn="false" value="OpenAL"/>
|
||||||
<listOptionValue builtIn="false" value="alut"/>
|
<listOptionValue builtIn="false" value="alut"/>
|
||||||
<listOptionValue builtIn="false" value="curl"/>
|
<listOptionValue builtIn="false" value="curl"/>
|
||||||
<listOptionValue builtIn="false" value="asound"/>
|
<listOptionValue builtIn="false" value="asound"/>
|
||||||
<listOptionValue builtIn="false" value="xml2"/>
|
<listOptionValue builtIn="false" value="xml2"/>
|
||||||
|
<listOptionValue builtIn="false" value="vorbis"/>
|
||||||
</option>
|
</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.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">
|
<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>
|
</scannerConfigBuildInfo>
|
||||||
</storageModule>
|
</storageModule>
|
||||||
<storageModule moduleId="com.qnx.tools.ide.qde.core.QNXProjectProperties"/>
|
<storageModule moduleId="com.qnx.tools.ide.qde.core.QNXProjectProperties"/>
|
||||||
<storageModule moduleId="refreshScope"/>
|
<storageModule moduleId="refreshScope" versionNumber="1">
|
||||||
|
<resource resourceType="PROJECT" workspacePath="/TestCocos2dx"/>
|
||||||
|
</storageModule>
|
||||||
</cproject>
|
</cproject>
|
||||||
|
|
|
@ -13,6 +13,8 @@
|
||||||
|
|
||||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
|
||||||
#define MUSIC_FILE "music.mid"
|
#define MUSIC_FILE "music.mid"
|
||||||
|
#elif (CC_TARGET_PLATFORM == CC_PLATFORM_QNX)
|
||||||
|
#define MUSIC_FILE "background.ogg"
|
||||||
#else
|
#else
|
||||||
#define MUSIC_FILE "background.mp3"
|
#define MUSIC_FILE "background.mp3"
|
||||||
#endif // CC_PLATFORM_WIN32
|
#endif // CC_PLATFORM_WIN32
|
||||||
|
|
|
@ -51,6 +51,8 @@ void UserDefaultTest::doTest()
|
||||||
CCLOG("bool is false");
|
CCLOG("bool is false");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//CCUserDefault::sharedUserDefault()->flush();
|
||||||
|
|
||||||
CCLOG("********************** after change value ***********************");
|
CCLOG("********************** after change value ***********************");
|
||||||
|
|
||||||
// change the value
|
// change the value
|
||||||
|
@ -61,6 +63,8 @@ void UserDefaultTest::doTest()
|
||||||
CCUserDefault::sharedUserDefault()->setDoubleForKey("double", 2.6);
|
CCUserDefault::sharedUserDefault()->setDoubleForKey("double", 2.6);
|
||||||
CCUserDefault::sharedUserDefault()->setBoolForKey("bool", false);
|
CCUserDefault::sharedUserDefault()->setBoolForKey("bool", false);
|
||||||
|
|
||||||
|
CCUserDefault::sharedUserDefault()->flush();
|
||||||
|
|
||||||
// print value
|
// print value
|
||||||
|
|
||||||
ret = CCUserDefault::sharedUserDefault()->getStringForKey("string");
|
ret = CCUserDefault::sharedUserDefault()->getStringForKey("string");
|
||||||
|
|
Loading…
Reference in New Issue