Merge branch 'develop' into issue4727

Conflicts:
	tools/cocos2d-console
This commit is contained in:
zhangbin 2014-04-15 15:18:00 +08:00
commit dd5c2aacd6
111 changed files with 1430 additions and 944 deletions

View File

@ -817,12 +817,16 @@ Developers:
iSevenDays
Fixed a bug that the result of 'malloc' is incompatible with type 'unsigned char *' in Image::saveImageToPNG
Fixed a potential memory leak in CCEditBoxImplIOS.mm
Fixed incompatible pointer conversion in external/chipmunk/src/cpArray.c
ololomax
Fixed a potential crash in SceneReader::createNodeWithSceneFile
gaoxiaosong
Fixed a warning in cpCollision.c
sachingarg05
Re-added orientation change callback in java activity
Retired Core Developers:
WenSheng Yang

View File

@ -1 +1 @@
3dec43835640892d3595d2063489624cf216dd73
f9627687e49dc44eace02e9648208c4cd1987246

View File

@ -76,7 +76,11 @@ ClippingNode::ClippingNode()
ClippingNode::~ClippingNode()
{
CC_SAFE_RELEASE(_stencil);
if (_stencil)
{
_stencil->stopAllActions();
_stencil->release();
}
}
ClippingNode* ClippingNode::create()
@ -291,9 +295,9 @@ Node* ClippingNode::getStencil() const
void ClippingNode::setStencil(Node *stencil)
{
CC_SAFE_RETAIN(stencil);
CC_SAFE_RELEASE(_stencil);
_stencil = stencil;
CC_SAFE_RETAIN(_stencil);
}
GLfloat ClippingNode::getAlphaThreshold() const

View File

@ -349,9 +349,9 @@ void EventDispatcher::removeEventListenersForTarget(Node* target, bool recursive
{
EventListener * listener = *iter;
if (listener->getSceneGraphPriority() == target)
if (listener->getAssociatedNode() == target)
{
listener->setSceneGraphPriority(nullptr); // Ensure no dangling ptr to the target node.
listener->setAssociatedNode(nullptr); // Ensure no dangling ptr to the target node.
listener->setRegistered(false);
listener->release();
iter = _toAddedListeners.erase(iter);
@ -446,7 +446,7 @@ void EventDispatcher::forceAddEventListener(EventListener* listener)
{
setDirty(listenerID, DirtyFlag::SCENE_GRAPH_PRIORITY);
auto node = listener->getSceneGraphPriority();
auto node = listener->getAssociatedNode();
CCASSERT(node != nullptr, "Invalid scene graph priority!");
associateNodeAndEventListener(node, listener);
@ -470,7 +470,7 @@ void EventDispatcher::addEventListenerWithSceneGraphPriority(EventListener* list
if (!listener->checkAvailable())
return;
listener->setSceneGraphPriority(node);
listener->setAssociatedNode(node);
listener->setFixedPriority(0);
listener->setRegistered(true);
@ -493,7 +493,7 @@ void EventDispatcher::debugCheckNodeHasNoEventListenersOnDestruction(Node* node)
for (EventListener * listener : *eventListenerVector->getSceneGraphPriorityListeners())
{
CCASSERT(!listener ||
listener->getSceneGraphPriority() != node,
listener->getAssociatedNode() != node,
"Node should have no event listeners registered for it upon destruction!");
}
}
@ -509,7 +509,7 @@ void EventDispatcher::debugCheckNodeHasNoEventListenersOnDestruction(Node* node)
{
for (EventListener * listener : *keyValuePair.second)
{
CCASSERT(listener->getSceneGraphPriority() != node,
CCASSERT(listener->getAssociatedNode() != node,
"Node should have no event listeners registered for it upon destruction!");
}
}
@ -525,7 +525,7 @@ void EventDispatcher::debugCheckNodeHasNoEventListenersOnDestruction(Node* node)
// Check the to be added list
for (EventListener * listener : _toAddedListeners)
{
CCASSERT(listener->getSceneGraphPriority() != node,
CCASSERT(listener->getAssociatedNode() != node,
"Node should have no event listeners registered for it upon destruction!");
}
@ -549,7 +549,7 @@ void EventDispatcher::addEventListenerWithFixedPriority(EventListener* listener,
if (!listener->checkAvailable())
return;
listener->setSceneGraphPriority(nullptr);
listener->setAssociatedNode(nullptr);
listener->setFixedPriority(fixedPriority);
listener->setRegistered(true);
listener->setPaused(false);
@ -582,10 +582,10 @@ void EventDispatcher::removeEventListener(EventListener* listener)
{
CC_SAFE_RETAIN(l);
l->setRegistered(false);
if (l->getSceneGraphPriority() != nullptr)
if (l->getAssociatedNode() != nullptr)
{
dissociateNodeAndEventListener(l->getSceneGraphPriority(), l);
l->setSceneGraphPriority(nullptr); // NULL out the node pointer so we don't have any dangling pointers to destroyed nodes.
dissociateNodeAndEventListener(l->getAssociatedNode(), l);
l->setAssociatedNode(nullptr); // NULL out the node pointer so we don't have any dangling pointers to destroyed nodes.
}
if (_inDispatch == 0)
@ -681,7 +681,7 @@ void EventDispatcher::setPriority(EventListener* listener, int fixedPriority)
auto found = std::find(fixedPriorityListeners->begin(), fixedPriorityListeners->end(), listener);
if (found != fixedPriorityListeners->end())
{
CCASSERT(listener->getSceneGraphPriority() == nullptr, "Can't set fixed priority with scene graph based listener.");
CCASSERT(listener->getAssociatedNode() == nullptr, "Can't set fixed priority with scene graph based listener.");
if (listener->getFixedPriority() != fixedPriority)
{
@ -782,7 +782,7 @@ void EventDispatcher::dispatchEvent(Event* event)
auto listeners = iter->second;
auto onEvent = [&event](EventListener* listener) -> bool{
event->setCurrentTarget(listener->getSceneGraphPriority());
event->setCurrentTarget(listener->getAssociatedNode());
listener->_onEvent(event);
return event->isStopped();
};
@ -1168,7 +1168,7 @@ void EventDispatcher::sortEventListenersOfSceneGraphPriority(const EventListener
// After sort: priority < 0, > 0
std::sort(sceneGraphListeners->begin(), sceneGraphListeners->end(), [this](const EventListener* l1, const EventListener* l2) {
return _nodePriorityMap[l1->getSceneGraphPriority()] > _nodePriorityMap[l2->getSceneGraphPriority()];
return _nodePriorityMap[l1->getAssociatedNode()] > _nodePriorityMap[l2->getAssociatedNode()];
});
#if DUMP_LISTENER_ITEM_PRIORITY_INFO
@ -1245,10 +1245,10 @@ void EventDispatcher::removeEventListenersForListenerID(const EventListener::Lis
{
auto l = *iter;
l->setRegistered(false);
if (l->getSceneGraphPriority() != nullptr)
if (l->getAssociatedNode() != nullptr)
{
dissociateNodeAndEventListener(l->getSceneGraphPriority(), l);
l->setSceneGraphPriority(nullptr); // NULL out the node pointer so we don't have any dangling pointers to destroyed nodes.
dissociateNodeAndEventListener(l->getAssociatedNode(), l);
l->setAssociatedNode(nullptr); // NULL out the node pointer so we don't have any dangling pointers to destroyed nodes.
}
if (_inDispatch == 0)

View File

@ -128,13 +128,13 @@ protected:
*/
inline int getFixedPriority() const { return _fixedPriority; };
/** Sets scene graph priority for this listener */
inline void setSceneGraphPriority(Node* node) { _node = node; };
/** Sets the node associated with this listener */
inline void setAssociatedNode(Node* node) { _node = node; };
/** Gets scene graph priority of this listener
* @return nullptr if it's a fixed priority listener, non-nullptr for scene graph priority listener
/** Gets the node associated with this listener
* @return nullptr if it's a fixed priority listener, otherwise return non-nullptr
*/
inline Node* getSceneGraphPriority() const { return _node; };
inline Node* getAssociatedNode() const { return _node; };
///////////////
// Properties

View File

@ -258,6 +258,7 @@ Label::Label(FontAtlas *atlas /* = nullptr */, TextHAlignment hAlignment /* = Te
, _textSprite(nullptr)
, _contentDirty(false)
, _shadowDirty(false)
, _compatibleMode(false)
{
setAnchorPoint(Point::ANCHOR_MIDDLE);
reset();
@ -943,6 +944,7 @@ void Label::setFontDefinition(const FontDefinition& textDefinition)
_fontDefinition._shadow._shadowEnabled = false;
enableShadow(Color4B(0,0,0,255 * _fontDefinition._shadow._shadowOpacity),_fontDefinition._shadow._shadowOffset,_fontDefinition._shadow._shadowBlur);
}
_compatibleMode = true;
}
void Label::updateContent()
@ -968,41 +970,44 @@ void Label::updateContent()
}
else
{
_fontDefinition._fontName = _systemFont;
_fontDefinition._fontSize = _systemFontSize;
_fontDefinition._alignment = _hAlignment;
_fontDefinition._vertAlignment = _vAlignment;
_fontDefinition._dimensions.width = _labelWidth;
_fontDefinition._dimensions.height = _labelHeight;
_fontDefinition._fontFillColor.r = _textColor.r;
_fontDefinition._fontFillColor.g = _textColor.g;
_fontDefinition._fontFillColor.b = _textColor.b;
_fontDefinition._shadow._shadowEnabled = false;
if (_currLabelEffect == LabelEffect::OUTLINE && _outlineSize > 0)
if (!_compatibleMode)
{
_fontDefinition._stroke._strokeEnabled = true;
_fontDefinition._stroke._strokeSize = _outlineSize;
_fontDefinition._stroke._strokeColor.r = _effectColor.r;
_fontDefinition._stroke._strokeColor.g = _effectColor.g;
_fontDefinition._stroke._strokeColor.b = _effectColor.b;
}
else
{
_fontDefinition._stroke._strokeEnabled = false;
}
_fontDefinition._fontName = _systemFont;
_fontDefinition._fontSize = _systemFontSize;
_fontDefinition._alignment = _hAlignment;
_fontDefinition._vertAlignment = _vAlignment;
_fontDefinition._dimensions.width = _labelWidth;
_fontDefinition._dimensions.height = _labelHeight;
_fontDefinition._fontFillColor.r = _textColor.r;
_fontDefinition._fontFillColor.g = _textColor.g;
_fontDefinition._fontFillColor.b = _textColor.b;
_fontDefinition._shadow._shadowEnabled = false;
if (_currLabelEffect == LabelEffect::OUTLINE && _outlineSize > 0)
{
_fontDefinition._stroke._strokeEnabled = true;
_fontDefinition._stroke._strokeSize = _outlineSize;
_fontDefinition._stroke._strokeColor.r = _effectColor.r;
_fontDefinition._stroke._strokeColor.g = _effectColor.g;
_fontDefinition._stroke._strokeColor.b = _effectColor.b;
}
else
{
_fontDefinition._stroke._strokeEnabled = false;
}
#if (CC_TARGET_PLATFORM != CC_PLATFORM_ANDROID) && (CC_TARGET_PLATFORM != CC_PLATFORM_IOS)
if (_fontDefinition._stroke._strokeEnabled)
{
CCLOGERROR("Currently only supported on iOS and Android!");
}
_fontDefinition._stroke._strokeEnabled = false;
if (_fontDefinition._stroke._strokeEnabled)
{
CCLOGERROR("Currently only supported on iOS and Android!");
}
_fontDefinition._stroke._strokeEnabled = false;
#endif
}
createSpriteWithFontDefinition();
}

View File

@ -325,6 +325,7 @@ protected:
//compatibility with older LabelTTF
Sprite* _textSprite;
FontDefinition _fontDefinition;
bool _compatibleMode;
//! used for optimization
Sprite *_reusedLetter;

View File

@ -589,7 +589,7 @@ void Sprite::updateTransform(void)
void Sprite::draw(Renderer *renderer, const kmMat4 &transform, bool transformUpdated)
{
// Don't do calculate the culling if the transform was not updated
_insideBounds = transformUpdated ? isInsideBounds() : _insideBounds;
_insideBounds = transformUpdated ? renderer->checkVisibility(transform, _contentSize) : _insideBounds;
if(_insideBounds)
{
@ -621,35 +621,6 @@ void Sprite::drawDebugData()
}
#endif //CC_SPRITE_DEBUG_DRAW
// Culling function from cocos2d-iphone CCSprite.m file
bool Sprite::isInsideBounds() const
{
// half size of the screen
Size screen_half = Director::getInstance()->getWinSize();
screen_half.width /= 2;
screen_half.height /= 2;
float hcsx = _contentSize.width / 2;
float hcsy = _contentSize.height / 2;
// convert to world coordinates
float x = hcsx * _modelViewTransform.mat[0] + hcsy * _modelViewTransform.mat[4] + _modelViewTransform.mat[12];
float y = hcsx * _modelViewTransform.mat[1] + hcsy * _modelViewTransform.mat[5] + _modelViewTransform.mat[13];
// center of screen is (0,0)
x -= screen_half.width;
y -= screen_half.height;
// convert content size to world coordinates
float wchw = hcsx * std::max(fabsf(_modelViewTransform.mat[0] + _modelViewTransform.mat[4]), fabsf(_modelViewTransform.mat[0] - _modelViewTransform.mat[4]));
float wchh = hcsy * std::max(fabsf(_modelViewTransform.mat[1] + _modelViewTransform.mat[5]), fabsf(_modelViewTransform.mat[1] - _modelViewTransform.mat[5]));
// compare if it in the positive quadrant of the screen
float tmpx = (fabsf(x)-wchw);
float tmpy = (fabsf(y)-wchh);
return (tmpx < screen_half.width && tmpy < screen_half.height);
}
// Node overrides
void Sprite::addChild(Node *child, int zOrder, int tag)
{

View File

@ -527,8 +527,6 @@ protected:
virtual void setReorderChildDirtyRecursively(void);
virtual void setDirtyRecursively(bool bValue);
bool isInsideBounds() const;
//
// Data used when the sprite is rendered using a SpriteSheet
//
@ -574,7 +572,6 @@ protected:
bool _flippedY; /// Whether the sprite is flipped vertically or not
bool _insideBounds; /// whether or not the sprite was inside bounds the previous frame
private:
CC_DISALLOW_COPY_AND_ASSIGN(Sprite);
};

View File

@ -93,7 +93,7 @@ std::string TextureCache::getDescription() const
return StringUtils::format("<TextureCache | Number of textures = %d>", static_cast<int>(_textures.size()));
}
void TextureCache::addImageAsync(const std::string &path, std::function<void(Texture2D*)> callback)
void TextureCache::addImageAsync(const std::string &path, const std::function<void(Texture2D*)>& callback)
{
Texture2D *texture = nullptr;

View File

@ -117,7 +117,7 @@ public:
* Supported image extensions: .png, .jpg
* @since v0.8
*/
virtual void addImageAsync(const std::string &filepath, std::function<void(Texture2D*)> callback);
virtual void addImageAsync(const std::string &filepath, const std::function<void(Texture2D*)>& callback);
/** Returns a Texture2D object given an Image.
* If the image was not previously loaded, it will create a new Texture2D object and it will return it.

View File

@ -31,7 +31,7 @@ NS_CC_BEGIN
const char* cocos2dVersion()
{
return "3.0";
return "3.0-rc2";
}
NS_CC_END

View File

@ -75,6 +75,7 @@ public class Cocos2dxRenderer implements GLSurfaceView.Renderer {
@Override
public void onSurfaceChanged(final GL10 pGL10, final int pWidth, final int pHeight) {
Cocos2dxRenderer.nativeOnSurfaceChanged(pWidth, pHeight);
}
@Override
@ -118,6 +119,7 @@ public class Cocos2dxRenderer implements GLSurfaceView.Renderer {
private static native boolean nativeKeyDown(final int pKeyCode);
private static native void nativeRender();
private static native void nativeInit(final int pWidth, final int pHeight);
private static native void nativeOnSurfaceChanged(final int pWidth, final int pHeight);
private static native void nativeOnPause();
private static native void nativeOnResume();

View File

@ -79,4 +79,10 @@ void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thi
}
void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeOnSurfaceChanged(JNIEnv* env, jobject thiz, jint w, jint h)
{
cocos2d::Application::getInstance()->applicationScreenSizeChanged(w, h);
}
}

View File

@ -29,20 +29,6 @@
NS_CC_BEGIN
static GroupCommandManager* s_instance;
GroupCommandManager *GroupCommandManager::getInstance()
{
if(!s_instance)
{
s_instance = new GroupCommandManager();
if(!s_instance->init())
{
CC_SAFE_DELETE(s_instance);
}
}
return s_instance;
}
GroupCommandManager::GroupCommandManager()
{
@ -50,7 +36,7 @@ GroupCommandManager::GroupCommandManager()
GroupCommandManager::~GroupCommandManager()
{
CC_SAFE_RELEASE_NULL(s_instance);
}
bool GroupCommandManager::init()
@ -88,19 +74,20 @@ void GroupCommandManager::releaseGroupID(int groupID)
GroupCommand::GroupCommand()
{
_type = RenderCommand::Type::GROUP_COMMAND;
_renderQueueID = GroupCommandManager::getInstance()->getGroupID();
_renderQueueID = Director::getInstance()->getRenderer()->getGroupCommandManager()->getGroupID();
}
void GroupCommand::init(float globalOrder)
{
_globalOrder = globalOrder;
GroupCommandManager::getInstance()->releaseGroupID(_renderQueueID);
_renderQueueID = GroupCommandManager::getInstance()->getGroupID();
auto manager = Director::getInstance()->getRenderer()->getGroupCommandManager();
manager->releaseGroupID(_renderQueueID);
_renderQueueID = manager->getGroupID();
}
GroupCommand::~GroupCommand()
{
GroupCommandManager::getInstance()->releaseGroupID(_renderQueueID);
Director::getInstance()->getRenderer()->getGroupCommandManager()->releaseGroupID(_renderQueueID);
}
NS_CC_END

View File

@ -37,17 +37,14 @@ NS_CC_BEGIN
class GroupCommandManager : public Ref
{
public:
static GroupCommandManager* getInstance();
~GroupCommandManager();
bool init();
int getGroupID();
void releaseGroupID(int groupID);
protected:
friend class Renderer;
GroupCommandManager();
~GroupCommandManager();
bool init();
std::unordered_map<int, bool> _groupMapping;
};

View File

@ -23,6 +23,9 @@
****************************************************************************/
#include "renderer/CCRenderer.h"
#include <algorithm>
#include "renderer/CCQuadCommand.h"
#include "renderer/CCBatchCommand.h"
#include "renderer/CCCustomCommand.h"
@ -34,15 +37,19 @@
#include "CCEventDispatcher.h"
#include "CCEventListenerCustom.h"
#include "CCEventType.h"
#include <algorithm>
#include "kazmath/kazmath.h"
NS_CC_BEGIN
// helper
bool compareRenderCommand(RenderCommand* a, RenderCommand* b)
{
return a->getGlobalOrder() < b->getGlobalOrder();
}
// queue
void RenderQueue::push_back(RenderCommand* command)
{
float z = command->getGlobalOrder();
@ -92,20 +99,25 @@ void RenderQueue::clear()
_queuePosZ.clear();
}
//
//
//
static const int DEFAULT_RENDER_QUEUE = 0;
//
// constructors, destructors, init
//
//
#define DEFAULT_RENDER_QUEUE 0
Renderer::Renderer()
:_lastMaterialID(0)
,_numQuads(0)
,_glViewAssigned(false)
,_isRendering(false)
#if CC_ENABLE_CACHE_TEXTURE_DATA
,_cacheTextureListener(nullptr)
#endif
{
_groupCommandManager = new GroupCommandManager();
_commandGroupStack.push(DEFAULT_RENDER_QUEUE);
RenderQueue defaultRenderQueue;
@ -116,6 +128,7 @@ Renderer::Renderer()
Renderer::~Renderer()
{
_renderGroups.clear();
_groupCommandManager->release();
glDeleteBuffers(2, _buffersVBO);
@ -236,6 +249,7 @@ void Renderer::addCommand(RenderCommand* command)
void Renderer::addCommand(RenderCommand* command, int renderQueue)
{
CCASSERT(!_isRendering, "Cannot add command while rendering");
CCASSERT(renderQueue >=0, "Invalid render queue");
CCASSERT(command->getType() != RenderCommand::Type::UNKNOWN_COMMAND, "Invalid Command Type");
_renderGroups[renderQueue].push_back(command);
@ -243,11 +257,13 @@ void Renderer::addCommand(RenderCommand* command, int renderQueue)
void Renderer::pushGroup(int renderQueueID)
{
CCASSERT(!_isRendering, "Cannot change render queue while rendering");
_commandGroupStack.push(renderQueueID);
}
void Renderer::popGroup()
{
CCASSERT(!_isRendering, "Cannot change render queue while rendering");
_commandGroupStack.pop();
}
@ -261,7 +277,8 @@ int Renderer::createRenderQueue()
void Renderer::visitRenderQueue(const RenderQueue& queue)
{
ssize_t size = queue.size();
for (auto index = 0; index < size; ++index)
for (ssize_t index = 0; index < size; ++index)
{
auto command = queue[index];
auto commandType = command->getType();
@ -316,7 +333,8 @@ void Renderer::render()
//glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//TODO setup camera or MVP
_isRendering = true;
if (_glViewAssigned)
{
// cleanup
@ -332,6 +350,7 @@ void Renderer::render()
flush();
}
clean();
_isRendering = false;
}
void Renderer::clean()
@ -487,4 +506,36 @@ void Renderer::flush()
_lastMaterialID = 0;
}
// helpers
bool Renderer::checkVisibility(const kmMat4 &transform, const Size &size)
{
// half size of the screen
Size screen_half = Director::getInstance()->getWinSize();
screen_half.width /= 2;
screen_half.height /= 2;
float hSizeX = size.width/2;
float hSizeY = size.height/2;
kmVec4 v4world, v4local;
kmVec4Fill(&v4local, hSizeX, hSizeY, 0, 1);
kmVec4MultiplyMat4(&v4world, &v4local, &transform);
// center of screen is (0,0)
v4world.x -= screen_half.width;
v4world.y -= screen_half.height;
// convert content size to world coordinates
float wshw = std::max(fabsf(hSizeX * transform.mat[0] + hSizeY * transform.mat[4]), fabsf(hSizeX * transform.mat[0] - hSizeY * transform.mat[4]));
float wshh = std::max(fabsf(hSizeX * transform.mat[1] + hSizeY * transform.mat[5]), fabsf(hSizeX * transform.mat[1] - hSizeY * transform.mat[5]));
// compare if it in the positive quadrant of the screen
float tmpx = (fabsf(v4world.x)-wshw);
float tmpy = (fabsf(v4world.y)-wshh);
bool ret = (tmpx < screen_half.width && tmpy < screen_half.height);
return ret;
}
NS_CC_END

View File

@ -64,6 +64,8 @@ struct RenderStackElement
ssize_t currentIndex;
};
class GroupCommandManager;
/* Class responsible for the rendering in.
Whenever possible prefer to use `QuadCommand` objects since the renderer will automatically batch them.
@ -110,6 +112,11 @@ public:
/* RenderCommands (except) QuadCommand should update this value */
void addDrawnVertices(ssize_t number) { _drawnVertices += number; };
inline GroupCommandManager* getGroupCommandManager() const { return _groupCommandManager; };
/** returns whether or not a rectangle is visible or not */
bool checkVisibility(const kmMat4& transform, const Size& size);
protected:
void setupIndices();
@ -148,6 +155,10 @@ protected:
// stats
ssize_t _drawnBatches;
ssize_t _drawnVertices;
//the flag for checking whether renderer is rendering
bool _isRendering;
GroupCommandManager* _groupCommandManager;
#if CC_ENABLE_CACHE_TEXTURE_DATA
EventListenerCustom* _cacheTextureListener;

View File

@ -203,8 +203,10 @@ void Audio::StopBackgroundMusic(bool bReleaseData)
StopSoundEffect(m_backgroundID);
if (bReleaseData)
if (bReleaseData){
UnloadSoundEffect(m_backgroundID);
RemoveFromList(m_backgroundID);
}
}
void Audio::PauseBackgroundMusic()
@ -406,7 +408,8 @@ void Audio::PauseAllSoundEffects()
EffectList::iterator iter;
for (iter = m_soundEffects.begin(); iter != m_soundEffects.end(); iter++)
{
PauseSoundEffect(iter->first);
if (iter->first != m_backgroundID)
PauseSoundEffect(iter->first);
}
}
@ -419,11 +422,12 @@ void Audio::ResumeAllSoundEffects()
EffectList::iterator iter;
for (iter = m_soundEffects.begin(); iter != m_soundEffects.end(); iter++)
{
ResumeSoundEffect(iter->first);
if (iter->first != m_backgroundID)
ResumeSoundEffect(iter->first);
}
}
void Audio::StopAllSoundEffects()
void Audio::StopAllSoundEffects(bool bReleaseData)
{
if (m_engineExperiencedCriticalError) {
return;
@ -432,8 +436,27 @@ void Audio::StopAllSoundEffects()
EffectList::iterator iter;
for (iter = m_soundEffects.begin(); iter != m_soundEffects.end(); iter++)
{
StopSoundEffect(iter->first);
if (iter->first != m_backgroundID){
StopSoundEffect(iter->first);
if (bReleaseData)
{
UnloadSoundEffect(iter->first);
}
}
}
if (bReleaseData)
{
for (iter = m_soundEffects.begin(); iter != m_soundEffects.end();)
{
if (iter->first != m_backgroundID){
m_soundEffects.erase(iter++);
}
else
{
iter++;
}
}
}
}
bool Audio::IsSoundEffectStarted(unsigned int sound)
@ -556,6 +579,8 @@ void Audio::UnloadSoundEffect(const char* pszFilePath)
int sound = Hash(pszFilePath);
UnloadSoundEffect(sound);
RemoveFromList(sound);
}
void Audio::UnloadSoundEffect(unsigned int sound)
@ -575,7 +600,12 @@ void Audio::UnloadSoundEffect(unsigned int sound)
m_soundEffects[sound].m_soundEffectBufferData = nullptr;
m_soundEffects[sound].m_soundEffectSourceVoice = nullptr;
m_soundEffects[sound].m_soundEffectStarted = false;
ZeroMemory(&m_soundEffects[sound].m_audioBuffer, sizeof(m_soundEffects[sound].m_audioBuffer));
ZeroMemory(&m_soundEffects[sound].m_audioBuffer, sizeof(m_soundEffects[sound].m_audioBuffer));
}
void Audio::RemoveFromList( unsigned int sound )
{
m_soundEffects.erase(sound);
}

View File

@ -156,9 +156,12 @@ public:
void PauseAllSoundEffects();
void ResumeAllSoundEffects();
void StopAllSoundEffects();
void StopAllSoundEffects(bool bReleaseData);
void PreloadSoundEffect(const char* pszFilePath, bool isMusic = false);
void UnloadSoundEffect(const char* pszFilePath);
void UnloadSoundEffect(unsigned int sound);
private:
void RemoveFromList(unsigned int sound);
};

View File

@ -63,7 +63,7 @@ SimpleAudioEngine::~SimpleAudioEngine()
void SimpleAudioEngine::end()
{
sharedAudioController()->StopBackgroundMusic(true);
sharedAudioController()->StopAllSoundEffects();
sharedAudioController()->StopAllSoundEffects(true);
sharedAudioController()->ReleaseResources();
s_initialized = false;
}
@ -158,7 +158,7 @@ void SimpleAudioEngine::resumeAllEffects()
void SimpleAudioEngine::stopAllEffects()
{
sharedAudioController()->StopAllSoundEffects();
sharedAudioController()->StopAllSoundEffects(false);
}
void SimpleAudioEngine::preloadBackgroundMusic(const char* pszFilePath)

View File

@ -38,7 +38,7 @@
#if defined(_MSC_VER) || defined(__MINGW32__)
#include <io.h>
#include <WS2tcpip.h>
#include <Winsock2.h>
#define bzero(a, b) memset(a, 0, b);
#else
@ -463,7 +463,7 @@ void Console::commandFileUtils(int fd, const std::string &args)
void Console::commandConfig(int fd, const std::string& args)
{
Scheduler *sched = Director::getInstance()->getScheduler();
sched->performFunctionInCocosThread( [&](){
sched->performFunctionInCocosThread( [=](){
mydprintf(fd, "%s", Configuration::getInstance()->getInfo().c_str());
sendPrompt(fd);
}
@ -504,7 +504,7 @@ void Console::commandResolution(int fd, const std::string& args)
stream >> width >> height>> policy;
Scheduler *sched = Director::getInstance()->getScheduler();
sched->performFunctionInCocosThread( [&](){
sched->performFunctionInCocosThread( [=](){
Director::getInstance()->getOpenGLView()->setDesignResolutionSize(width, height, static_cast<ResolutionPolicy>(policy));
} );
}
@ -538,13 +538,13 @@ void Console::commandProjection(int fd, const std::string& args)
}
else if( args.compare("2d") == 0)
{
sched->performFunctionInCocosThread( [&](){
sched->performFunctionInCocosThread( [=](){
director->setProjection(Director::Projection::_2D);
} );
}
else if( args.compare("3d") == 0)
{
sched->performFunctionInCocosThread( [&](){
sched->performFunctionInCocosThread( [=](){
director->setProjection(Director::Projection::_3D);
} );
}
@ -560,14 +560,14 @@ void Console::commandTextures(int fd, const std::string& args)
if( args.compare("flush")== 0)
{
sched->performFunctionInCocosThread( [&](){
sched->performFunctionInCocosThread( [](){
Director::getInstance()->getTextureCache()->removeAllTextures();
}
);
}
else if(args.length()==0)
{
sched->performFunctionInCocosThread( [&](){
sched->performFunctionInCocosThread( [=](){
mydprintf(fd, "%s", Director::getInstance()->getTextureCache()->getCachedTextureInfo().c_str());
sendPrompt(fd);
}
@ -596,7 +596,7 @@ void Console::commandDirector(int fd, const std::string& args)
else if(args == "pause")
{
Scheduler *sched = director->getScheduler();
sched->performFunctionInCocosThread( [&](){
sched->performFunctionInCocosThread( [](){
Director::getInstance()->pause();
}
);
@ -609,7 +609,7 @@ void Console::commandDirector(int fd, const std::string& args)
else if(args == "stop")
{
Scheduler *sched = director->getScheduler();
sched->performFunctionInCocosThread( [&](){
sched->performFunctionInCocosThread( [](){
Director::getInstance()->stopAnimation();
}
);
@ -1063,15 +1063,20 @@ void Console::loop()
//On linux, if you send data to a closed socket, the sending process will
//receive a SIGPIPE, which will cause linux system shutdown the sending process.
//Add this ioctl code to check if the socket has been closed by peer.
#if (CC_TARGET_PLATFORM == CC_PLATFORM_LINUX)
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
u_long n = 0;
ioctlsocket(fd, FIONREAD, &n);
#else
int n = 0;
ioctl(fd, FIONREAD, &n);
#endif
if(n == 0)
{
//no data received, or fd is closed
continue;
}
#endif
if( ! parseCommand(fd) )
{
to_remove.push_back(fd);

View File

@ -40,7 +40,9 @@ THE SOFTWARE.
#define IMPLEMENT_CLASS_INFO(className) \
cocos2d::Ref* className::createInstance(void) \
{ \
return new className; \
auto ret = new className; \
ret->autorelease(); \
return ret; \
} \
cocostudio::ObjectFactory::TInfo className::Type(#className, &className::createInstance); \

View File

@ -28,6 +28,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "vec2.h"
#include "vec3.h"
#include "vec4.h"
#include "mat3.h"
#include "mat4.h"
#include "utility.h"

View File

@ -31,6 +31,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "vec4.h"
#include "mat4.h"
#include "neon_matrix_impl.h"
kmVec4* kmVec4Fill(kmVec4* pOut, kmScalar x, kmScalar y, kmScalar z, kmScalar w)
{
@ -137,10 +138,14 @@ kmVec4* kmVec4Div( kmVec4* pOut,const kmVec4* pV1, const kmVec4* pV2 ) {
/// Multiplies a 4D vector by a matrix, the result is stored in pOut, and pOut is returned.
kmVec4* kmVec4MultiplyMat4(kmVec4* pOut, const kmVec4* pV, const struct kmMat4* pM) {
#if defined(__ARM_NEON__) && !defined(__arm64__)
NEON_Matrix4Vector4Mul(&pM->mat[0], (const float*)pV, (float*)pOut);
#else
pOut->x = pV->x * pM->mat[0] + pV->y * pM->mat[4] + pV->z * pM->mat[8] + pV->w * pM->mat[12];
pOut->y = pV->x * pM->mat[1] + pV->y * pM->mat[5] + pV->z * pM->mat[9] + pV->w * pM->mat[13];
pOut->z = pV->x * pM->mat[2] + pV->y * pM->mat[6] + pV->z * pM->mat[10] + pV->w * pM->mat[14];
pOut->w = pV->x * pM->mat[3] + pV->y * pM->mat[7] + pV->z * pM->mat[11] + pV->w * pM->mat[15];
#endif
return pOut;
}

View File

@ -1 +1 @@
9f759dc3875d5cbbe9b00da054338f2bde85efa0
5c9b46709a646c59f7dda47fd5d3f2302f1145fb

View File

@ -1 +1 @@
fe27a3bee5f56dc93ee7ae540adb0d88245d8072
9ad446c3528688b8df8fe36f8d72cec5eb49789d

View File

@ -304,7 +304,7 @@ void ProtectedNode::visit(Renderer* renderer, const kmMat4 &parentTransform, boo
{
auto node = _children.at(i);
if ( node && node->getZOrder() < 0 )
if ( node && node->getLocalZOrder() < 0 )
node->visit(renderer, _modelViewTransform, dirty);
else
break;
@ -314,7 +314,7 @@ void ProtectedNode::visit(Renderer* renderer, const kmMat4 &parentTransform, boo
{
auto node = _protectedChildren.at(j);
if ( node && node->getZOrder() < 0 )
if ( node && node->getLocalZOrder() < 0 )
node->visit(renderer, _modelViewTransform, dirty);
else
break;

View File

@ -790,7 +790,7 @@ void Layout::stencilClippingVisit(Renderer *renderer, const kmMat4 &parentTransf
{
auto node = _children.at(i);
if ( node && node->getZOrder() < 0 )
if ( node && node->getLocalZOrder() < 0 )
node->visit(renderer, _modelViewTransform, dirty);
else
break;
@ -800,7 +800,7 @@ void Layout::stencilClippingVisit(Renderer *renderer, const kmMat4 &parentTransf
{
auto node = _protectedChildren.at(j);
if ( node && node->getZOrder() < 0 )
if ( node && node->getLocalZOrder() < 0 )
node->visit(renderer, _modelViewTransform, dirty);
else
break;

View File

@ -52,7 +52,7 @@ cpArrayPush(cpArray *arr, void *object)
{
if(arr->num == arr->max){
arr->max *= 2;
arr->arr = (void **)cprealloc(arr->arr, arr->max*sizeof(void**));
arr->arr = (void **)cprealloc(arr->arr, arr->max*sizeof(void*));
}
arr->arr[arr->num] = object;

View File

@ -60,6 +60,14 @@ NDK_ROOT = 'NDK_ROOT'
ANDROID_SDK_ROOT = 'ANDROID_SDK_ROOT'
ANT_ROOT = 'ANT_ROOT'
def _check_python_version():
major_ver = sys.version_info[0]
if major_ver > 2:
print ("The python version is %d.%d. But python 2.x is required. (Version 2.7 is well tested)\n"
"Download it here: https://www.python.org/" % (major_ver, sys.version_info[1]))
return False
return True
class SetEnvVar(object):
@ -168,7 +176,7 @@ class SetEnvVar(object):
def _set_environment_variable(self, key, value):
print " -> Add %s environment variable..." % key
print(" -> Add %s environment variable..." % key)
ret = False
if self._isWindows():
ret = self._set_environment_variable_win32(key, value)
@ -176,9 +184,9 @@ class SetEnvVar(object):
ret = self._set_environment_variable_unix(key, value)
if ret:
print " ->Added %s=%s\n" % (key, value)
print(" ->Added %s=%s\n" % (key, value))
else:
print " ->Add failed\n"
print(" ->Add failed\n")
return ret
@ -199,7 +207,7 @@ class SetEnvVar(object):
return ret
def _find_environment_variable(self, var):
print " ->Find environment variable %s..." % var
print(" ->Find environment variable %s..." % var)
ret = None
try:
ret = os.environ[var]
@ -227,7 +235,7 @@ class SetEnvVar(object):
0,
_winreg.KEY_READ)
ret = _winreg.QueryValueEx(env, var)
ret = _winreg.QueryValueEx(env, var)[0]
_winreg.CloseKey(env)
except Exception:
if env:
@ -235,9 +243,9 @@ class SetEnvVar(object):
ret = None
if ret is None:
print " ->%s not found\n" % var
print(" ->%s not found\n" % var)
else:
print " ->%s is found : %s\n" % (var, ret)
print(" ->%s is found : %s\n" % (var, ret))
return ret
@ -320,7 +328,7 @@ class SetEnvVar(object):
ret = False
if not ret:
print ' ->Error: "%s" is not a valid path of %s. Ignoring it.' % (value, var_name)
print(' ->Error: "%s" is not a valid path of %s. Ignoring it.' % (value, var_name))
return ret
@ -384,9 +392,9 @@ class SetEnvVar(object):
_winreg.FlushKey(env)
_winreg.CloseKey(env)
print ' ->Remove directory \"%s\" from PATH!\n' % remove_dir
print(' ->Remove directory \"%s\" from PATH!\n' % remove_dir)
except Exception:
print ' ->Remove directory \"%s\" from PATH failed!\n' % remove_dir
print(' ->Remove directory \"%s\" from PATH failed!\n' % remove_dir)
def set_windows_path(self, add_dir):
ret = False
@ -425,13 +433,13 @@ class SetEnvVar(object):
_winreg.CloseKey(env)
if ret:
print " ->Add directory \"%s\" into PATH succeed!\n" % add_dir
print(" ->Add directory \"%s\" into PATH succeed!\n" % add_dir)
else:
print " ->Add directory \"%s\" into PATH failed!\n" % add_dir
print(" ->Add directory \"%s\" into PATH failed!\n" % add_dir)
def set_console_root(self):
print "->Check environment variable %s" % COCOS_CONSOLE_ROOT
print("->Check environment variable %s" % COCOS_CONSOLE_ROOT)
cocos_consle_root = os.path.join(self.current_absolute_path, 'tools', 'cocos2d-console', 'bin')
old_dir = self._find_environment_variable(COCOS_CONSOLE_ROOT)
if old_dir is None:
@ -441,6 +449,10 @@ class SetEnvVar(object):
self._set_environment_variable(COCOS_CONSOLE_ROOT, cocos_consle_root)
else:
if old_dir == cocos_consle_root:
# is same with before, nothing to do
return
# update the environment variable
if self._isWindows():
self.remove_dir_from_win_path(old_dir)
@ -459,7 +471,7 @@ class SetEnvVar(object):
if self._isLinux():
file_list = SetEnvVar.LINUX_CHECK_FILES
print " ->Update variable %s in files %s" % (var_name, str(file_list))
print(" ->Update variable %s in files %s" % (var_name, str(file_list)))
variable_updated = False
for file_name in file_list:
path = os.path.join(home, file_name)
@ -484,11 +496,11 @@ class SetEnvVar(object):
file_obj = open(path, 'w')
file_obj.writelines(lines)
file_obj.close()
print " ->File %s updated!" % path
print(" ->File %s updated!" % path)
# nothing updated, should add variable
if not variable_updated:
print "\n ->No files updated, add variable %s instead!" % var_name
print("\n ->No files updated, add variable %s instead!" % var_name)
ret = self._set_environment_variable(var_name, value)
else:
ret = True
@ -499,18 +511,18 @@ class SetEnvVar(object):
def _force_update_env(self, var_name, value):
ret = False
if self._isWindows():
print " ->Force update environment variable %s" % var_name
print(" ->Force update environment variable %s" % var_name)
ret = self._set_environment_variable_win32(var_name, value)
if not ret:
print " ->Failed!"
print(" ->Failed!")
else:
print " ->Succeed : %s=%s" % (var_name, value)
print(" ->Succeed : %s=%s" % (var_name, value))
else:
ret = self._force_update_unix_env(var_name, value)
return ret
def set_variable(self, var_name, value):
print "->Check environment variable %s" % var_name
print("->Check environment variable %s" % var_name)
find_value = self._find_environment_variable(var_name)
var_found = (find_value is not None)
action_none = 0
@ -558,7 +570,7 @@ class SetEnvVar(object):
def set_environment_variables(self, ndk_root, android_sdk_root, ant_root):
print '\nSetting up cocos2d-x...'
print('\nSetting up cocos2d-x...')
self.file_used_for_setup = self._get_filepath_for_setup()
@ -569,15 +581,17 @@ class SetEnvVar(object):
# tip the backup file
if (self.backup_file is not None) and (os.path.exists(self.backup_file)):
print '\nA backup file \"%s\" is created for \"%s\".' % (self.backup_file, self.file_used_for_setup)
print('\nA backup file \"%s\" is created for \"%s\".' % (self.backup_file, self.file_used_for_setup))
if self._isWindows():
print '\nPlease restart the terminal or restart computer to make added system variables take effect\n'
print('\nPlease restart the terminal or restart computer to make added system variables take effect\n')
else:
print '\nPlease execute command: "source %s" to make added system variables take effect\n' % self.file_used_for_setup
print('\nPlease execute command: "source %s" to make added system variables take effect\n' % self.file_used_for_setup)
if __name__ == '__main__':
if not _check_python_version():
exit()
parser = OptionParser()
parser.add_option('-n', '--ndkroot', dest='ndk_root', help='directory of ndk root')
parser.add_option('-a', '--androidsdkroot', dest='android_sdk_root', help='directory of android sdk root')
@ -587,3 +601,12 @@ if __name__ == '__main__':
# set environment variables
env = SetEnvVar()
env.set_environment_variables(opts.ndk_root, opts.android_sdk_root, opts.ant_root)
if env._isWindows():
import ctypes
HWND_BROADCAST = 0xFFFF
WM_SETTINGCHANGE = 0x1A
SMTO_ABORTIFHUNG = 0x0002
result = ctypes.c_long()
SendMessageTimeoutW = ctypes.windll.user32.SendMessageTimeoutW
SendMessageTimeoutW(HWND_BROADCAST, WM_SETTINGCHANGE, 0, u'Environment', SMTO_ABORTIFHUNG, 5000, ctypes.byref(result))

View File

@ -70,14 +70,20 @@
}
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
[super didRotateFromInterfaceOrientation:fromInterfaceOrientation];
[super didRotateFromInterfaceOrientation:fromInterfaceOrientation];
cocos2d::GLView *glview = cocos2d::Director::getInstance()->getOpenGLView();
cocos2d::GLView *glview = cocos2d::Director::getInstance()->getOpenGLView();
if (glview)
{
CCEAGLView *eaglview = (CCEAGLView*) glview->getEAGLView();
CGSize s = CGSizeMake([eaglview getWidth], [eaglview getHeight]);
cocos2d::Application::getInstance()->applicationScreenSizeChanged((int) s.width, (int) s.height);
if (eaglview)
{
CGSize s = CGSizeMake([eaglview getWidth], [eaglview getHeight]);
cocos2d::Application::getInstance()->applicationScreenSizeChanged((int) s.width, (int) s.height);
}
}
}
//fix not hide status on ios7

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<buildpath>
<buildpathentry kind="con" path="org.eclipse.koneki.ldt.ExecutionEnvironmentContainer/cocos2dx/3.0-rc0"/>
</buildpath>

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>CocosGame</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
</buildSpec>
<natures>
<nature>org.ccdt.cocosproject</nature>
<nature>org.eclipse.koneki.ldt.nature</nature>
</natures>
</projectDescription>

View File

@ -22,11 +22,11 @@ bool AppDelegate::applicationDidFinishLaunching()
{
// initialize director
auto director = Director::getInstance();
auto glview = director->getOpenGLView();
if(!glview) {
glview = GLView::createWithRect("HelloLua", Rect(0,0,900,640));
director->setOpenGLView(glview);
}
auto glview = director->getOpenGLView();
if(!glview) {
glview = GLView::createWithRect("HelloLua", Rect(0,0,900,640));
director->setOpenGLView(glview);
}
glview->setDesignResolutionSize(480, 320, ResolutionPolicy::NO_BORDER);
@ -35,17 +35,15 @@ bool AppDelegate::applicationDidFinishLaunching()
// set FPS. the default value is 1.0/60 if you don't call this
director->setAnimationInterval(1.0 / 60);
#ifdef COCOS2D_DEBUG
startRuntime();
#else
auto engine = LuaEngine::getInstance();
ScriptEngineManager::getInstance()->setScriptEngine(engine);
engine->executeScriptFile("src/main.lua");
if (startRuntime())
return true;
#endif
auto engine = LuaEngine::getInstance();
ScriptEngineManager::getInstance()->setScriptEngine(engine);
engine->executeScriptFile("src/main.lua");
return true;
}

View File

@ -26,6 +26,10 @@ THE SOFTWARE.
#include "lua_debugger.h"
#include "CCLuaEngine.h"
#include "cocos2d.h"
#include "json/document.h"
#include "json/filestream.h"
#include "json/stringbuffer.h"
#include "json/writer.h"
#ifdef _WIN32
#include <direct.h>
@ -39,8 +43,11 @@ THE SOFTWARE.
using namespace std;
using namespace cocos2d;
std::string g_resourcePath;
static rapidjson::Document g_filecfgjson;
extern string getIPAddress();
string getRuntimeVersion()
const char* getRuntimeVersion()
{
return "0.0.1";
}
@ -48,22 +55,35 @@ void startScript(string strDebugArg)
{
// register lua engine
auto engine = LuaEngine::getInstance();
if (!strDebugArg.empty())
{
engine->executeString(strDebugArg.c_str());
}
cocos2d::log("debug args = %s",strDebugArg.c_str());
if (!strDebugArg.empty())
{
engine->executeString(strDebugArg.c_str());
}
cocos2d::log("debug args = %s",strDebugArg.c_str());
engine->executeScriptFile("src/main.lua");
}
void reloadScript(const string& modulefile)
bool reloadScript(const string& modulefile)
{
string strfile = modulefile;
if (strfile.empty())
{
strfile = "src/main.lua";
}
LuaEngine::getInstance()->reload(strfile.c_str());
string strfile = modulefile;
if (strfile.empty())
{
strfile = "src/main.lua";
}
auto director = Director::getInstance();
FontFNT::purgeCachedData();
if (director->getOpenGLView())
{
SpriteFrameCache::getInstance()->removeSpriteFrames();
director->getTextureCache()->removeAllTextures();
}
FileUtils::getInstance()->purgeCachedEntries();
director->getScheduler()->unscheduleAll();
director->getScheduler()->scheduleUpdate(director->getActionManager(), Scheduler::PRIORITY_SYSTEM, false);
return (LuaEngine::getInstance()->reload(strfile.c_str())==0);
}
@ -159,8 +179,8 @@ class ConnectWaitLayer: public Layer
{
public:
ConnectWaitLayer()
{
ConnectWaitLayer()
{
string strip = getIPAddress();
char szIPAddress[512]={0};
sprintf(szIPAddress, "LocalIP: %s",strip.c_str());
@ -168,7 +188,15 @@ public:
addChild(label, 9999);
label->setPosition( Point(VisibleRect::center().x, VisibleRect::top().y - 30) );
auto labelwait = LabelTTF::create("wait transfer files ...", "Arial", 22);
string strShowMsg ="";
if (CC_PLATFORM_WIN32 == CC_TARGET_PLATFORM || CC_PLATFORM_MAC == CC_TARGET_PLATFORM)
{
strShowMsg = "waiting for debugger to connect ...";
}else
{
strShowMsg = "waiting for file transfer ...";
}
auto labelwait = LabelTTF::create(strShowMsg.c_str(), "Arial", 22);
addChild(labelwait, 10000);
labelwait->setPosition( Point(VisibleRect::center().x, VisibleRect::center().y) );
@ -180,9 +208,7 @@ public:
menu->setPosition( Point::ZERO );
menuItem->setPosition( Point( VisibleRect::right().x - 50, VisibleRect::bottom().y + 25) );
addChild(menu, 1);
//_scheduler = CCDirector::sharedDirector()->getScheduler();
//scheduleUpdate();
}
}
void playerCallback(Object* sender)
{
@ -216,14 +242,13 @@ public:
_listenfd = -1;
_running = false;
_endThread = false;
_writepath = FileUtils::getInstance()->getWritablePath();
}
bool listenOnTCP(int port);
bool listenOnTCP(int port);
void stop();
private:
bool recv_file(int fd);
bool receiveFile(int fd);
void addClient();
void loop();
@ -235,116 +260,115 @@ private:
fd_set _read_set;
bool _running;
bool _endThread;
std::string _writepath;
};
bool FileServer::listenOnTCP(int port)
{
int listenfd, n;
const int on = 1;
struct addrinfo hints, *res, *ressave;
char serv[30];
int listenfd, n;
const int on = 1;
struct addrinfo hints, *res, *ressave;
char serv[30];
snprintf(serv, sizeof(serv)-1, "%d", port );
serv[sizeof(serv)-1]=0;
snprintf(serv, sizeof(serv)-1, "%d", port );
serv[sizeof(serv)-1]=0;
bzero(&hints, sizeof(struct addrinfo));
hints.ai_flags = AI_PASSIVE;
hints.ai_family = AF_INET; // AF_UNSPEC: Do we need IPv6 ?
hints.ai_socktype = SOCK_STREAM;
bzero(&hints, sizeof(struct addrinfo));
hints.ai_flags = AI_PASSIVE;
hints.ai_family = AF_INET; // AF_UNSPEC: Do we need IPv6 ?
hints.ai_socktype = SOCK_STREAM;
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
WSADATA wsaData;
n = WSAStartup(MAKEWORD(2, 2),&wsaData);
WSADATA wsaData;
n = WSAStartup(MAKEWORD(2, 2),&wsaData);
#endif
if ( (n = getaddrinfo(NULL, serv, &hints, &res)) != 0) {
fprintf(stderr,"net_listen error for %s: %s", serv, gai_strerror(n));
return false;
}
if ( (n = getaddrinfo(NULL, serv, &hints, &res)) != 0) {
fprintf(stderr,"net_listen error for %s: %s", serv, gai_strerror(n));
return false;
}
ressave = res;
do {
listenfd = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
if (listenfd < 0)
continue; /* error, try next one */
setsockopt(listenfd, SOL_SOCKET, SO_REUSEADDR, (const char*)&on, sizeof(on));
if (::bind(listenfd, res->ai_addr, res->ai_addrlen) == 0)
break; /* success */
close(listenfd); /* bind error, close and try next one */
} while ( (res = res->ai_next) != NULL);
ressave = res;
do {
listenfd = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
if (listenfd < 0)
continue; /* error, try next one */
setsockopt(listenfd, SOL_SOCKET, SO_REUSEADDR, (const char*)&on, sizeof(on));
if (::bind(listenfd, res->ai_addr, res->ai_addrlen) == 0)
break; /* success */
close(listenfd); /* bind error, close and try next one */
} while ( (res = res->ai_next) != NULL);
if (res == NULL) {
perror("net_listen:");
freeaddrinfo(ressave);
return false;
}
if (res == NULL) {
perror("net_listen:");
freeaddrinfo(ressave);
return false;
}
listen(listenfd, 1);
listen(listenfd, 1);
if (res->ai_family == AF_INET)
{
char buf[INET_ADDRSTRLEN] = "";
struct sockaddr_in *sin = (struct sockaddr_in*) res->ai_addr;
if( inet_ntop(res->ai_family, &sin->sin_addr, buf, sizeof(buf)) != NULL )
cocos2d::log("Console: listening on %s : %d", buf, ntohs(sin->sin_port));
else
perror("inet_ntop");
} else if (res->ai_family == AF_INET6)
{
char buf[INET6_ADDRSTRLEN] = "";
struct sockaddr_in6 *sin = (struct sockaddr_in6*) res->ai_addr;
if( inet_ntop(res->ai_family, &sin->sin6_addr, buf, sizeof(buf)) != NULL )
cocos2d::log("Console: listening on %s : %d", buf, ntohs(sin->sin6_port));
else
perror("inet_ntop");
}
freeaddrinfo(ressave);
_listenfd = listenfd;
_thread = std::thread( std::bind( &FileServer::loop, this) );
return true;
if (res->ai_family == AF_INET)
{
char buf[INET_ADDRSTRLEN] = "";
struct sockaddr_in *sin = (struct sockaddr_in*) res->ai_addr;
if( inet_ntop(res->ai_family, &sin->sin_addr, buf, sizeof(buf)) != NULL )
cocos2d::log("Console: listening on %s : %d", buf, ntohs(sin->sin_port));
else
perror("inet_ntop");
} else if (res->ai_family == AF_INET6)
{
char buf[INET6_ADDRSTRLEN] = "";
struct sockaddr_in6 *sin = (struct sockaddr_in6*) res->ai_addr;
if( inet_ntop(res->ai_family, &sin->sin6_addr, buf, sizeof(buf)) != NULL )
cocos2d::log("Console: listening on %s : %d", buf, ntohs(sin->sin6_port));
else
perror("inet_ntop");
}
freeaddrinfo(ressave);
_listenfd = listenfd;
_thread = std::thread( std::bind( &FileServer::loop, this) );
return true;
}
void FileServer::stop()
{
if( _running ) {
_endThread = true;
_thread.join();
}
if( _running ) {
_endThread = true;
_thread.join();
}
}
string& replace_all(string& str,const string& old_value,const string& new_value)
string& replaceAll(string& str,const string& old_value,const string& new_value)
{
while(true)
{
int pos=0;
if((pos=str.find(old_value,0))!=string::npos)
str.replace(pos,old_value.length(),new_value);
else break;
}
return str;
while(true)
{
int pos=0;
if((pos=str.find(old_value,0))!=string::npos)
str.replace(pos,old_value.length(),new_value);
else break;
}
return str;
}
bool CreateDir(const char *sPathName)
{
char DirName[256]={0};
strcpy(DirName, sPathName);
int i,len = strlen(DirName);
if(DirName[len-1]!='/')
strcat(DirName, "/");
char DirName[256]={0};
strcpy(DirName, sPathName);
int i,len = strlen(DirName);
if(DirName[len-1]!='/')
strcat(DirName, "/");
len = strlen(DirName);
for(i=1; i<len; i++)
{
if(DirName[i]=='/')
{
DirName[i] = 0;
if(access(DirName, NULL)!=0 )
{
len = strlen(DirName);
for(i=1; i<len; i++)
{
if(DirName[i]=='/')
{
DirName[i] = 0;
if(access(DirName, NULL)!=0 )
{
#ifdef _WIN32
if(mkdir(DirName/*, 0755*/)==-1)
if(mkdir(DirName/*, 0755*/)==-1)
#else
if(mkdir(DirName, 0755)==-1)
#endif
@ -352,138 +376,210 @@ bool CreateDir(const char *sPathName)
perror("mkdir error");
return false;
}
}
DirName[i] = '/';
}
}
}
DirName[i] = '/';
}
}
return true;
return true;
}
bool FileServer::recv_file(int fd)
static bool updateResFileInfo()
{
char buffer[1024]={0};
char namelen[5]={0};
if (recv(fd, namelen, 4,0)<=0) {
return false;
}
rapidjson::StringBuffer buffer;
rapidjson::Writer< rapidjson::StringBuffer > writer(buffer);
g_filecfgjson.Accept(writer);
const char* str = buffer.GetString();
string filecfg = g_resourcePath;
filecfg.append("/");
filecfg.append("fileinfo_debug.json");
FILE * pFile = fopen (filecfg.c_str() , "w");
if (!pFile)
return false;
if (recv(fd, buffer, atoi(namelen),0)<=0) {
return false;
}
fwrite(str,sizeof(char),strlen(str),pFile);
fclose(pFile);
return true;
}
static void readResFileFinfo()
{
string filecfg = g_resourcePath;
filecfg.append("/");
filecfg.append("fileinfo_debug.json");
FILE * pFile = fopen (filecfg.c_str() , "r");
if(pFile)
{
rapidjson::FileStream inputStream(pFile);
g_filecfgjson.ParseStream<0>(inputStream);
fclose(pFile);
}
if(!g_filecfgjson.IsObject())
{
g_filecfgjson.SetObject();
}
}
bool FileServer::receiveFile(int fd)
{
char headlen[5]={0};
if (recv(fd, headlen, 4,0)<=0) {
return false;
}
char *headSeg = new char[atoi(headlen)+1];
if (!headSeg)
{
return false;
}
memset(headSeg,0,atoi(headlen)+1);
if (recv(fd, headSeg, atoi(headlen),0)<=0) {
return false;
}
rapidjson::Document headjson;
headjson.Parse<0>(headSeg);
if (headjson.HasMember("filename"))
{
string filename = headjson["filename"].GetString();
char fullfilename[1024]={0};
sprintf(fullfilename,"%s%s",g_resourcePath.c_str(),filename.c_str());
string file(fullfilename);
file=replaceAll(file,"\\","/");
sprintf(fullfilename, "%s", file.c_str());
cocos2d::log("recv fullfilename = %s",fullfilename);
CreateDir(file.substr(0,file.find_last_of("/")).c_str());
FILE *fp =fopen(fullfilename, "wb");
int length =0;
while ((length=recv(fd, fullfilename, sizeof(fullfilename),0)) > 0) {
fwrite(fullfilename, sizeof(char), length,fp);
}
fclose(fp);
if (headjson.HasMember("lastmodifytime"))
{
string filemodifytime = headjson["lastmodifytime"].GetString();
if (g_filecfgjson.HasMember(filename.c_str()))
{
g_filecfgjson.RemoveMember(filename.c_str());
}
rapidjson::Value filetimeValue(rapidjson::kStringType);
filetimeValue.SetString(filemodifytime.c_str(),g_filecfgjson.GetAllocator());
rapidjson::Value filenameValue(rapidjson::kStringType);
filenameValue.SetString(filename.c_str(),g_filecfgjson.GetAllocator());
g_filecfgjson.AddMember(filenameValue.GetString(),filetimeValue,g_filecfgjson.GetAllocator());
updateResFileInfo();
}
}
if (headSeg)
{
delete [] headSeg;
headSeg =nullptr;
}
char fullfilename[1024]={0};
sprintf(fullfilename,"%s%s",_writepath.c_str(),buffer);
string file(fullfilename);
file=replace_all(file,"\\","/");
sprintf(fullfilename, "%s", file.c_str());
cocos2d::log("recv fullfilename = %s",fullfilename);
CreateDir(file.substr(0,file.find_last_of("/")).c_str());
FILE *fp =fopen(fullfilename, "wb");
int length =0;
while ((length=recv(fd, fullfilename, sizeof(fullfilename),0)) > 0) {
fwrite(fullfilename, sizeof(char), length,fp);
}
fclose(fp);
return true;
string finish("finish\n");
send(fd, finish.c_str(), finish.size(),0);
return true;
}
void FileServer::addClient()
{
struct sockaddr client;
socklen_t client_len;
struct sockaddr client;
socklen_t client_len;
/* new client */
client_len = sizeof( client );
int fd = accept(_listenfd, (struct sockaddr *)&client, &client_len );
/* new client */
client_len = sizeof( client );
int fd = accept(_listenfd, (struct sockaddr *)&client, &client_len );
// add fd to list of FD
if( fd != -1 ) {
FD_SET(fd, &_read_set);
_fds.push_back(fd);
_maxfd = std::max(_maxfd,fd);
}
// add fd to list of FD
if( fd != -1 ) {
FD_SET(fd, &_read_set);
_fds.push_back(fd);
_maxfd = std::max(_maxfd,fd);
}
}
void FileServer::loop()
{
fd_set copy_set;
struct timeval timeout, timeout_copy;
fd_set copy_set;
struct timeval timeout, timeout_copy;
_running = true;
_running = true;
FD_ZERO(&_read_set);
FD_SET(_listenfd, &_read_set);
_maxfd = _listenfd;
FD_ZERO(&_read_set);
FD_SET(_listenfd, &_read_set);
_maxfd = _listenfd;
timeout.tv_sec = 0;
timeout.tv_sec = 0;
/* 0.016 seconds. Wake up once per frame at 60PFS */
timeout.tv_usec = 16000;
/* 0.016 seconds. Wake up once per frame at 60PFS */
timeout.tv_usec = 16000;
while(!_endThread) {
while(!_endThread) {
copy_set = _read_set;
timeout_copy = timeout;
int nready = select(_maxfd+1, &copy_set, NULL, NULL, &timeout_copy);
copy_set = _read_set;
timeout_copy = timeout;
int nready = select(_maxfd+1, &copy_set, NULL, NULL, &timeout_copy);
if( nready == -1 )
{
/* error */
if(errno != EINTR)
log("Abnormal error in select()\n");
continue;
}
else if( nready == 0 )
{
/* timeout. do somethig ? */
}
else
{
/* new client */
if(FD_ISSET(_listenfd, &copy_set)) {
addClient();
if(--nready <= 0)
continue;
}
if( nready == -1 )
{
/* error */
if(errno != EINTR)
log("Abnormal error in select()\n");
continue;
}
else if( nready == 0 )
{
/* timeout. do somethig ? */
}
else
{
/* new client */
if(FD_ISSET(_listenfd, &copy_set)) {
addClient();
if(--nready <= 0)
continue;
}
/* data from client */
std::vector<int> to_remove;
for(const auto &fd: _fds) {
if(FD_ISSET(fd,&copy_set)) {
if( ! recv_file(fd) ) {
to_remove.push_back(fd);
}
if(--nready <= 0)
break;
}
}
/* data from client */
std::vector<int> to_remove;
for(const auto &fd: _fds) {
if(FD_ISSET(fd,&copy_set)) {
if( ! receiveFile(fd) ) {
to_remove.push_back(fd);
}
if(--nready <= 0)
break;
}
}
/* remove closed conections */
for(int fd: to_remove) {
FD_CLR(fd, &_read_set);
_fds.erase(std::remove(_fds.begin(), _fds.end(), fd), _fds.end());
}
}
}
/* remove closed conections */
for(int fd: to_remove) {
FD_CLR(fd, &_read_set);
_fds.erase(std::remove(_fds.begin(), _fds.end(), fd), _fds.end());
}
}
}
// clean up: ignore stdin, stdout and stderr
for(const auto &fd: _fds )
{
// clean up: ignore stdin, stdout and stderr
for(const auto &fd: _fds )
{
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
closesocket(fd);
closesocket(fd);
#else
close(fd);
close(fd);
#endif
}
}
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
closesocket(_listenfd);
WSACleanup();
closesocket(_listenfd);
WSACleanup();
#else
close(_listenfd);
close(_listenfd);
#endif
_running = false;
_running = false;
}
@ -492,13 +588,9 @@ class ConsoleCustomCommand
public:
ConsoleCustomCommand():_fileserver(nullptr)
{
_writepath = FileUtils::getInstance()->getWritablePath();
cocos2d::Console *_console = Director::getInstance()->getConsole();
static struct Console::Command commands[] = {
{"shutdownapp","exit runtime app",std::bind(&ConsoleCustomCommand::onShutDownApp, this, std::placeholders::_1, std::placeholders::_2)},
{"start-logic","run game logic script.Arg:[debugArg]",std::bind(&ConsoleCustomCommand::onRunLogicScript, this, std::placeholders::_1, std::placeholders::_2)},
{"reload","reload script.Args:[filepath]",std::bind(&ConsoleCustomCommand::onReloadScriptFile, this, std::placeholders::_1, std::placeholders::_2)},
{"getversion","get runtime version.",std::bind(&ConsoleCustomCommand::onRuntimeVersion, this, std::placeholders::_1, std::placeholders::_2)},
{"sendrequest","send command to runtime.Args[json format]",std::bind(&ConsoleCustomCommand::onSendCommand, this, std::placeholders::_1, std::placeholders::_2)},
};
for (int i=0;i< sizeof(commands)/sizeof(Console::Command);i++) {
_console->addCommand(commands[i]);
@ -510,6 +602,7 @@ public:
}
~ConsoleCustomCommand()
{
Director::getInstance()->getConsole()->stop();
_fileserver->stop();
if (_fileserver) {
delete _fileserver;
@ -517,61 +610,197 @@ public:
}
}
void onRunLogicScript(int fd, const std::string &args)
void onSendCommand(int fd, const std::string &args)
{
Director::getInstance()->getScheduler()->performFunctionInCocosThread([=](){
char szDebugArg[1024]={0};
sprintf(szDebugArg, "require('debugger')(%s,'%s')",args.c_str(),_writepath.c_str());
startScript(szDebugArg);
});
}
void onReloadScriptFile(int fd,const std::string &args)
{
Director::getInstance()->getScheduler()->performFunctionInCocosThread([=](){
reloadScript(args.c_str());
});
}
void onRuntimeVersion(int fd, const std::string &args)
{
string runtimeVer=getRuntimeVersion();
send(fd, runtimeVer.c_str(), runtimeVer.size(),0);
}
void onShutDownApp(int fd, const std::string &args)
{
Director::getInstance()->getScheduler()->performFunctionInCocosThread([](){
exit(0);
Director::getInstance()->getScheduler()->performFunctionInCocosThread([=](){
rapidjson::Document dArgParse;
dArgParse.Parse<0>(args.c_str());
if (dArgParse.HasMember("cmd"))
{
string strcmd = dArgParse["cmd"].GetString();
rapidjson::Document dReplyParse;
dReplyParse.SetObject();
dReplyParse.AddMember("cmd",strcmd.c_str(),dReplyParse.GetAllocator());
if (dArgParse.HasMember("seq")) {
dReplyParse.AddMember("seq",dArgParse["seq"],dReplyParse.GetAllocator());
}
if(strcmp(strcmd.c_str(),"start-logic")==0)
{
char szDebugArg[1024]={0};
sprintf(szDebugArg, "require('debugger')(%s,'%s')",dArgParse["debugcfg"].GetString(),g_resourcePath.c_str());
startScript(szDebugArg);
dReplyParse.AddMember("code",0,dReplyParse.GetAllocator());
}else if(strcmp(strcmd.c_str(),"reload")==0)
{
if (dArgParse.HasMember("modulefiles"))
{
rapidjson::Value bodyvalue(rapidjson::kObjectType);
const rapidjson::Value& objectfiles = dArgParse["modulefiles"];
for (rapidjson::SizeType i = 0; i < objectfiles.Size(); i++)
{
if (!reloadScript(objectfiles[i].GetString())) {
bodyvalue.AddMember(objectfiles[i].GetString(),1,dReplyParse.GetAllocator());
}
}
if (0 == objectfiles.Size())
{
reloadScript("");
}
dReplyParse.AddMember("body",bodyvalue,dReplyParse.GetAllocator());
}
dReplyParse.AddMember("code",0,dReplyParse.GetAllocator());
}else if(strcmp(strcmd.c_str(),"getversion")==0)
{
rapidjson::Value bodyvalue(rapidjson::kObjectType);
bodyvalue.AddMember("version",getRuntimeVersion(),dReplyParse.GetAllocator());
dReplyParse.AddMember("body",bodyvalue,dReplyParse.GetAllocator());
dReplyParse.AddMember("code",0,dReplyParse.GetAllocator());
}else if(strcmp(strcmd.c_str(),"getfileinfo")==0)
{
rapidjson::Value bodyvalue(rapidjson::kObjectType);
for (auto it=g_filecfgjson.MemberonBegin();it!=g_filecfgjson.MemberonEnd();++it)
{
bodyvalue.AddMember(it->name.GetString(),it->value.GetString(),dReplyParse.GetAllocator());
}
dReplyParse.AddMember("body",bodyvalue,dReplyParse.GetAllocator());
dReplyParse.AddMember("code",0,dReplyParse.GetAllocator());
}else if(strcmp(strcmd.c_str(),"getIP")==0)
{
rapidjson::Value bodyvalue(rapidjson::kObjectType);
rapidjson::Value IPValue(rapidjson::kStringType);
IPValue.SetString(getIPAddress().c_str(),dReplyParse.GetAllocator());
bodyvalue.AddMember("IP",IPValue,dReplyParse.GetAllocator());
dReplyParse.AddMember("body",bodyvalue,dReplyParse.GetAllocator());
dReplyParse.AddMember("code",0,dReplyParse.GetAllocator());
}else if(strcmp(strcmd.c_str(),"updatefileinfo")==0)
{
if(updateResFileInfo())
{
dReplyParse.AddMember("code",0,dReplyParse.GetAllocator());
}else
{
dReplyParse.AddMember("code",1,dReplyParse.GetAllocator());
}
}else if(strcmp(strcmd.c_str(),"remove")==0)
{
if (dArgParse.HasMember("files"))
{
rapidjson::Value bodyvalue(rapidjson::kObjectType);
const rapidjson::Value& objectfiles = dArgParse["files"];
for (rapidjson::SizeType i = 0; i < objectfiles.Size(); i++)
{
string filename(g_resourcePath);
filename.append("/");
filename.append(objectfiles[i].GetString());
if (FileUtils::getInstance()->isFileExist(filename))
{
if(remove(filename.c_str())==0)
{
if (g_filecfgjson.HasMember(objectfiles[i].GetString())) {
g_filecfgjson.RemoveMember(objectfiles[i].GetString());
}
}
else
{
bodyvalue.AddMember(objectfiles[i].GetString(),2,dReplyParse.GetAllocator());
}
}else
{
bodyvalue.AddMember(objectfiles[i].GetString(),1,dReplyParse.GetAllocator());
}
}
dReplyParse.AddMember("body",bodyvalue,dReplyParse.GetAllocator());
updateResFileInfo();
}
dReplyParse.AddMember("code",0,dReplyParse.GetAllocator());
}else if(strcmp(strcmd.c_str(),"shutdownapp")==0)
{
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
extern void shutDownApp();
shutDownApp();
#else
exit(0);
#endif
}
rapidjson::StringBuffer buffer;
rapidjson::Writer< rapidjson::StringBuffer > writer(buffer);
dReplyParse.Accept(writer);
const char* str = buffer.GetString();
char msgSize[64]={0x1,0};
sprintf(msgSize+1,"%d:",strlen(str));
string replymsg(msgSize);
replymsg.append(str);
send(fd,replymsg.c_str(),replymsg.size(),0);
}
});
}
private:
FileServer* _fileserver;
string _writepath;
};
void startRuntime()
bool startRuntime()
{
auto engine = LuaEngine::getInstance();
ScriptEngineManager::getInstance()->setScriptEngine(engine);
luaopen_debugger(engine->getLuaStack()->getLuaState());
static ConsoleCustomCommand s_customCommand;
vector<string> searchPathArray;
searchPathArray=FileUtils::getInstance()->getSearchPaths();
vector<string> writePathArray;
writePathArray.push_back(FileUtils::getInstance()->getWritablePath());
FileUtils::getInstance()->setSearchPaths(writePathArray);
for (unsigned i = 0; i < searchPathArray.size(); i++)
{
FileUtils::getInstance()->addSearchPath(searchPathArray[i]);
}
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
#ifndef _DEBUG
return false;
#endif
#elif(CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
#ifdef NDEBUG
return false;
#endif
#elif(CC_TARGET_PLATFORM == CC_PLATFORM_MAC || CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
#ifndef COCOS2D_DEBUG
return false;
#endif
#endif
vector<string> searchPathArray;
searchPathArray=FileUtils::getInstance()->getSearchPaths();
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 || CC_TARGET_PLATFORM == CC_PLATFORM_MAC)
if (g_resourcePath.empty())
{
extern std::string getCurAppPath();
string resourcePath = getCurAppPath();
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
resourcePath.append("/../../");
#elif (CC_TARGET_PLATFORM == CC_PLATFORM_MAC)
resourcePath.append("/../../../");
#endif
resourcePath =replaceAll(resourcePath,"\\","/");
g_resourcePath = resourcePath;
}
#else
g_resourcePath = FileUtils::getInstance()->getWritablePath();
#endif
g_resourcePath=replaceAll(g_resourcePath,"\\","/");
searchPathArray.insert(searchPathArray.begin(),g_resourcePath);
FileUtils::getInstance()->setSearchPaths(searchPathArray);
static ConsoleCustomCommand s_customCommand;
auto engine = LuaEngine::getInstance();
ScriptEngineManager::getInstance()->setScriptEngine(engine);
luaopen_debugger(engine->getLuaStack()->getLuaState());
readResFileFinfo();
auto scene = Scene::create();
auto layer = new ConnectWaitLayer();
layer->autorelease();
auto director = Director::getInstance();
scene->addChild(layer);
director->runWithScene(scene);
return true;
}
@ -579,35 +808,35 @@ void startRuntime()
SimulatorConfig *SimulatorConfig::s_sharedInstance = NULL;
SimulatorConfig *SimulatorConfig::getInstance(void)
{
if (!s_sharedInstance)
{
s_sharedInstance = new SimulatorConfig();
}
return s_sharedInstance;
if (!s_sharedInstance)
{
s_sharedInstance = new SimulatorConfig();
}
return s_sharedInstance;
}
SimulatorConfig::SimulatorConfig(void)
{
m_screenSizeArray.push_back(SimulatorScreenSize("iPhone 3Gs (480x320)", 480, 320));
m_screenSizeArray.push_back(SimulatorScreenSize("iPhone 4 (960x640)", 960, 640));
m_screenSizeArray.push_back(SimulatorScreenSize("iPhone 5 (1136x640)", 1136, 640));
m_screenSizeArray.push_back(SimulatorScreenSize("iPad (1024x768)", 1024, 768));
m_screenSizeArray.push_back(SimulatorScreenSize("iPad Retina (2048x1536)", 2048, 1536));
m_screenSizeArray.push_back(SimulatorScreenSize("Android (800x480)", 800, 480));
m_screenSizeArray.push_back(SimulatorScreenSize("Android (854x480)", 854, 480));
m_screenSizeArray.push_back(SimulatorScreenSize("Android (960x540)", 960, 540));
m_screenSizeArray.push_back(SimulatorScreenSize("Android (1024x600)", 1024, 600));
m_screenSizeArray.push_back(SimulatorScreenSize("Android (1280x720)", 1280, 720));
m_screenSizeArray.push_back(SimulatorScreenSize("Android (1280x800)", 1280, 800));
m_screenSizeArray.push_back(SimulatorScreenSize("Android (1920x1080)", 1920, 1080));
m_screenSizeArray.push_back(SimulatorScreenSize("iPhone 3Gs (480x320)", 480, 320));
m_screenSizeArray.push_back(SimulatorScreenSize("iPhone 4 (960x640)", 960, 640));
m_screenSizeArray.push_back(SimulatorScreenSize("iPhone 5 (1136x640)", 1136, 640));
m_screenSizeArray.push_back(SimulatorScreenSize("iPad (1024x768)", 1024, 768));
m_screenSizeArray.push_back(SimulatorScreenSize("iPad Retina (2048x1536)", 2048, 1536));
m_screenSizeArray.push_back(SimulatorScreenSize("Android (800x480)", 800, 480));
m_screenSizeArray.push_back(SimulatorScreenSize("Android (854x480)", 854, 480));
m_screenSizeArray.push_back(SimulatorScreenSize("Android (960x540)", 960, 540));
m_screenSizeArray.push_back(SimulatorScreenSize("Android (1024x600)", 1024, 600));
m_screenSizeArray.push_back(SimulatorScreenSize("Android (1280x720)", 1280, 720));
m_screenSizeArray.push_back(SimulatorScreenSize("Android (1280x800)", 1280, 800));
m_screenSizeArray.push_back(SimulatorScreenSize("Android (1920x1080)", 1920, 1080));
}
int SimulatorConfig::getScreenSizeCount(void)
{
return (int)m_screenSizeArray.size();
return (int)m_screenSizeArray.size();
}
const SimulatorScreenSize SimulatorConfig::getScreenSize(int index)
{
return m_screenSizeArray.at(index);
return m_screenSizeArray.at(index);
}

View File

@ -30,9 +30,9 @@ THE SOFTWARE.
using namespace std;
void startRuntime();
bool startRuntime();
void reloadScript(const string& modulefile);
bool reloadScript(const string& modulefile);
// SimulatorConfig
typedef struct _SimulatorScreenSize {

View File

@ -6,14 +6,14 @@ LOCAL_MODULE := cocos2dlua_shared
LOCAL_MODULE_FILENAME := libcocos2dlua
LOCAL_SRC_FILES := hellolua/main.cpp \
hellolua/Runtime_android.cpp \
LOCAL_SRC_FILES := lua/main.cpp \
lua/Runtime_android.cpp \
../../Classes/AppDelegate.cpp \
../../Classes/Runtime.cpp
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../Classes
LOCAL_STATIC_LIBRARIES := curl_static_prebuilt
LOCAL_WHOLE_STATIC_LIBRARIES := cocos_lua_static

View File

@ -99,6 +99,26 @@
C07828FA18B4D72E00BD2287 /* SimulatorApp.mm in Sources */ = {isa = PBXBuildFile; fileRef = C07828F718B4D72E00BD2287 /* SimulatorApp.mm */; };
C07828FD18B4DC6F00BD2287 /* Runtime.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C07828FB18B4DC6F00BD2287 /* Runtime.cpp */; };
C07828FE18B4DC7000BD2287 /* Runtime.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C07828FB18B4DC6F00BD2287 /* Runtime.cpp */; };
C08D5D5618E567C6009071A4 /* ftp.lua in Resources */ = {isa = PBXBuildFile; fileRef = C08D5D4C18E567C6009071A4 /* ftp.lua */; };
C08D5D5718E567C6009071A4 /* ftp.lua in Resources */ = {isa = PBXBuildFile; fileRef = C08D5D4C18E567C6009071A4 /* ftp.lua */; };
C08D5D5818E567C6009071A4 /* headers.lua in Resources */ = {isa = PBXBuildFile; fileRef = C08D5D4D18E567C6009071A4 /* headers.lua */; };
C08D5D5918E567C6009071A4 /* headers.lua in Resources */ = {isa = PBXBuildFile; fileRef = C08D5D4D18E567C6009071A4 /* headers.lua */; };
C08D5D5A18E567C6009071A4 /* http.lua in Resources */ = {isa = PBXBuildFile; fileRef = C08D5D4E18E567C6009071A4 /* http.lua */; };
C08D5D5B18E567C6009071A4 /* http.lua in Resources */ = {isa = PBXBuildFile; fileRef = C08D5D4E18E567C6009071A4 /* http.lua */; };
C08D5D5C18E567C6009071A4 /* ltn12.lua in Resources */ = {isa = PBXBuildFile; fileRef = C08D5D4F18E567C6009071A4 /* ltn12.lua */; };
C08D5D5D18E567C6009071A4 /* ltn12.lua in Resources */ = {isa = PBXBuildFile; fileRef = C08D5D4F18E567C6009071A4 /* ltn12.lua */; };
C08D5D5E18E567C6009071A4 /* mbox.lua in Resources */ = {isa = PBXBuildFile; fileRef = C08D5D5018E567C6009071A4 /* mbox.lua */; };
C08D5D5F18E567C6009071A4 /* mbox.lua in Resources */ = {isa = PBXBuildFile; fileRef = C08D5D5018E567C6009071A4 /* mbox.lua */; };
C08D5D6018E567C6009071A4 /* mime.lua in Resources */ = {isa = PBXBuildFile; fileRef = C08D5D5118E567C6009071A4 /* mime.lua */; };
C08D5D6118E567C6009071A4 /* mime.lua in Resources */ = {isa = PBXBuildFile; fileRef = C08D5D5118E567C6009071A4 /* mime.lua */; };
C08D5D6218E567C6009071A4 /* smtp.lua in Resources */ = {isa = PBXBuildFile; fileRef = C08D5D5218E567C6009071A4 /* smtp.lua */; };
C08D5D6318E567C6009071A4 /* smtp.lua in Resources */ = {isa = PBXBuildFile; fileRef = C08D5D5218E567C6009071A4 /* smtp.lua */; };
C08D5D6418E567C6009071A4 /* socket.lua in Resources */ = {isa = PBXBuildFile; fileRef = C08D5D5318E567C6009071A4 /* socket.lua */; };
C08D5D6518E567C6009071A4 /* socket.lua in Resources */ = {isa = PBXBuildFile; fileRef = C08D5D5318E567C6009071A4 /* socket.lua */; };
C08D5D6618E567C6009071A4 /* tp.lua in Resources */ = {isa = PBXBuildFile; fileRef = C08D5D5418E567C6009071A4 /* tp.lua */; };
C08D5D6718E567C6009071A4 /* tp.lua in Resources */ = {isa = PBXBuildFile; fileRef = C08D5D5418E567C6009071A4 /* tp.lua */; };
C08D5D6818E567C6009071A4 /* url.lua in Resources */ = {isa = PBXBuildFile; fileRef = C08D5D5518E567C6009071A4 /* url.lua */; };
C08D5D6918E567C6009071A4 /* url.lua in Resources */ = {isa = PBXBuildFile; fileRef = C08D5D5518E567C6009071A4 /* url.lua */; };
C09BA7E718BC929700A85A3E /* WorkSpaceDialog.xib in Resources */ = {isa = PBXBuildFile; fileRef = C09BA7E418BC929700A85A3E /* WorkSpaceDialog.xib */; };
C09BA7E818BC929700A85A3E /* WorkSpaceDialogController.mm in Sources */ = {isa = PBXBuildFile; fileRef = C09BA7E618BC929700A85A3E /* WorkSpaceDialogController.mm */; };
C09BA7EE18BCA49600A85A3E /* NSAppSheetAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = C09BA7ED18BCA49600A85A3E /* NSAppSheetAdditions.m */; };
@ -348,6 +368,16 @@
C07828F718B4D72E00BD2287 /* SimulatorApp.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = SimulatorApp.mm; sourceTree = "<group>"; };
C07828FB18B4DC6F00BD2287 /* Runtime.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Runtime.cpp; path = ../Classes/Runtime.cpp; sourceTree = "<group>"; };
C07828FC18B4DC6F00BD2287 /* Runtime.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Runtime.h; path = ../Classes/Runtime.h; sourceTree = "<group>"; };
C08D5D4C18E567C6009071A4 /* ftp.lua */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = ftp.lua; path = "../../cocos2d-x/external/lua/luasocket/ftp.lua"; sourceTree = "<group>"; };
C08D5D4D18E567C6009071A4 /* headers.lua */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = headers.lua; path = "../../cocos2d-x/external/lua/luasocket/headers.lua"; sourceTree = "<group>"; };
C08D5D4E18E567C6009071A4 /* http.lua */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = http.lua; path = "../../cocos2d-x/external/lua/luasocket/http.lua"; sourceTree = "<group>"; };
C08D5D4F18E567C6009071A4 /* ltn12.lua */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = ltn12.lua; path = "../../cocos2d-x/external/lua/luasocket/ltn12.lua"; sourceTree = "<group>"; };
C08D5D5018E567C6009071A4 /* mbox.lua */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = mbox.lua; path = "../../cocos2d-x/external/lua/luasocket/mbox.lua"; sourceTree = "<group>"; };
C08D5D5118E567C6009071A4 /* mime.lua */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = mime.lua; path = "../../cocos2d-x/external/lua/luasocket/mime.lua"; sourceTree = "<group>"; };
C08D5D5218E567C6009071A4 /* smtp.lua */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = smtp.lua; path = "../../cocos2d-x/external/lua/luasocket/smtp.lua"; sourceTree = "<group>"; };
C08D5D5318E567C6009071A4 /* socket.lua */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = socket.lua; path = "../../cocos2d-x/external/lua/luasocket/socket.lua"; sourceTree = "<group>"; };
C08D5D5418E567C6009071A4 /* tp.lua */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = tp.lua; path = "../../cocos2d-x/external/lua/luasocket/tp.lua"; sourceTree = "<group>"; };
C08D5D5518E567C6009071A4 /* url.lua */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = url.lua; path = "../../cocos2d-x/external/lua/luasocket/url.lua"; sourceTree = "<group>"; };
C09BA7E418BC929700A85A3E /* WorkSpaceDialog.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = WorkSpaceDialog.xib; sourceTree = "<group>"; };
C09BA7E518BC929700A85A3E /* WorkSpaceDialogController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WorkSpaceDialogController.h; sourceTree = "<group>"; };
C09BA7E618BC929700A85A3E /* WorkSpaceDialogController.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WorkSpaceDialogController.mm; sourceTree = "<group>"; };
@ -436,6 +466,16 @@
1A0227A417A3AA1A00B867AD /* Lua Common */ = {
isa = PBXGroup;
children = (
C08D5D4C18E567C6009071A4 /* ftp.lua */,
C08D5D4D18E567C6009071A4 /* headers.lua */,
C08D5D4E18E567C6009071A4 /* http.lua */,
C08D5D4F18E567C6009071A4 /* ltn12.lua */,
C08D5D5018E567C6009071A4 /* mbox.lua */,
C08D5D5118E567C6009071A4 /* mime.lua */,
C08D5D5218E567C6009071A4 /* smtp.lua */,
C08D5D5318E567C6009071A4 /* socket.lua */,
C08D5D5418E567C6009071A4 /* tp.lua */,
C08D5D5518E567C6009071A4 /* url.lua */,
C03781BD18BF656900FE4F13 /* AudioEngine.lua */,
C03781BE18BF656900FE4F13 /* CCBReaderLoad.lua */,
C03781BF18BF656900FE4F13 /* Cocos2d.lua */,
@ -780,20 +820,30 @@
C03781F018BF656A00FE4F13 /* OpenglConstants.lua in Resources */,
C03781E418BF656A00FE4F13 /* extern.lua in Resources */,
C03781E618BF656A00FE4F13 /* GuiConstants.lua in Resources */,
C08D5D6118E567C6009071A4 /* mime.lua in Resources */,
C03781D418BF656A00FE4F13 /* Cocos2d.lua in Resources */,
C03781BA18BF655400FE4F13 /* res in Resources */,
C09BA7E718BC929700A85A3E /* WorkSpaceDialog.xib in Resources */,
C03781BC18BF655400FE4F13 /* src in Resources */,
C08D5D6918E567C6009071A4 /* url.lua in Resources */,
C03781E218BF656A00FE4F13 /* DrawPrimitives.lua in Resources */,
C08D5D6318E567C6009071A4 /* smtp.lua in Resources */,
C08D5D5718E567C6009071A4 /* ftp.lua in Resources */,
C08D5D5B18E567C6009071A4 /* http.lua in Resources */,
C03781DA18BF656A00FE4F13 /* Deprecated.lua in Resources */,
C03781E018BF656A00FE4F13 /* DeprecatedOpenglEnum.lua in Resources */,
C08D5D6518E567C6009071A4 /* socket.lua in Resources */,
C08D5D5D18E567C6009071A4 /* ltn12.lua in Resources */,
C03781EC18BF656A00FE4F13 /* luaoc.lua in Resources */,
C07828F918B4D72E00BD2287 /* MainMenu.xib in Resources */,
5023817617EBBE3400990C9B /* Icon.icns in Resources */,
C03781D218BF656A00FE4F13 /* CCBReaderLoad.lua in Resources */,
C08D5D5F18E567C6009071A4 /* mbox.lua in Resources */,
C03781D018BF656A00FE4F13 /* AudioEngine.lua in Resources */,
C03781D818BF656A00FE4F13 /* CocoStudio.lua in Resources */,
C08D5D5918E567C6009071A4 /* headers.lua in Resources */,
C03781DC18BF656A00FE4F13 /* DeprecatedClass.lua in Resources */,
C08D5D6718E567C6009071A4 /* tp.lua in Resources */,
C03781F218BF656A00FE4F13 /* StudioConstants.lua in Resources */,
C03781EA18BF656A00FE4F13 /* luaj.lua in Resources */,
C03781DE18BF656A00FE4F13 /* DeprecatedEnum.lua in Resources */,
@ -807,13 +857,19 @@
buildActionMask = 2147483647;
files = (
15A8A4491834C64F00142BE0 /* Icon-114.png in Resources */,
C08D5D5618E567C6009071A4 /* ftp.lua in Resources */,
C08D5D5C18E567C6009071A4 /* ltn12.lua in Resources */,
C08D5D5E18E567C6009071A4 /* mbox.lua in Resources */,
C03781DB18BF656A00FE4F13 /* DeprecatedClass.lua in Resources */,
5023811D17EBBCAC00990C9B /* Icon-120.png in Resources */,
5091733B17ECE17A00D62437 /* Icon-100.png in Resources */,
C08D5D5818E567C6009071A4 /* headers.lua in Resources */,
C03781E918BF656A00FE4F13 /* luaj.lua in Resources */,
5023811B17EBBCAC00990C9B /* Default@2x.png in Resources */,
5091733617ECE17A00D62437 /* Icon-29.png in Resources */,
C08D5D6418E567C6009071A4 /* socket.lua in Resources */,
C03781E718BF656A00FE4F13 /* json.lua in Resources */,
C08D5D5A18E567C6009071A4 /* http.lua in Resources */,
5023811917EBBCAC00990C9B /* Default-568h@2x.png in Resources */,
C03781D318BF656A00FE4F13 /* Cocos2d.lua in Resources */,
5091733917ECE17A00D62437 /* Icon-58.png in Resources */,
@ -829,16 +885,20 @@
5023812217EBBCAC00990C9B /* Icon-76.png in Resources */,
C03781DF18BF656A00FE4F13 /* DeprecatedOpenglEnum.lua in Resources */,
5091733A17ECE17A00D62437 /* Icon-80.png in Resources */,
C08D5D6018E567C6009071A4 /* mime.lua in Resources */,
5091733717ECE17A00D62437 /* Icon-40.png in Resources */,
5023811E17EBBCAC00990C9B /* Icon-144.png in Resources */,
5023811A17EBBCAC00990C9B /* Default.png in Resources */,
C03781E118BF656A00FE4F13 /* DrawPrimitives.lua in Resources */,
C08D5D6218E567C6009071A4 /* smtp.lua in Resources */,
C03781BB18BF655400FE4F13 /* src in Resources */,
C03781EB18BF656A00FE4F13 /* luaoc.lua in Resources */,
5091733817ECE17A00D62437 /* Icon-50.png in Resources */,
C03781D718BF656A00FE4F13 /* CocoStudio.lua in Resources */,
C03781D518BF656A00FE4F13 /* Cocos2dConstants.lua in Resources */,
C08D5D6618E567C6009071A4 /* tp.lua in Resources */,
5023812117EBBCAC00990C9B /* Icon-72.png in Resources */,
C08D5D6818E567C6009071A4 /* url.lua in Resources */,
C03781DD18BF656A00FE4F13 /* DeprecatedEnum.lua in Resources */,
C03781E318BF656A00FE4F13 /* extern.lua in Resources */,
C03781D918BF656A00FE4F13 /* Deprecated.lua in Resources */,

View File

@ -52,6 +52,11 @@ using namespace cocos2d;
@synthesize menu;
std::string getCurAppPath(void)
{
return [[[NSBundle mainBundle] bundlePath] UTF8String];
}
-(void) dealloc
{
Director::getInstance()->end();
@ -63,8 +68,15 @@ using namespace cocos2d;
- (void) applicationDidFinishLaunching:(NSNotification *)aNotification
{
NSArray *args = [[NSProcessInfo processInfo] arguments];
if (args!=nullptr && [args count]>=2) {
extern std::string g_resourcePath;
g_resourcePath = [[args objectAtIndex:1]UTF8String];
}
AppDelegate app;
[self createSimulator:[NSString stringWithUTF8String:"HelloLua"] viewWidth:960 viewHeight:640 factor:1.0];
[self createSimulator:[NSString stringWithUTF8String:"HelloLua"] viewWidth:960 viewHeight:640 factor:1.0];
Application::getInstance()->run();
// After run, application needs to be terminated immediately.
[NSApp terminate: self];
@ -77,20 +89,20 @@ using namespace cocos2d;
- (void) createSimulator:(NSString*)viewName viewWidth:(float)width viewHeight:(float)height factor:(float)frameZoomFactor
{
if (g_eglView)
{
return;
}
{
return;
}
g_eglView = GLView::createWithRect([viewName cStringUsingEncoding:NSUTF8StringEncoding],cocos2d::Rect(0.0f,0.0f,width,height),frameZoomFactor);
auto director = Director::getInstance();
director->setOpenGLView(g_eglView);
g_landscape = false;
g_screenSize.width = width;
g_screenSize.height = height;
if (width > height)
{
g_landscape = true;
}
g_eglView = GLView::createWithRect([viewName cStringUsingEncoding:NSUTF8StringEncoding],cocos2d::Rect(0.0f,0.0f,width,height),frameZoomFactor);
auto director = Director::getInstance();
director->setOpenGLView(g_eglView);
g_landscape = false;
g_screenSize.width = width;
g_screenSize.height = height;
if (width > height)
{
g_landscape = true;
}
window = glfwGetCocoaWindow(g_eglView->getWindow());
[NSApp setDelegate: self];
@ -166,26 +178,26 @@ using namespace cocos2d;
}
int width = g_screenSize.width;
int height = g_screenSize.height;
if (height > width)
{
int w = width;
width = height;
height = w;
}
int height = g_screenSize.height;
if (height > width)
{
int w = width;
width = height;
height = w;
}
int count = SimulatorConfig::getInstance()->getScreenSizeCount();
for (int i = 0; i < count; ++i)
{
bool bSel = false;
int count = SimulatorConfig::getInstance()->getScreenSizeCount();
for (int i = 0; i < count; ++i)
{
bool bSel = false;
SimulatorScreenSize size = SimulatorConfig::getInstance()->getScreenSize(i);
if (size.width == width && size.height == height)
{
bSel = true;
}
if (size.width == width && size.height == height)
{
bSel = true;
}
NSMenuItem *itemView = [menuScreen itemWithTitle:[NSString stringWithUTF8String:size.title.c_str()]];
[itemView setState:(bSel? NSOnState : NSOffState)];
}
}
//[window setTitle:[NSString stringWithFormat:@"quick-x-player (%0.0f%%)", projectConfig.getFrameScale() * 100]];
@ -197,14 +209,14 @@ using namespace cocos2d;
auto policy = g_eglView->getResolutionPolicy();
auto designSize = g_eglView->getDesignResolutionSize();
if (g_landscape)
{
if (g_landscape)
{
g_eglView->setFrameSize(g_screenSize.width, g_screenSize.height);
}
else
{
}
else
{
g_eglView->setFrameSize(g_screenSize.height, g_screenSize.width);
}
}
g_eglView->setDesignResolutionSize(designSize.width, designSize.height, policy);
@ -268,13 +280,13 @@ using namespace cocos2d;
- (IBAction) onViewChangeFrameSize:(id)sender
{
NSInteger index = [sender tag];
if (index >= 0 && index < SimulatorConfig::getInstance()->getScreenSizeCount())
{
if (index >= 0 && index < SimulatorConfig::getInstance()->getScreenSizeCount())
{
SimulatorScreenSize size = SimulatorConfig::getInstance()->getScreenSize(index);
g_screenSize.width = size.width;
g_screenSize.height = size.height;
[self updateView];
}
g_screenSize.width = size.width;
g_screenSize.height = size.height;
[self updateView];
}
}

View File

@ -66,7 +66,7 @@
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<AdditionalIncludeDirectories>$(ProjectDir)..\Classes;$(EngineRoot)cocos\scripting\lua-bindings\auto;$(EngineRoot)cocos\scripting\lua-bindings\manual;$(EngineRoot)cocos\audio\include;$(EngineRoot)external\lua\lua;$(EngineRoot)external\lua\tolua;$(EngineRoot)external\chipmunk\include\chipmunk;$(EngineRoot)extensions;$(EngineRoot);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(ProjectDir)..\Classes;$(EngineRoot)cocos\scripting\lua-bindings\auto;$(EngineRoot)cocos\scripting\lua-bindings\manual;$(EngineRoot)cocos\audio\include;$(EngineRoot)external;$(EngineRoot)external\lua\lua;$(EngineRoot)external\lua\tolua;$(EngineRoot)external\chipmunk\include\chipmunk;$(EngineRoot)extensions;$(EngineRoot);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
@ -111,7 +111,8 @@ mkdir "$(OutDir)\Resource\src"
mkdir "$(OutDir)\Resource\res"
xcopy "$(ProjectDir)..\..\cocos2d-x\cocos\scripting\lua-bindings\script" "$(OutDir)\Resource" /e /Y
xcopy "$(ProjectDir)..\..\..\src" "$(OutDir)\Resource\src" /e /Y
xcopy "$(ProjectDir)..\..\..\res" "$(OutDir)\Resource\res" /e /Y</Command>
xcopy "$(ProjectDir)..\..\..\res" "$(OutDir)\Resource\res" /e /Y
xcopy "$(ProjectDir)..\..\cocos2d-x\external\lua\luasocket\*.lua" "$(OutDir)\Resource" /e /Y</Command>
<Message>copy files</Message>
</PreBuildEvent>
<PreLinkEvent>
@ -121,7 +122,7 @@ xcopy /Y /Q "$(EngineRoot)external\websockets\prebuilt\win32\*.*" "$(OutDir)"</C
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<AdditionalIncludeDirectories>$(ProjectDir)..\Classes;$(EngineRoot)cocos\scripting\lua-bindings\auto;$(EngineRoot)cocos\scripting\lua-bindings\manual;$(EngineRoot)cocos\audio\include;$(EngineRoot)external\lua\lua;$(EngineRoot)external\lua\tolua;$(EngineRoot)external\chipmunk\include\chipmunk;$(EngineRoot)extensions;$(EngineRoot);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(ProjectDir)..\Classes;$(EngineRoot)cocos\scripting\lua-bindings\auto;$(EngineRoot)cocos\scripting\lua-bindings\manual;$(EngineRoot)cocos\audio\include;$(EngineRoot)external;$(EngineRoot)external\lua\lua;$(EngineRoot)external\lua\tolua;$(EngineRoot)external\chipmunk\include\chipmunk;$(EngineRoot)extensions;$(EngineRoot);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
@ -165,7 +166,8 @@ mkdir "$(OutDir)\Resource\src"
mkdir "$(OutDir)\Resource\res"
xcopy "$(ProjectDir)..\..\cocos2d-x\cocos\scripting\lua-bindings\script" "$(OutDir)\Resource" /e /Y
xcopy "$(ProjectDir)..\..\..\src" "$(OutDir)\Resource\src" /e /Y
xcopy "$(ProjectDir)..\..\..\res" "$(OutDir)\Resource\res" /e /Y</Command>
xcopy "$(ProjectDir)..\..\..\res" "$(OutDir)\Resource\res" /e /Y
xcopy "$(ProjectDir)..\..\cocos2d-x\external\lua\luasocket\*.lua" "$(OutDir)\Resource" /e /Y</Command>
<Message>copy files</Message>
</PreBuildEvent>
<PreLinkEvent>
@ -231,4 +233,4 @@ xcopy /Y /Q "$(EngineRoot)external\websockets\prebuilt\win32\*.*" "$(OutDir)"</C
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
</Project>

View File

@ -44,264 +44,270 @@ INT_PTR CALLBACK AboutDialogCallback(HWND hDlg, UINT message, WPARAM wParam, LPA
void createViewMenu()
{
HMENU menu = GetMenu(glfwGetWin32Window(g_eglView->getWindow()));
HMENU viewMenu = GetSubMenu(menu, 1);
HMENU menu = GetMenu(glfwGetWin32Window(g_eglView->getWindow()));
HMENU viewMenu = GetSubMenu(menu, 1);
for (int i = SimulatorConfig::getInstance()->getScreenSizeCount() - 1; i >= 0; --i)
{
SimulatorScreenSize size = SimulatorConfig::getInstance()->getScreenSize(i);
wstring menuName;
menuName.assign(size.title.begin(), size.title.end());
for (int i = SimulatorConfig::getInstance()->getScreenSizeCount() - 1; i >= 0; --i)
{
SimulatorScreenSize size = SimulatorConfig::getInstance()->getScreenSize(i);
wstring menuName;
menuName.assign(size.title.begin(), size.title.end());
MENUITEMINFO item;
ZeroMemory(&item, sizeof(item));
item.cbSize = sizeof(item);
item.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STRING;
item.fType = MFT_STRING;
item.wID = ID_VIEW_SIZE + i;
item.dwTypeData = (LPTSTR)menuName.c_str();
item.cch = menuName.length();
MENUITEMINFO item;
ZeroMemory(&item, sizeof(item));
item.cbSize = sizeof(item);
item.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STRING;
item.fType = MFT_STRING;
item.wID = ID_VIEW_SIZE + i;
item.dwTypeData = (LPTSTR)menuName.c_str();
item.cch = menuName.length();
InsertMenuItem(viewMenu, 0, TRUE, &item);
}
InsertMenuItem(viewMenu, 0, TRUE, &item);
}
}
void updateMenu()
{
HMENU menu = GetMenu(glfwGetWin32Window(g_eglView->getWindow()));
HMENU viewMenu = GetSubMenu(menu, 1);
HMENU menu = GetMenu(glfwGetWin32Window(g_eglView->getWindow()));
HMENU viewMenu = GetSubMenu(menu, 1);
if (g_landscape)
{
CheckMenuItem(viewMenu, ID_VIEW_PORTRAIT, MF_BYCOMMAND | MF_UNCHECKED);
CheckMenuItem(viewMenu, ID_VIEW_LANDSCAPE, MF_BYCOMMAND | MF_CHECKED);
}
else
{
CheckMenuItem(viewMenu, ID_VIEW_PORTRAIT, MF_BYCOMMAND | MF_CHECKED);
CheckMenuItem(viewMenu, ID_VIEW_LANDSCAPE, MF_BYCOMMAND | MF_UNCHECKED);
}
if (g_landscape)
{
CheckMenuItem(viewMenu, ID_VIEW_PORTRAIT, MF_BYCOMMAND | MF_UNCHECKED);
CheckMenuItem(viewMenu, ID_VIEW_LANDSCAPE, MF_BYCOMMAND | MF_CHECKED);
}
else
{
CheckMenuItem(viewMenu, ID_VIEW_PORTRAIT, MF_BYCOMMAND | MF_CHECKED);
CheckMenuItem(viewMenu, ID_VIEW_LANDSCAPE, MF_BYCOMMAND | MF_UNCHECKED);
}
int width = g_screenSize.width;
int height = g_screenSize.height;
if (height > width)
{
int w = width;
width = height;
height = w;
}
int width = g_screenSize.width;
int height = g_screenSize.height;
if (height > width)
{
int w = width;
width = height;
height = w;
}
int count = SimulatorConfig::getInstance()->getScreenSizeCount();
for (int i = 0; i < count; ++i)
{
bool bSel = false;
int count = SimulatorConfig::getInstance()->getScreenSizeCount();
for (int i = 0; i < count; ++i)
{
bool bSel = false;
SimulatorScreenSize size = SimulatorConfig::getInstance()->getScreenSize(i);
if (size.width == width && size.height == height)
{
bSel = true;
}
CheckMenuItem(viewMenu, i, MF_BYPOSITION | (bSel? MF_CHECKED : MF_UNCHECKED));
}
SimulatorScreenSize size = SimulatorConfig::getInstance()->getScreenSize(i);
if (size.width == width && size.height == height)
{
bSel = true;
}
CheckMenuItem(viewMenu, i, MF_BYPOSITION | (bSel? MF_CHECKED : MF_UNCHECKED));
}
int scale=g_eglView->getFrameZoomFactor()*100;
CheckMenuItem(viewMenu, ID_VIEW_ZOOMOUT100, MF_BYCOMMAND | MF_UNCHECKED);
CheckMenuItem(viewMenu, ID_VIEW_ZOOMOUT75, MF_BYCOMMAND | MF_UNCHECKED);
CheckMenuItem(viewMenu, ID_VIEW_ZOOMOUT50, MF_BYCOMMAND | MF_UNCHECKED);
CheckMenuItem(viewMenu, ID_VIEW_ZOOMOUT25, MF_BYCOMMAND | MF_UNCHECKED);
switch (scale)
{
case 100:
CheckMenuItem(viewMenu, ID_VIEW_ZOOMOUT100, MF_BYCOMMAND | MF_CHECKED);
break;
case 75:
CheckMenuItem(viewMenu, ID_VIEW_ZOOMOUT75, MF_BYCOMMAND | MF_CHECKED);
break;
case 50:
CheckMenuItem(viewMenu, ID_VIEW_ZOOMOUT50, MF_BYCOMMAND | MF_CHECKED);
break;
case 25:
CheckMenuItem(viewMenu, ID_VIEW_ZOOMOUT25, MF_BYCOMMAND | MF_CHECKED);
break;
default:
break;
}
int scale=g_eglView->getFrameZoomFactor()*100;
CheckMenuItem(viewMenu, ID_VIEW_ZOOMOUT100, MF_BYCOMMAND | MF_UNCHECKED);
CheckMenuItem(viewMenu, ID_VIEW_ZOOMOUT75, MF_BYCOMMAND | MF_UNCHECKED);
CheckMenuItem(viewMenu, ID_VIEW_ZOOMOUT50, MF_BYCOMMAND | MF_UNCHECKED);
CheckMenuItem(viewMenu, ID_VIEW_ZOOMOUT25, MF_BYCOMMAND | MF_UNCHECKED);
switch (scale)
{
case 100:
CheckMenuItem(viewMenu, ID_VIEW_ZOOMOUT100, MF_BYCOMMAND | MF_CHECKED);
break;
case 75:
CheckMenuItem(viewMenu, ID_VIEW_ZOOMOUT75, MF_BYCOMMAND | MF_CHECKED);
break;
case 50:
CheckMenuItem(viewMenu, ID_VIEW_ZOOMOUT50, MF_BYCOMMAND | MF_CHECKED);
break;
case 25:
CheckMenuItem(viewMenu, ID_VIEW_ZOOMOUT25, MF_BYCOMMAND | MF_CHECKED);
break;
default:
break;
}
}
/*@brief updateView*/
void updateView()
{
auto policy = g_eglView->getResolutionPolicy();
auto designSize = g_eglView->getDesignResolutionSize();
auto policy = g_eglView->getResolutionPolicy();
auto designSize = g_eglView->getDesignResolutionSize();
if (g_landscape)
{
g_eglView->setFrameSize(g_screenSize.width, g_screenSize.height);
}
else
{
g_eglView->setFrameSize(g_screenSize.height, g_screenSize.width);
}
if (g_landscape)
{
g_eglView->setFrameSize(g_screenSize.width, g_screenSize.height);
}
else
{
g_eglView->setFrameSize(g_screenSize.height, g_screenSize.width);
}
g_eglView->setDesignResolutionSize(designSize.width, designSize.height, policy);
g_eglView->setDesignResolutionSize(designSize.width, designSize.height, policy);
updateMenu();
updateMenu();
}
void onViewChangeOrientation(int viewMenuID)
{
if (viewMenuID == ID_VIEW_PORTRAIT && g_landscape)
{
g_landscape = false;
updateView();
}
else if (viewMenuID == ID_VIEW_LANDSCAPE && !g_landscape)
{
g_landscape = true;
updateView();
}
if (viewMenuID == ID_VIEW_PORTRAIT && g_landscape)
{
g_landscape = false;
updateView();
}
else if (viewMenuID == ID_VIEW_LANDSCAPE && !g_landscape)
{
g_landscape = true;
updateView();
}
}
void onViewZoomOut(int viewMenuID)
{
float scale = 1.0;
switch (viewMenuID)
{
case ID_VIEW_ZOOMOUT100:
scale=1.0;
break;
case ID_VIEW_ZOOMOUT75:
scale=0.75;
break;
case ID_VIEW_ZOOMOUT50:
scale=0.50;
break;
case ID_VIEW_ZOOMOUT25:
scale=0.25;
break;
default:
break;
}
g_eglView->setFrameZoomFactor(scale);
updateView();
float scale = 1.0;
switch (viewMenuID)
{
case ID_VIEW_ZOOMOUT100:
scale=1.0;
break;
case ID_VIEW_ZOOMOUT75:
scale=0.75;
break;
case ID_VIEW_ZOOMOUT50:
scale=0.50;
break;
case ID_VIEW_ZOOMOUT25:
scale=0.25;
break;
default:
break;
}
g_eglView->setFrameZoomFactor(scale);
updateView();
}
void onViewChangeFrameSize(int viewMenuID)
{
int index = viewMenuID - ID_VIEW_SIZE;
if (index >= 0 && index < SimulatorConfig::getInstance()->getScreenSizeCount())
{
SimulatorScreenSize size = SimulatorConfig::getInstance()->getScreenSize(index);
g_screenSize.width = size.width;
g_screenSize.height = size.height;
updateView();
}
int index = viewMenuID - ID_VIEW_SIZE;
if (index >= 0 && index < SimulatorConfig::getInstance()->getScreenSizeCount())
{
SimulatorScreenSize size = SimulatorConfig::getInstance()->getScreenSize(index);
g_screenSize.width = size.width;
g_screenSize.height = size.height;
updateView();
}
}
void onHelpAbout()
{
DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_DIALOG_ABOUT), glfwGetWin32Window(g_eglView->getWindow()), AboutDialogCallback);
DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_DIALOG_ABOUT), glfwGetWin32Window(g_eglView->getWindow()), AboutDialogCallback);
}
void shutDownApp()
{
HWND hWnd=glfwGetWin32Window(g_eglView->getWindow());
::SendMessage(hWnd,WM_CLOSE,NULL,NULL);
}
/*@brief new windows process*/
LRESULT CALLBACK SNewWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
switch (message)
{
case WM_COMMAND:
{
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
int wmId, wmEvent;
switch (message)
{
case WM_COMMAND:
{
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
switch (wmId)
{
case ID_FILE_EXIT:
exit(0);
break;
switch (wmId)
{
case ID_FILE_EXIT:
shutDownApp();
break;
case ID_VIEW_PORTRAIT:
case ID_VIEW_LANDSCAPE:
onViewChangeOrientation(wmId);
break;
case ID_VIEW_PORTRAIT:
case ID_VIEW_LANDSCAPE:
onViewChangeOrientation(wmId);
break;
case ID_VIEW_ZOOMOUT100:
case ID_VIEW_ZOOMOUT75:
case ID_VIEW_ZOOMOUT50:
case ID_VIEW_ZOOMOUT25:
onViewZoomOut(wmId);
break;
case ID_VIEW_ZOOMOUT100:
case ID_VIEW_ZOOMOUT75:
case ID_VIEW_ZOOMOUT50:
case ID_VIEW_ZOOMOUT25:
onViewZoomOut(wmId);
break;
case ID_CONTROL_RELOAD:
reloadScript("");
break;
case ID_CONTROL_RELOAD:
reloadScript("");
break;
case ID_HELP_ABOUT:
onHelpAbout();
case ID_HELP_ABOUT:
onHelpAbout();
default:
if (wmId >= ID_VIEW_SIZE && wmId <= ID_VIEW_SIZE + SimulatorConfig::getInstance()->getScreenSizeCount() - 1)
{
onViewChangeFrameSize(wmId);
break;
}
return 0;
}
}
break;
}
return g_oldProc(hWnd, message, wParam, lParam);
default:
if (wmId >= ID_VIEW_SIZE && wmId <= ID_VIEW_SIZE + SimulatorConfig::getInstance()->getScreenSizeCount() - 1)
{
onViewChangeFrameSize(wmId);
break;
}
return 0;
}
}
break;
}
return g_oldProc(hWnd, message, wParam, lParam);
}
/*@brief AboutDialog Callback*/
INT_PTR CALLBACK AboutDialogCallback(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
UNREFERENCED_PARAMETER(lParam);
switch (message)
{
case WM_INITDIALOG:
return (INT_PTR)TRUE;
UNREFERENCED_PARAMETER(lParam);
switch (message)
{
case WM_INITDIALOG:
return (INT_PTR)TRUE;
case WM_COMMAND:
if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
{
EndDialog(hDlg, LOWORD(wParam));
return (INT_PTR)TRUE;
}
break;
}
return (INT_PTR)FALSE;
case WM_COMMAND:
if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
{
EndDialog(hDlg, LOWORD(wParam));
return (INT_PTR)TRUE;
}
break;
}
return (INT_PTR)FALSE;
}
void createSimulator(const char* viewName, float width, float height, float frameZoomFactor)
{
if (g_eglView)
{
return;
}
if (g_eglView)
{
return;
}
g_eglView = GLView::createWithRect(viewName,Rect(0,0,width,height),frameZoomFactor);
auto director = Director::getInstance();
director->setOpenGLView(g_eglView);
g_landscape = false;
g_screenSize.width = width;
g_screenSize.height = height;
if (width > height)
{
g_landscape = true;
}
g_eglView = GLView::createWithRect(viewName,Rect(0,0,width,height),frameZoomFactor);
auto director = Director::getInstance();
director->setOpenGLView(g_eglView);
g_landscape = false;
g_screenSize.width = width;
g_screenSize.height = height;
if (width > height)
{
g_landscape = true;
}
HWND hWnd=glfwGetWin32Window(g_eglView->getWindow());
HMENU hMenu = LoadMenu(GetModuleHandle(NULL), MAKEINTRESOURCE(IDR_MENU_COCOS));
SetMenu(hWnd, hMenu);
createViewMenu();
updateMenu();
HWND hWnd=glfwGetWin32Window(g_eglView->getWindow());
HMENU hMenu = LoadMenu(GetModuleHandle(NULL), MAKEINTRESOURCE(IDR_MENU_COCOS));
SetMenu(hWnd, hMenu);
createViewMenu();
updateMenu();
g_oldProc = (WNDPROC)SetWindowLong(hWnd, GWL_WNDPROC, (LONG)SNewWndProc);
if (g_oldProc==0)
{
printf("SetWindowLong NewWndProc Error:%d\n",GetLastError());
}
g_oldProc = (WNDPROC)SetWindowLong(hWnd, GWL_WNDPROC, (LONG)SNewWndProc);
if (g_oldProc==0)
{
printf("SetWindowLong NewWndProc Error:%d\n",GetLastError());
}
}

View File

@ -2,7 +2,7 @@
#include "AppDelegate.h"
#include "cocos2d.h"
#include "SimulatorWindow.h"
#include <shellapi.h>
USING_NS_CC;
// uncomment below line, open debug console
@ -16,6 +16,21 @@ int APIENTRY _tWinMain(HINSTANCE hInstance,
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);
LPWSTR *szArgList=nullptr;
int argCount=0;
szArgList = CommandLineToArgvW(GetCommandLine(),&argCount);
if (argCount >=2 )
{
int iLen = 2*wcslen(szArgList[1]);
char* chRtn = new char[iLen+1];
wcstombs(chRtn,szArgList[1],iLen+1);
extern std::string g_resourcePath;
g_resourcePath = chRtn;
delete [] chRtn;
}
LocalFree(szArgList);
#ifdef USE_WIN32_CONSOLE
AllocConsole();
freopen("CONIN$", "r", stdin);
@ -25,7 +40,7 @@ int APIENTRY _tWinMain(HINSTANCE hInstance,
// create the application instance
AppDelegate app;
createSimulator("HelloLua",960,640);
createSimulator("HelloLua",960,640);
int ret = Application::getInstance()->run();
@ -37,23 +52,23 @@ int APIENTRY _tWinMain(HINSTANCE hInstance,
}
std::string getCurAppPath(void)
{
TCHAR szAppDir[MAX_PATH]={0};
if (!GetModuleFileName(NULL,szAppDir,MAX_PATH))
return "";
int nEnd=0;
for (int i=0;szAppDir[i];i++)
{
if(szAppDir[i]=='\\')
nEnd = i;
}
szAppDir[nEnd] = 0;
int iLen = 2*wcslen(szAppDir);
char* chRtn = new char[iLen+1];
wcstombs(chRtn,szAppDir,iLen+1);
std::string strPath = chRtn;
delete [] chRtn;
chRtn=NULL;
char fuldir[MAX_PATH]={0};
_fullpath(fuldir,strPath.c_str(),MAX_PATH);
return fuldir;
TCHAR szAppDir[MAX_PATH]={0};
if (!GetModuleFileName(NULL,szAppDir,MAX_PATH))
return "";
int nEnd=0;
for (int i=0;szAppDir[i];i++)
{
if(szAppDir[i]=='\\')
nEnd = i;
}
szAppDir[nEnd] = 0;
int iLen = 2*wcslen(szAppDir);
char* chRtn = new char[iLen+1];
wcstombs(chRtn,szAppDir,iLen+1);
std::string strPath = chRtn;
delete [] chRtn;
chRtn=NULL;
char fuldir[MAX_PATH]={0};
_fullpath(fuldir,strPath.c_str(),MAX_PATH);
return fuldir;
}

View File

@ -0,0 +1 @@
8e9998bc900f66fc53ba7d0c15c57e7c989a8ab9

View File

@ -0,0 +1 @@
66c6d1cead373b45218424f6a82f370897e443e4

View File

@ -0,0 +1 @@
84689888a14a2123d2b39f7f2f61be8c15207479

View File

@ -0,0 +1 @@
APPL????

View File

@ -0,0 +1 @@
2625bd2fcb60920b0186e8a5b6654bc78992aa1b

View File

@ -0,0 +1 @@
31173448a0280d6c576e331fe29698676e6f313e

View File

@ -0,0 +1 @@
2040fc6fe624353ae1d3db50cd3d450f4fda5afc

View File

@ -0,0 +1 @@
64894cef61f7c2ff915cf5e71e135d59b794eef1

View File

@ -0,0 +1 @@
93fab5683b15236a71735b2b1693ddd69c9abf8d

View File

@ -0,0 +1 @@
3e82b1aeace3a21d8b38ff5f6c1c2d8269da4507

View File

@ -0,0 +1 @@
1ce960d750c5d069e9de8f9b396cd93ea0811609

View File

@ -119,7 +119,7 @@ local function main()
local touchBeginPoint = nil
local function onTouchBegan(touch, event)
local location = touch:getLocation()
cclog("onTouchBegan: %0.2f, %0.2f", location.x, location.y)
--cclog("onTouchBegan: %0.2f, %0.2f", location.x, location.y)
touchBeginPoint = {x = location.x, y = location.y}
spriteDog.isPaused = true
-- CCTOUCHBEGAN event must return true
@ -128,7 +128,7 @@ local function main()
local function onTouchMoved(touch, event)
local location = touch:getLocation()
cclog("onTouchMoved: %0.2f, %0.2f", location.x, location.y)
--cclog("onTouchMoved: %0.2f, %0.2f", location.x, location.y)
if touchBeginPoint then
local cx, cy = layerFarm:getPosition()
layerFarm:setPosition(cx + location.x - touchBeginPoint.x,
@ -139,7 +139,7 @@ local function main()
local function onTouchEnded(touch, event)
local location = touch:getLocation()
cclog("onTouchEnded: %0.2f, %0.2f", location.x, location.y)
--cclog("onTouchEnded: %0.2f, %0.2f", location.x, location.y)
touchBeginPoint = nil
spriteDog.isPaused = false
end

View File

@ -472,54 +472,47 @@ std::string NewDrawNodeTest::subtitle() const
NewCullingTest::NewCullingTest()
{
auto s = Director::getInstance()->getWinSize();
Size size = Director::getInstance()->getWinSize();
auto sprite = Sprite::create("Images/btn-about-normal-vertical.png");
sprite->setRotation(5);
sprite->setPosition(Point(size.width/2,size.height/3));
sprite->setScale(2);
addChild(sprite);
std::vector<std::string> images;
images.push_back("Images/grossini_dance_01.png");
images.push_back("Images/grossini_dance_02.png");
images.push_back("Images/grossini_dance_03.png");
images.push_back("Images/grossini_dance_04.png");
images.push_back("Images/grossini_dance_05.png");
images.push_back("Images/grossini_dance_06.png");
images.push_back("Images/grossini_dance_07.png");
images.push_back("Images/grossini_dance_08.png");
images.push_back("Images/grossini_dance_09.png");
images.push_back("Images/grossini_dance_10.png");
images.push_back("Images/grossini_dance_11.png");
images.push_back("Images/grossini_dance_12.png");
images.push_back("Images/grossini_dance_13.png");
images.push_back("Images/grossini_dance_14.png");
images.push_back("Images/grossini.png");
auto parent = Node::create();
parent->setPosition(s.width/2, s.height/2);
addChild(parent);
for(int index = 0; index < 500; ++index)
{
auto parent2 = Node::create();
parent2->setPosition(0,0);
parent->addChild(parent2);
parent2->setPosition(-50,0);
parent2->runAction(RepeatForever::create((JumpBy::create(10, Point(0,0), 400, 1))));
Sprite* sprite = Sprite::create(images[index % images.size()].c_str());
sprite->setPosition(Point(0,0));
//sprite->runAction(RepeatForever::create(RotateBy::create(3, 360)));
sprite->runAction(RepeatForever::create(Sequence::createWithTwoActions(ScaleBy::create(2, 2), ScaleBy::create(2,0.5))));
parent2->addChild(sprite);
}
auto sprite2 = Sprite::create("Images/btn-about-normal-vertical.png");
sprite2->setRotation(-85);
sprite2->setPosition(Point(size.width/2,size.height * 2/3));
sprite2->setScale(2);
addChild(sprite2);
for(int index = 0; index < 500; ++index)
{
auto parent2 = Node::create();
parent->addChild(parent2);
parent2->setPosition(50,0);
parent2->runAction(RepeatForever::create((JumpBy::create(7, Point(0,0), 400, 1))));
Sprite* sprite = Sprite::create(images[index % images.size()].c_str());
sprite->setPosition(Point(0,0));
//sprite->runAction(RepeatForever::create(RotateBy::create(3, 360)));
sprite->runAction(RepeatForever::create(Sequence::createWithTwoActions(ScaleBy::create(2, 2), ScaleBy::create(2,0.5))));
parent2->addChild(sprite);
}
auto listener = EventListenerTouchOneByOne::create();
listener->setSwallowTouches(true);
listener->onTouchBegan = CC_CALLBACK_2(NewCullingTest::onTouchBegan, this);
listener->onTouchMoved = CC_CALLBACK_2(NewCullingTest::onTouchMoved, this);
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
}
bool NewCullingTest::onTouchBegan(Touch* touch, Event *event)
{
auto pos = touch->getLocation();
_lastPos = pos;
return true;
}
void NewCullingTest::onTouchMoved(Touch* touch, Event *event)
{
auto pos = touch->getLocation();
auto offset = pos - _lastPos;
auto layerPos = getPosition();
auto newPos = layerPos + offset;
setPosition(newPos);
_lastPos = pos;
}
NewCullingTest::~NewCullingTest()
@ -534,7 +527,7 @@ std::string NewCullingTest::title() const
std::string NewCullingTest::subtitle() const
{
return "Culling";
return "Drag the layer to test the result of culling";
}
VBOFullTest::VBOFullTest()

View File

@ -129,6 +129,9 @@ public:
protected:
NewCullingTest();
virtual ~NewCullingTest();
bool onTouchBegan(Touch* touch, Event *event);
void onTouchMoved(Touch* touch, Event *event);
Point _lastPos;
};
class VBOFullTest : public MultiSceneTest

View File

@ -584,11 +584,13 @@ void CameraOrbitTest::onEnter()
{
TestCocosNodeDemo::onEnter();
_preProjection = Director::getInstance()->getProjection();
Director::getInstance()->setDepthTest(true);
Director::getInstance()->setProjection(Director::Projection::_3D);
}
void CameraOrbitTest::onExit()
{
Director::getInstance()->setDepthTest(false);
Director::getInstance()->setProjection(_preProjection);
TestCocosNodeDemo::onExit();
}
@ -1053,6 +1055,7 @@ void CameraTest1::onEnter()
void CameraTest1::onExit()
{
Director::getInstance()->setProjection(_preProjection);
Director::getInstance()->setDepthTest(false);
TestCocosNodeDemo::onExit();
}
@ -1100,6 +1103,7 @@ void CameraTest2::onEnter()
void CameraTest2::onExit()
{
Director::getInstance()->setProjection(_preProjection);
Director::getInstance()->setDepthTest(false);
TestCocosNodeDemo::onExit();
}

View File

@ -670,6 +670,10 @@ std::string RenderTextureTargetNode::subtitle() const
// SpriteRenderTextureBug
SpriteRenderTextureBug::SimpleSprite::SimpleSprite() : _rt(nullptr) {}
SpriteRenderTextureBug::SimpleSprite::~SimpleSprite()
{
CC_SAFE_RELEASE(_rt);
}
SpriteRenderTextureBug::SimpleSprite* SpriteRenderTextureBug::SimpleSprite::create(const char* filename, const Rect &rect)
{
@ -687,16 +691,6 @@ SpriteRenderTextureBug::SimpleSprite* SpriteRenderTextureBug::SimpleSprite::crea
}
void SpriteRenderTextureBug::SimpleSprite::draw(Renderer *renderer, const kmMat4 &transform, bool transformUpdated)
{
_customCommand.init(_globalZOrder);
_customCommand.func = CC_CALLBACK_0(SpriteRenderTextureBug::SimpleSprite::onBeforeDraw, this);
renderer->addCommand(&_customCommand);
Sprite::draw(renderer, transform, transformUpdated);
}
void SpriteRenderTextureBug::SimpleSprite::onBeforeDraw()
{
if (_rt == nullptr)
{
@ -706,6 +700,9 @@ void SpriteRenderTextureBug::SimpleSprite::onBeforeDraw()
}
_rt->beginWithClear(0.0f, 0.0f, 0.0f, 1.0f);
_rt->end();
Sprite::draw(renderer, transform, transformUpdated);
}
SpriteRenderTextureBug::SpriteRenderTextureBug()

View File

@ -139,14 +139,10 @@ public:
public:
static SimpleSprite* create(const char* filename, const Rect &rect);
SimpleSprite();
~SimpleSprite();
virtual void draw(Renderer *renderer, const kmMat4 &transform, bool transformUpdated);
protected:
void onBeforeDraw();
public:
RenderTexture *_rt;
protected:
CustomCommand _customCommand;
};
public:

View File

@ -1076,7 +1076,7 @@ void SchedulerIssue2268::onEnter()
void SchedulerIssue2268::update(float dt)
{
if ( testNode != NULL ) {
if ( testNode != nullptr ) {
// do something with testNode
// at some point we are done, pause the nodes actions and schedulers
@ -1085,13 +1085,13 @@ void SchedulerIssue2268::update(float dt)
// at some other point we are completely done with the node and want to clear it
testNode->unscheduleAllSelectors();
testNode->release();
testNode = NULL;
testNode = nullptr;
}
}
SchedulerIssue2268::~SchedulerIssue2268()
{
CC_SAFE_RELEASE(testNode);
}
std::string SchedulerIssue2268::title() const

View File

@ -118,6 +118,11 @@ void TileDemo::onEnter()
BaseTest::onEnter();
}
void TileDemo::onExit()
{
BaseTest::onExit();
Director::getInstance()->setDepthTest(false);
}
void TileDemo::restartCallback(Ref* sender)
{
auto s = new TileMapTestScene();
@ -166,6 +171,7 @@ void TileMapTestScene::runThisTest()
Director::getInstance()->replaceScene(this);
}
//------------------------------------------------------------------
//
// TileMapTest
@ -1095,12 +1101,14 @@ void TMXIsoVertexZ::onEnter()
// TIP: 2d projection should be used
Director::getInstance()->setProjection(Director::Projection::_2D);
Director::getInstance()->setDepthTest(true);
}
void TMXIsoVertexZ::onExit()
{
// At exit use any other projection.
Director::getInstance()->setProjection(Director::Projection::DEFAULT);
Director::getInstance()->setDepthTest(false);
TileDemo::onExit();
}

View File

@ -14,6 +14,7 @@ public:
virtual std::string title() const override;
virtual std::string subtitle() const override;
virtual void onEnter() override;
virtual void onExit()override;
void restartCallback(Ref* sender);
void nextCallback(Ref* sender);

View File

@ -380,6 +380,7 @@ void TestLayer1::onExitTransitionDidStart()
void TestLayer1::onExit()
{
Layer::onExit();
Director::getInstance()->setDepthTest(false);
log("Scene 1 onExit");
}
@ -509,5 +510,6 @@ void TestLayer2::onExitTransitionDidStart()
void TestLayer2::onExit()
{
Layer::onExit();
Director::getInstance()->setDepthTest(false);
log("Scene 2 onExit");
}

View File

@ -109,9 +109,10 @@ xcopy /Y /Q "$(ProjectDir)..\..\..\external\websockets\prebuilt\win32\*.*" "$(Ou
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<DebugInformationFormat>OldStyle</DebugInformationFormat>
<DisableSpecificWarnings>4267;4251;4244;%(DisableSpecificWarnings)</DisableSpecificWarnings>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
<MinimalRebuild>false</MinimalRebuild>
</ClCompile>
<Link>
<AdditionalDependencies>libcurl_imp.lib;websockets.lib;%(AdditionalDependencies)</AdditionalDependencies>
@ -583,4 +584,4 @@ xcopy /Y /Q "$(ProjectDir)..\..\..\external\websockets\prebuilt\win32\*.*" "$(Ou
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
</Project>

View File

@ -7,7 +7,7 @@ local function AccelerometerMainLayer()
local function onEnter()
layer:setAccelerometerEnabled(true)
local label = cc.Label:create(title(), "fonts/arial.ttf", 32)
local label = cc.Label:createWithTTF(title(), "fonts/arial.ttf", 32)
layer:addChild(label, 1)
label:setAnchorPoint(cc.p(0.5, 0.5))
label:setPosition( cc.p(VisibleRect:center().x, VisibleRect:top().y - 50) )

View File

@ -68,7 +68,7 @@ local function PauseTest()
local function onNodeEvent(event)
if event == "enter" then
local s = cc.Director:getInstance():getWinSize()
local l = cc.Label:create("After 3 seconds grossini should move", "fonts/Thonburi.ttf", 16)
local l = cc.Label:createWithTTF("After 3 seconds grossini should move", "fonts/Thonburi.ttf", 16)
ret:addChild(l)
l:setAnchorPoint(cc.p(0.5, 0.5))
l:setPosition( cc.p(s.width / 2, 245) )
@ -102,7 +102,7 @@ end
--------------------------------------------------------------------
local function RemoveTest()
local ret = createTestLayer("Remove Test")
local l = cc.Label:create("Should not crash", "fonts/Thonburi.ttf", 16)
local l = cc.Label:createWithTTF("Should not crash", "fonts/Thonburi.ttf", 16)
local s = cc.Director:getInstance():getWinSize()
ret:addChild(l)
l:setAnchorPoint(cc.p(0.5, 0.5))
@ -147,7 +147,7 @@ local function ResumeTest()
local function onNodeEvent(event)
if event == "enter" then
local l = cc.Label:create("Grossini only rotate/scale in 3 seconds", "fonts/Thonburi.ttf", 16)
local l = cc.Label:createWithTTF("Grossini only rotate/scale in 3 seconds", "fonts/Thonburi.ttf", 16)
ret:addChild(l)
local s = cc.Director:getInstance():getWinSize()
l:setAnchorPoint(cc.p(0.5, 0.5))

View File

@ -198,7 +198,7 @@ local function SpriteProgressBarTintAndFade()
left:runAction(cc.RepeatForever:create(cc.Sequence:create(cc.TintTo:create(1, 255, 0, 0), cc.TintTo:create(1, 0, 255, 0), cc.TintTo:create(1, 0, 0, 255))))
layer:addChild(left)
left:addChild(cc.Label:create("Tint", "fonts/Marker Felt.ttf", 20.0))
left:addChild(cc.Label:createWithTTF("Tint", "fonts/Marker Felt.ttf", 20.0))
local middle = cc.ProgressTimer:create(cc.Sprite:create(s_pPathSister2))
middle:setType(cc.PROGRESS_TIMER_TYPE_BAR)
@ -213,7 +213,7 @@ local function SpriteProgressBarTintAndFade()
middle:runAction(cc.RepeatForever:create(fade2))
layer:addChild(middle)
middle:addChild(cc.Label:create("Fade", "fonts/Marker Felt.ttf", 20.0))
middle:addChild(cc.Label:createWithTTF("Fade", "fonts/Marker Felt.ttf", 20.0))
local right = cc.ProgressTimer:create(cc.Sprite:create(s_pPathSister2))
right:setType(cc.PROGRESS_TIMER_TYPE_BAR)
@ -227,7 +227,7 @@ local function SpriteProgressBarTintAndFade()
right:runAction(cc.RepeatForever:create(cc.Sequence:create(cc.FadeTo:create(1.0, 0), cc.FadeTo:create(1.0, 255))))
layer:addChild(right)
right:addChild(cc.Label:create("Tint and Fade", "fonts/Marker Felt.ttf", 20.0))
right:addChild(cc.Label:createWithTTF("Tint and Fade", "fonts/Marker Felt.ttf", 20.0))
Helper.subtitleLabel:setString("ProgressTo Bar Mid")
return layer

View File

@ -184,7 +184,7 @@ local function ActionRotationalSkewVSStandardSkew()
box:ignoreAnchorPointForPosition(false);
box:setPosition(cc.p(s.width/2, s.height - 100 - box:getContentSize().height/2));
layer:addChild(box);
local label = cc.Label:create("Standard cocos2d Skew", s_markerFeltFontPath, 16);
local label = cc.Label:createWithTTF("Standard cocos2d Skew", s_markerFeltFontPath, 16);
label:setAnchorPoint(cc.p(0.5, 0.5))
label:setPosition(cc.p(s.width/2, s.height - 100 + label:getContentSize().height));
layer:addChild(label);
@ -200,12 +200,12 @@ local function ActionRotationalSkewVSStandardSkew()
box:ignoreAnchorPointForPosition(false);
box:setPosition(cc.p(s.width/2, s.height - 250 - box:getContentSize().height/2));
layer:addChild(box);
label = cc.Label:create("Rotational Skew", s_markerFeltFontPath, 16);
label = cc.Label:createWithTTF("Rotational Skew", s_markerFeltFontPath, 16);
label:setAnchorPoint(cc.p(0.5, 0.5))
label:setPosition(cc.p(s.width/2, s.height - 250 + label:getContentSize().height/2));
layer:addChild(label);
local actionTo2 = cc.RotateBy:create(2, 360);
local actionToBack2 = cc.RotateBy:create(2, -360);
local actionTo2 = cc.RotateBy:create(2, 360, 0);
local actionToBack2 = cc.RotateBy:create(2, -360, 0);
seq = cc.Sequence:create(actionTo2, actionToBack2)
box:runAction(seq);
@ -590,7 +590,7 @@ end
local actionSequenceLayer = nil
local function ActionSequenceCallback1()
local label = cc.Label:create("callback 1 called", s_markerFeltFontPath, 16)
local label = cc.Label:createWithTTF("callback 1 called", s_markerFeltFontPath, 16)
label:setAnchorPoint(cc.p(0.5, 0.5))
label:setPosition(size.width / 4, size.height / 2)
@ -598,7 +598,7 @@ local function ActionSequenceCallback1()
end
local function ActionSequenceCallback2(sender)
local label = cc.Label:create("callback 2 called", s_markerFeltFontPath, 16)
local label = cc.Label:createWithTTF("callback 2 called", s_markerFeltFontPath, 16)
label:setAnchorPoint(cc.p(0.5, 0.5))
label:setPosition(cc.p(size.width / 4 * 2, size.height / 2))
@ -606,7 +606,7 @@ local function ActionSequenceCallback2(sender)
end
local function ActionSequenceCallback3(sender)
local label = cc.Label:create("callback 3 called", s_markerFeltFontPath, 16)
local label = cc.Label:createWithTTF("callback 3 called", s_markerFeltFontPath, 16)
label:setAnchorPoint(cc.p(0.5, 0.5))
label:setPosition(cc.p(size.width / 4 * 3, size.height / 2))
@ -789,7 +789,7 @@ end
local callFuncLayer = nil
local function CallFucnCallback1()
local label = cc.Label:create("callback 1 called", s_markerFeltFontPath, 16)
local label = cc.Label:createWithTTF("callback 1 called", s_markerFeltFontPath, 16)
label:setAnchorPoint(cc.p(0.5, 0.5))
label:setPosition(size.width / 4, size.height / 2)
@ -797,7 +797,7 @@ local function CallFucnCallback1()
end
local function CallFucnCallback2(sender)
local label = cc.Label:create("callback 2 called", s_markerFeltFontPath, 16)
local label = cc.Label:createWithTTF("callback 2 called", s_markerFeltFontPath, 16)
label:setAnchorPoint(cc.p(0.5, 0.5))
label:setPosition(size.width / 4 * 2, size.height / 2)
@ -805,7 +805,7 @@ local function CallFucnCallback2(sender)
end
local function CallFucnCallback3(sender)
local label = cc.Label:create("callback 3 called", s_markerFeltFontPath, 16)
local label = cc.Label:createWithTTF("callback 3 called", s_markerFeltFontPath, 16)
label:setAnchorPoint(cc.p(0.5, 0.5))
label:setPosition(size.width / 4 * 3, size.height / 2)

View File

@ -26,7 +26,7 @@ function AssetManagerModule.newScene(backfunc)
backMenu:addChild(backMenuItem)
layer:addChild(backMenu,6)
local helloLabel = cc.Label:create("Hello World", s_arialPath, 38)
local helloLabel = cc.Label:createWithTTF("Hello World", s_arialPath, 38)
helloLabel:setAnchorPoint(cc.p(0.5, 0.5))
helloLabel:setPosition(cc.p(winSize.width / 2, winSize.height - 40))
layer:addChild(helloLabel, 5)

View File

@ -35,7 +35,7 @@ local function updateLayer()
cc.MenuItemFont:setFontName("Arial")
cc.MenuItemFont:setFontSize(24)
local progressLable = cc.Label:create("",s_arialPath,30)
local progressLable = cc.Label:createWithTTF("",s_arialPath,30)
progressLable:setAnchorPoint(cc.p(0.5, 0.5))
progressLable:setPosition(cc.p(140,50))
layer:addChild(progressLable)

View File

@ -90,7 +90,7 @@ local function BugTest458()
local function InitQuestionContainerSprite(pSprite)
--Add label
local pLabel = cc.Label:create("Answer 1", s_arialPath, 12)
local pLabel = cc.Label:createWithTTF("Answer 1", s_arialPath, 12)
pLabel:setAnchorPoint(cc.p(0.5,0.5))
pLabel:setTag(100)
@ -190,7 +190,7 @@ local BugTest624_2_entry = nil
local function BugTest624()
local pLayer = cc.Layer:create()
local pLabel = cc.Label:create("Layer1", s_markerFeltFontPath, 36)
local pLabel = cc.Label:createWithTTF("Layer1", s_markerFeltFontPath, 36)
pLabel:setAnchorPoint(cc.p(0.5, 0.5))
pLabel:setPosition(cc.p(Winsize.width / 2, Winsize.height / 2))
pLayer:addChild(pLabel)
@ -230,7 +230,7 @@ end
function BugTest624_2()
local pLayer = cc.Layer:create()
local pLabel = cc.Label:create("Layer2", s_markerFeltFontPath, 36)
local pLabel = cc.Label:createWithTTF("Layer2", s_markerFeltFontPath, 36)
pLabel:setAnchorPoint(cc.p(0.5, 0.5))
pLabel:setPosition(cc.p(Winsize.width / 2, Winsize.height / 2))
pLayer:addChild(pLabel)
@ -319,7 +319,7 @@ local function BugTest914()
cc.Director:getInstance():replaceScene(scene)
end
local label = cc.Label:create("Hello World", s_markerFeltFontPath, 64)
local label = cc.Label:createWithTTF("Hello World", s_markerFeltFontPath, 64)
label:setAnchorPoint(cc.p(0.5, 0.5))
--position the label on the center of the screen
label:setPosition(cc.p( Winsize.width /2 , Winsize.height/2 ))
@ -382,7 +382,7 @@ local function BugTest1159()
pScene:addChild(pLayer)
cc.Director:getInstance():replaceScene(cc.TransitionPageTurn:create(1.0, pScene, false))
end
local label = cc.MenuItemLabel:create(cc.Label:create("Flip Me", "Helvetica", 24))
local label = cc.MenuItemLabel:create(cc.Label:createWithSystemFont("Flip Me", "Helvetica", 24))
label:setAnchorPoint(cc.p(0.5, 0.5))
label:registerScriptTapHandler(menuCallback)
local menu = cc.Menu:create()
@ -594,7 +594,7 @@ local function BugsTestMainLayer()
local i = 1
for i = 1, nTestCount do
local label = cc.Label:create(testNames[i], s_arialPath, 24)
local label = cc.Label:createWithTTF(testNames[i], s_arialPath, 24)
label:setAnchorPoint(cc.p(0.5, 0.5))
local pMenuItem = cc.MenuItemLabel:create(label)
pMenuItem:registerScriptTapHandler(menuCallback)

View File

@ -195,14 +195,14 @@ function ArmatureTestLayer:createToExtensionMenu()
end
function ArmatureTestLayer:creatTitleAndSubTitle(idx)
local title = cc.Label:create(ArmatureTestLayer.title(idx), s_arialPath, 18)
local title = cc.Label:createWithTTF(ArmatureTestLayer.title(idx), s_arialPath, 18)
title:setColor(cc.c3b(0,0,0))
self:addChild(title, 1, 10000)
title:setAnchorPoint(cc.p(0.5, 0.5))
title:setPosition( cc.p(VisibleRect:center().x, VisibleRect:top().y - 30))
local subTitle = nil
if "" ~= ArmatureTestLayer.subTitle(idx) then
local subTitle = cc.Label:create(ArmatureTestLayer.subTitle(idx), s_arialPath, 18)
local subTitle = cc.Label:createWithTTF(ArmatureTestLayer.subTitle(idx), s_arialPath, 18)
subTitle:setColor(cc.c3b(0,0,0))
self:addChild(subTitle, 1, 10001)
subTitle:setAnchorPoint(cc.p(0.5, 0.5))
@ -228,7 +228,7 @@ function TestAsynchronousLoading:onEnter()
self._restarItem:setEnabled(false)
self._nextItem:setEnabled(false)
local title = cc.Label:create(ArmatureTestLayer.title(1), s_arialPath, 18)
local title = cc.Label:createWithTTF(ArmatureTestLayer.title(1), s_arialPath, 18)
title:setColor(cc.c3b(0,0,0))
self:addChild(title, 1, 10000)
title:setAnchorPoint(cc.p(0.5, 0.5))
@ -236,7 +236,7 @@ function TestAsynchronousLoading:onEnter()
local subTitle = nil
if "" ~= ArmatureTestLayer.subTitle(1) then
local subInfo = ArmatureTestLayer.subTitle(1) .. 0.0
local subTitle = cc.Label:create(subInfo, s_arialPath, 18)
local subTitle = cc.Label:createWithTTF(subInfo, s_arialPath, 18)
subTitle:setColor(cc.c3b(0,0,0))
self:addChild(subTitle, 1, 10001)
subTitle:setAnchorPoint(cc.p(0.5, 0.5))
@ -1164,7 +1164,7 @@ function TestArmatureNesting2:onEnter()
end
self._touchedMenu = false
local label = cc.Label:create("Change Mount", s_arialPath, 20)
local label = cc.Label:createWithTTF("Change Mount", s_arialPath, 20)
label:setAnchorPoint(cc.p(0.5, 0.5))
local menuItem = cc.MenuItemLabel:create(label)
menuItem:registerScriptTapHandler(changeMountCallback)

View File

@ -63,7 +63,7 @@ function SceneEditorTestLayer.create()
end
function SceneEditorTestLayer:createTitle()
local title = cc.Label:create(self.title[sceneEditorTestIdx], s_arialPath, 18)
local title = cc.Label:createWithTTF(self.title[sceneEditorTestIdx], s_arialPath, 18)
title:setAnchorPoint(cc.p(0.5, 0.5))
title:setColor(cc.c3b(255, 255, 255))
self:addChild(title, 1, 10000)

View File

@ -105,7 +105,7 @@ local function CocosDenshionTest()
m_nTestCount = table.getn(testItems)
local i = 1
for i = 1, m_nTestCount do
local label = cc.Label:create(testItems[i], s_arialPath, 24)
local label = cc.Label:createWithTTF(testItems[i], s_arialPath, 24)
label:setAnchorPoint(cc.p(0.5, 0.5))
local pMenuItem = cc.MenuItemLabel:create(label)
pMenuItem:registerScriptTapHandler(menuCallback)

View File

@ -1,11 +1,11 @@
local function CurrentLanguageTest()
local ret = cc.Layer:create()
local label = cc.Label:create("Current language Test", s_arialPath, 28)
local label = cc.Label:createWithTTF("Current language Test", s_arialPath, 28)
ret:addChild(label, 0)
label:setAnchorPoint(cc.p(0.5, 0.5))
label:setPosition( cc.p(VisibleRect:center().x, VisibleRect:top().y-50) )
local labelLanguage = cc.Label:create("", s_arialPath, 20)
local labelLanguage = cc.Label:createWithTTF("", s_arialPath, 20)
labelLanguage:setAnchorPoint(cc.p(0.5, 0.5))
labelLanguage:setPosition(VisibleRect:center())

View File

@ -66,13 +66,13 @@ local function drawPrimitivesMainLayer()
local function InitTitle(layer)
--Title
local lableTitle = cc.Label:create(GetTitle(), s_arialPath, 40)
local lableTitle = cc.Label:createWithTTF(GetTitle(), s_arialPath, 40)
layer:addChild(lableTitle, 15)
lableTitle:setAnchorPoint(cc.p(0.5, 0.5))
lableTitle:setPosition(cc.p(size.width / 2, size.height - 32))
lableTitle:setColor(cc.c3b(255, 255, 40))
--SubTitle
local subLabelTitle = cc.Label:create(GetSubTitle(), s_thonburiPath, 16)
local subLabelTitle = cc.Label:createWithTTF(GetSubTitle(), s_thonburiPath, 16)
layer:addChild(subLabelTitle, 15)
subLabelTitle:setAnchorPoint(cc.p(0.5, 0.5))
subLabelTitle:setPosition(cc.p(size.width / 2, size.height - 80))

View File

@ -352,7 +352,7 @@ function CreateEffectsTestLayer()
local x, y = size.width, size.height
titleLabel = cc.Label:create(EffectsList[ActionIdx], s_markerFeltFontPath, 32)
titleLabel = cc.Label:createWithTTF(EffectsList[ActionIdx], s_markerFeltFontPath, 32)
titleLabel:setAnchorPoint(cc.p(0.5, 0.5))
titleLabel:setPosition(x / 2, y - 80)
testLayer:addChild(titleLabel)

View File

@ -78,8 +78,8 @@ local function runNotificationCenterTest()
cc.NotificationCenter:getInstance():postNotification(NotificationCenterParam.MSG_SWITCH_STATE,selectedItem)
end
local switchlabel1 = cc.Label:create("switch off", "Marker Felt", 26)
local switchlabel2 = cc.Label:create("switch on", "Marker Felt", 26)
local switchlabel1 = cc.Label:createWithSystemFont("switch off", "Marker Felt", 26)
local switchlabel2 = cc.Label:createWithSystemFont("switch on", "Marker Felt", 26)
local switchitem1 = cc.MenuItemLabel:create(switchlabel1)
local switchitem2 = cc.MenuItemLabel:create(switchlabel2)
local switchitem = cc.MenuItemToggle:create(switchitem1)
@ -144,9 +144,9 @@ local function runNotificationCenterTest()
lightArray[i]:setPosition(cc.p(100, s.height / 4 * i) )
pLayer:addChild(lightArray[i])
local connectlabel1 = cc.Label:create("not connected", "Marker Felt", 26)
local connectlabel1 = cc.Label:createWithSystemFont("not connected", "Marker Felt", 26)
local connectlabel2 = cc.Label:create("connected", "Marker Felt", 26)
local connectlabel2 = cc.Label:createWithSystemFont("connected", "Marker Felt", 26)
local connectitem1 = cc.MenuItemLabel:create(connectlabel1)
local connectitem2 = cc.MenuItemLabel:create(connectlabel2)
local connectitem = cc.MenuItemToggle:create(connectitem1)
@ -348,7 +348,7 @@ local function runCCControlTest()
pLayer:addChild(pRibbon)
--Add the title
pSceneTitleLabel = cc.Label:create("Title", "Arial", 12)
pSceneTitleLabel = cc.Label:createWithSystemFont("Title", "Arial", 12)
pSceneTitleLabel:setPosition(cc.p (VisibleRect:center().x, VisibleRect:top().y - pSceneTitleLabel:getContentSize().height / 2 - 5))
pLayer:addChild(pSceneTitleLabel, 1)
pSceneTitleLabel:setString(pStrTitle)
@ -366,7 +366,7 @@ local function runCCControlTest()
local screenSize = cc.Director:getInstance():getWinSize()
--Add a label in which the slider value will be displayed
local pDisplayValueLabel = cc.Label:create("Move the slider thumb!\nThe lower slider is restricted." ,"Marker Felt", 32)
local pDisplayValueLabel = cc.Label:createWithSystemFont("Move the slider thumb!\nThe lower slider is restricted." ,"Marker Felt", 32)
pDisplayValueLabel:retain()
pDisplayValueLabel:setAnchorPoint(cc.p(0.5, -1.0))
pDisplayValueLabel:setPosition(cc.p(screenSize.width / 1.7, screenSize.height / 2.0))
@ -453,7 +453,7 @@ local function runCCControlTest()
pNode:addChild(pBackground)
dLayer_width = dLayer_width + pBackground:getContentSize().width
pColorLabel = cc.Label:create("#color", "Marker Felt", 30)
pColorLabel = cc.Label:createWithSystemFont("#color", "Marker Felt", 30)
pColorLabel:retain()
pColorLabel:setPosition(pBackground:getPosition())
pNode:addChild(pColorLabel)
@ -487,7 +487,7 @@ local function runCCControlTest()
pNode:addChild(pBackground)
dLayer_width = dLayer_width + pBackground:getContentSize().width
local pDisplayValueLabel = cc.Label:create("#color" ,"Marker Felt" ,30)
local pDisplayValueLabel = cc.Label:createWithSystemFont("#color" ,"Marker Felt" ,30)
pDisplayValueLabel:retain()
pDisplayValueLabel:setPosition(pBackground:getPosition())
@ -511,8 +511,8 @@ local function runCCControlTest()
cc.Sprite:create("extensions/switch-on.png"),
cc.Sprite:create("extensions/switch-off.png"),
cc.Sprite:create("extensions/switch-thumb.png"),
cc.Label:create("On", "Arial-BoldMT", 16),
cc.Label:create("Off", "Arial-BoldMT", 16)
cc.Label:createWithSystemFont("On", "Arial-BoldMT", 16),
cc.Label:createWithSystemFont("Off", "Arial-BoldMT", 16)
)
pSwitchControl:setPosition(cc.p (dLayer_width + 10 + pSwitchControl:getContentSize().width / 2, 0))
pNode:addChild(pSwitchControl)
@ -532,7 +532,7 @@ local function runCCControlTest()
local pBackgroundButton = cc.Scale9Sprite:create("extensions/button.png")
local pBackgroundHighlightedButton = cc.Scale9Sprite:create("extensions/buttonHighlighted.png")
pTitleButton = cc.Label:create(pStrTitle, "Marker Felt", 30)
pTitleButton = cc.Label:createWithSystemFont(pStrTitle, "Marker Felt", 30)
pTitleButton:setColor(cc.c3b(159, 168, 176))
@ -587,7 +587,7 @@ local function runCCControlTest()
local pBackgroundHighlightedButton = cc.Scale9Sprite:create("extensions/buttonHighlighted.png")
pBackgroundHighlightedButton:setPreferredSize(cc.size(45, 45))
local pTitleButton = cc.Label:create(pStrTitle, "Marker Felt", 30)
local pTitleButton = cc.Label:createWithSystemFont(pStrTitle, "Marker Felt", 30)
pTitleButton:setColor(cc.c3b(159, 168, 176))
@ -651,7 +651,7 @@ local function runCCControlTest()
--Add a label in which the button events will be displayed
local pDisplayValueLabel = nil
pDisplayValueLabel = cc.Label:create("No Event", "Marker Felt", 32)
pDisplayValueLabel = cc.Label:createWithSystemFont("No Event", "Marker Felt", 32)
pDisplayValueLabel:setAnchorPoint(cc.p(0.5, -1))
pDisplayValueLabel:setPosition(cc.p(screenSize.width / 2.0, screenSize.height / 2.0))
pLayer:addChild(pDisplayValueLabel, 1)
@ -660,7 +660,7 @@ local function runCCControlTest()
local pBackgroundButton = cc.Scale9Sprite:create("extensions/button.png")
local pBackgroundHighlightedButton = cc.Scale9Sprite:create("extensions/buttonHighlighted.png")
local pTitleButtonLabel = cc.Label:create("Touch Me!", "Marker Felt", 30)
local pTitleButtonLabel = cc.Label:createWithSystemFont("Touch Me!", "Marker Felt", 30)
pTitleButtonLabel:setColor(cc.c3b(159, 168, 176))
local pControlButton = cc.ControlButton:create(pTitleButtonLabel, pBackgroundButton)
@ -764,7 +764,7 @@ local function runCCControlTest()
dLayer_width = dLayer_width + pBackground:getContentSize().width
local pDisplayValueLabel = cc.Label:create("", "HelveticaNeue-Bold", 30)
local pDisplayValueLabel = cc.Label:createWithSystemFont("", "HelveticaNeue-Bold", 30)
pDisplayValueLabel:setPosition(pBackground:getPosition())
pNode:addChild(pDisplayValueLabel)
@ -816,7 +816,7 @@ local function runCCControlTest()
background:setPosition(cc.p(layer_width + background:getContentSize().width / 2.0, 0))
pNode:addChild(background)
local pDisplayValueLabel = cc.Label:create("0", "HelveticaNeue-Bold", 30)
local pDisplayValueLabel = cc.Label:createWithSystemFont("0", "HelveticaNeue-Bold", 30)
pDisplayValueLabel:setPosition(background:getPosition())
pNode:addChild(pDisplayValueLabel)
@ -901,7 +901,7 @@ local function runEditBoxTest()
pBg:setPosition(cc.p(visibleOrigin.x+visibleSize.width/2, visibleOrigin.y+visibleSize.height/2))
newLayer:addChild(pBg)
local TTFShowEditReturn = cc.Label:create("No edit control return!", "", 30)
local TTFShowEditReturn = cc.Label:createWithSystemFont("No edit control return!", "", 30)
TTFShowEditReturn:setPosition(cc.p(visibleOrigin.x+visibleSize.width/2, visibleOrigin.y + visibleSize.height - 50))
newLayer:addChild(TTFShowEditReturn)
@ -1032,7 +1032,7 @@ function TableViewTestLayer.tableCellAtIndex(table, idx)
sprite:setPosition(cc.p(0, 0))
cell:addChild(sprite)
label = cc.Label:create(strValue, "Helvetica", 20.0)
label = cc.Label:createWithSystemFont(strValue, "Helvetica", 20.0)
label:setPosition(cc.p(0,0))
label:setAnchorPoint(cc.p(0,0))
label:setTag(123)

View File

@ -15,7 +15,7 @@
local receiveTextTimes = 0
local receiveBinaryTimes = 0
local label = cc.Label:create("WebSocket Test", s_arialPath, 28)
local label = cc.Label:createWithTTF("WebSocket Test", s_arialPath, 28)
label:setAnchorPoint(cc.p(0.5, 0.5))
label:setPosition(cc.p( winSize.width / 2, winSize.height - MARGIN))
layer:addChild(label, 0)
@ -37,7 +37,7 @@
end
end
end
local labelSendText = cc.Label:create("Send Text", s_arialPath, 22)
local labelSendText = cc.Label:createWithTTF("Send Text", s_arialPath, 22)
labelSendText:setAnchorPoint(0.5, 0.5)
local itemSendText = cc.MenuItemLabel:create(labelSendText)
itemSendText:registerScriptTapHandler(onMenuSendTextClicked)
@ -56,7 +56,7 @@
end
end
end
local labelSendBinary = cc.Label:create("Send Binary", s_arialPath, 22)
local labelSendBinary = cc.Label:createWithTTF("Send Binary", s_arialPath, 22)
labelSendBinary:setAnchorPoint(cc.p(0.5, 0.5))
local itemSendBinary = cc.MenuItemLabel:create(labelSendBinary)
itemSendBinary:registerScriptTapHandler(onMenuSendBinaryClicked)
@ -64,19 +64,19 @@
menuRequest:addChild(itemSendBinary)
--Send Text Status Label
sendTextStatus = cc.Label:create("Send Text WS is waiting...", s_arialPath, 14,cc.size(160, 100),cc.VERTICAL_TEXT_ALIGNMENT_CENTER,cc.VERTICAL_TEXT_ALIGNMENT_TOP)
sendTextStatus = cc.Label:createWithTTF("Send Text WS is waiting...", s_arialPath, 14,cc.size(160, 100),cc.VERTICAL_TEXT_ALIGNMENT_CENTER,cc.VERTICAL_TEXT_ALIGNMENT_TOP)
sendTextStatus:setAnchorPoint(cc.p(0, 0))
sendTextStatus:setPosition(cc.p(0, 25))
layer:addChild(sendTextStatus)
--Send Binary Status Label
sendBinaryStatus = cc.Label:create("Send Binary WS is waiting...", s_arialPath, 14, cc.size(160, 100), cc.VERTICAL_TEXT_ALIGNMENT_CENTER, cc.VERTICAL_TEXT_ALIGNMENT_TOP)
sendBinaryStatus = cc.Label:createWithTTF("Send Binary WS is waiting...", s_arialPath, 14, cc.size(160, 100), cc.VERTICAL_TEXT_ALIGNMENT_CENTER, cc.VERTICAL_TEXT_ALIGNMENT_TOP)
sendBinaryStatus:setAnchorPoint(cc.p(0, 0))
sendBinaryStatus:setPosition(cc.p(160, 25))
layer:addChild(sendBinaryStatus)
--Error Label
errorStatus = cc.Label:create("Error WS is waiting...", s_arialPath, 14, cc.size(160, 100), cc.VERTICAL_TEXT_ALIGNMENT_CENTER, cc.VERTICAL_TEXT_ALIGNMENT_TOP)
errorStatus = cc.Label:createWithTTF("Error WS is waiting...", s_arialPath, 14, cc.size(160, 100), cc.VERTICAL_TEXT_ALIGNMENT_CENTER, cc.VERTICAL_TEXT_ALIGNMENT_TOP)
errorStatus:setAnchorPoint(cc.p(0, 0))
errorStatus:setPosition(cc.p(320, 25))
layer:addChild(errorStatus)

View File

@ -37,12 +37,12 @@ local function showFont(ret, pFont)
ret:removeChildByTag(kTagLabel3, true)
ret:removeChildByTag(kTagLabel4, true)
local top = cc.Label:create(pFont, pFont, 24)
local left = cc.Label:create("alignment left", pFont, fontSize,
local top = cc.Label:createWithTTF(pFont, pFont, 24)
local left = cc.Label:createWithTTF("alignment left", pFont, fontSize,
blockSize, cc.TEXT_ALIGNMENT_LEFT, verticalAlignment[vAlignIdx])
local center = cc.Label:create("alignment center", pFont, fontSize,
local center = cc.Label:createWithTTF("alignment center", pFont, fontSize,
blockSize, cc.TEXT_ALIGNMENT_CENTER, verticalAlignment[vAlignIdx])
local right = cc.Label:create("alignment right", pFont, fontSize,
local right = cc.Label:createWithTTF("alignment right", pFont, fontSize,
blockSize, cc.TEXT_ALIGNMENT_RIGHT, verticalAlignment[vAlignIdx])
local leftColor = cc.LayerColor:create(cc.c4b(100, 100, 100, 255), blockSize.width, blockSize.height)

View File

@ -4,12 +4,12 @@ local function KeypadMainLayer()
local function onEnter()
print("come in")
local s = cc.Director:getInstance():getWinSize()
local label = cc.Label:create("Keypad Test", s_thonburiPath, 28)
local label = cc.Label:createWithTTF("Keypad Test", s_thonburiPath, 28)
layer:addChild(label, 0)
label:setAnchorPoint(cc.p(0.5, 0.5))
label:setPosition(cc.p(s.width/2, s.height-50))
local labelTip = cc.Label:create("Please press any key...", "s_thonburiPath", 22)
local labelTip = cc.Label:createWithTTF("Please press any key...", s_thonburiPath, 22)
labelTip:setAnchorPoint(cc.p(0.5, 0.5))
labelTip:setPosition(cc.p(s.width / 2, s.height / 2))
layer:addChild(labelTip, 0)

View File

@ -1478,7 +1478,7 @@ function LabelFontNameTest.create()
label1:setPosition( cc.p(size.width/2, size.height * 0.7) )
layer:addChild(label1)
local label3 = cc.Label:create("fonts/Marker Felt.ttf","fonts/Marker Felt.ttf",32)
local label3 = cc.Label:createWithTTF("fonts/Marker Felt.ttf","fonts/Marker Felt.ttf",32)
label3:setPosition( cc.p(size.width/2, size.height * 0.5) )
layer:addChild(label3)
@ -1673,7 +1673,7 @@ function LabelTTFOldNew.create()
local s = cc.Director:getInstance():getWinSize()
local delta = s.height/4
local label1 = cc.Label:create("Cocos2d-x Label Test", "arial", 24)
local label1 = cc.Label:createWithSystemFont("Cocos2d-x Label Test", "arial", 24)
layer:addChild(label1, 0, kTagBitmapAtlas1)
label1:setPosition(cc.p(s.width/2, delta * 2))
label1:setColor(cc.c3b(255, 0, 0))

View File

@ -442,9 +442,9 @@ local function LayerGradient()
local layer1 = cc.LayerGradient:create(cc.c4b(255,0,0,255), cc.c4b(0,255,0,255), cc.p(0.9, 0.9))
ret:addChild(layer1, 0, kTagLayer)
local label1 = cc.Label:create("Compressed Interpolation: Enabled", s_markerFeltFontPath, 26)
local label1 = cc.Label:createWithTTF("Compressed Interpolation: Enabled", s_markerFeltFontPath, 26)
label1:setAnchorPoint(cc.p(0.5, 0.5))
local label2 = cc.Label:create("Compressed Interpolation: Disabled", s_markerFeltFontPath, 26)
local label2 = cc.Label:createWithTTF("Compressed Interpolation: Disabled", s_markerFeltFontPath, 26)
label2:setAnchorPoint(cc.p(0.5, 0.5))
local item1 = cc.MenuItemLabel:create(label1)
local item2 = cc.MenuItemLabel:create(label2)

View File

@ -48,13 +48,13 @@ local function LuaBridgeLayer()
local function newLuaJavaBridge()
local newScene = cc.Scene:create()
local titleLabel = cc.Label:create("", s_arialPath, 28)
local titleLabel = cc.Label:createWithTTF("", s_arialPath, 28)
newScene:addChild(titleLabel, 1)
titleLabel:setAnchorPoint(cc.p(0.5, 0.5))
titleLabel:setPosition(s.width / 2, s.height - 50)
titleLabel:setString("LuaJavaBridge Test")
subtitleLabel = cc.Label:create("", s_thonburiPath, 16)
subtitleLabel = cc.Label:createWithTTF("", s_thonburiPath, 16)
newScene:addChild(subtitleLabel, 1)
subtitleLabel:setAnchorPoint(cc.p(0.5, 0.5))
subtitleLabel:setPosition(s.width / 2, s.height - 80)
@ -88,13 +88,13 @@ local function LuaBridgeLayer()
local function newLuaObjectCBridge()
local newScene = cc.Scene:create()
local titleLabel = cc.Label:create("", s_arialPath, 28)
local titleLabel = cc.Label:createWithTTF("", s_arialPath, 28)
newScene:addChild(titleLabel, 1)
titleLabel:setAnchorPoint(cc.p(0.5, 0.5))
titleLabel:setPosition(s.width / 2, s.height - 50)
titleLabel:setString("LuaObjectCBridge Test")
subtitleLabel = cc.Label:create("", s_thonburiPath, 16)
subtitleLabel = cc.Label:createWithTTF("", s_thonburiPath, 16)
newScene:addChild(subtitleLabel, 1)
subtitleLabel:setAnchorPoint(cc.p(0.5, 0.5))
subtitleLabel:setPosition(s.width / 2, s.height - 80)

View File

@ -520,7 +520,7 @@ local function RemoveMenuItemWhenMove()
local ret = cc.Layer:create()
local s = cc.Director:getInstance():getWinSize()
local label = cc.Label:create("click item and move, should not crash", s_arialPath, 20)
local label = cc.Label:createWithTTF("click item and move, should not crash", s_arialPath, 20)
label:setAnchorPoint(cc.p(0.5, 0.5))
label:setPosition(cc.p(s.width/2, s.height - 30))
ret:addChild(label)

View File

@ -165,14 +165,14 @@ function EventDispatcherTestDemo:createMenu()
end
function EventDispatcherTestDemo:creatTitleAndSubTitle(idx)
local title = cc.Label:create(EventDispatcherTestDemo.title(idx),s_arialPath,18)
local title = cc.Label:createWithTTF(EventDispatcherTestDemo.title(idx),s_arialPath,18)
title:setColor(cc.c3b(128,128,0))
self:addChild(title, 1, 10000)
title:setAnchorPoint(cc.p(0.5, 0.5))
title:setPosition( cc.p(VisibleRect:center().x, VisibleRect:top().y - 30))
local subTitle = nil
if "" ~= EventDispatcherTestDemo.subTitle(idx) then
local subTitle = cc.Label:create(EventDispatcherTestDemo.subTitle(idx), s_arialPath, 18)
local subTitle = cc.Label:createWithTTF(EventDispatcherTestDemo.subTitle(idx), s_arialPath, 18)
subTitle:setColor(cc.c3b(128,128,0))
self:addChild(subTitle, 1, 10001)
subTitle:setAnchorPoint(cc.p(0.5, 0.5))
@ -493,7 +493,7 @@ function RemoveListenerWhenDispatchingTest:onEnter()
local eventDispatcher = self:getEventDispatcher()
eventDispatcher:addEventListenerWithSceneGraphPriority(listener1, sprite1)
local statusLabel = cc.Label:create("The sprite could be touched!", "", 20)
local statusLabel = cc.Label:createWithSystemFont("The sprite could be touched!", "", 20)
statusLabel:setAnchorPoint(cc.p(0.5, 0.5))
statusLabel:setPosition(cc.p(origin.x + size.width/2, origin.y + size.height - 90))
self:addChild(statusLabel)
@ -560,7 +560,7 @@ function CustomEventTest:onEnter()
cc.MenuItemFont:setFontSize(20)
local statusLabel1 = cc.Label:create("No custom event 1 received!", "", 20)
local statusLabel1 = cc.Label:createWithSystemFont("No custom event 1 received!", "", 20)
statusLabel1:setAnchorPoint(cc.p(0.5, 0.5))
statusLabel1:setPosition(cc.p(origin.x + size.width/2, origin.y + size.height-90 ))
self:addChild(statusLabel1)
@ -586,7 +586,7 @@ function CustomEventTest:onEnter()
sendItem1:registerScriptTapHandler(sendCallback1)
sendItem1:setPosition(cc.p(origin.x + size.width/2, origin.y + size.height/2))
local statusLabel2 = cc.Label:create("No custom event 2 received!", "", 20)
local statusLabel2 = cc.Label:createWithSystemFont("No custom event 2 received!", "", 20)
statusLabel2:setAnchorPoint(cc.p(0.5, 0.5))
statusLabel2:setPosition(cc.p(origin.x + size.width/2, origin.y + size.height-120 ))
self:addChild(statusLabel2)
@ -659,7 +659,7 @@ function LabelKeyboardEventTest:onEnter()
local origin = cc.Director:getInstance():getVisibleOrigin()
local size = cc.Director:getInstance():getVisibleSize()
local statusLabel = cc.Label:create("No keyboard event received!", "", 20)
local statusLabel = cc.Label:createWithSystemFont("No keyboard event received!", "", 20)
statusLabel:setAnchorPoint(cc.p(0.5, 0.5))
statusLabel:setPosition(cc.p(origin.x + size.width/2,origin.y + size.height/2))
self:addChild(statusLabel)
@ -1365,7 +1365,7 @@ function Issue4129Test:onEnter()
local eventDispatcher = self:getEventDispatcher()
local function eventCustomListener(event)
local label = cc.Label:create("Yeah, this issue was fixed.", "", 20)
local label = cc.Label:createWithSystemFont("Yeah, this issue was fixed.", "", 20)
label:setAnchorPoint(cc.p(0, 0.5))
label:setPosition(VisibleRect:left())
self:addChild(label)

View File

@ -426,8 +426,10 @@ end
local function CameraOrbitTest_onEnterOrExit(tag)
if tag == "enter" then
cc.Director:getInstance():setProjection(cc.DIRECTOR_PROJECTION3_D)
cc.Director:getInstance():setDepthTest(true)
elseif tag == "exit" then
cc.Director:getInstance():setProjection(cc.DIRECTOR_PROJECTION2_D)
cc.Director:getInstance():setProjection(cc.DIRECTOR_PROJECTION_DEFAULT)
cc.Director:getInstance():setDepthTest(false)
end
end
@ -470,7 +472,7 @@ local function CameraOrbitTest()
p:runAction(cc.RepeatForever:create(orbit))
layer:setScale(1)
layer:registerScriptHandler(CameraOrbitTest_onEnterOrExit)
Helper.titleLabel:setString("Camera Orbit test")
return layer
end
@ -499,7 +501,7 @@ local function CameraZoomTest_onEnterOrExit(tag)
cc.Director:getInstance():setProjection(cc.DIRECTOR_PROJECTION3_D)
CameraZoomTest_entry = scheduler:scheduleScriptFunc(CameraZoomTest_update, 0.0, false)
elseif tag == "exit" then
cc.Director:getInstance():setProjection(cc.DIRECTOR_PROJECTION2_D)
cc.Director:getInstance():setProjection(cc.DIRECTOR_PROJECTION_DEFAULT)
scheduler:unscheduleScriptEntry(CameraZoomTest_entry)
end
end
@ -693,7 +695,7 @@ function CocosNodeTest()
StressTest2,
NodeToWorld,
CameraOrbitTest,
CameraZoomTest,
-- CameraZoomTest,
ConvertToNode,
NodeOpaqueTest,
NodeNonOpaqueTest,

View File

@ -125,13 +125,13 @@ local function OpenGLTestMainLayer()
local function InitTitle(layer)
--Title
local lableTitle = cc.Label:create(GetTitle(), s_arialPath, 40)
local lableTitle = cc.Label:createWithTTF(GetTitle(), s_arialPath, 40)
layer:addChild(lableTitle, 15)
lableTitle:setAnchorPoint(cc.p(0.5, 0.5))
lableTitle:setPosition(cc.p(size.width/2, size.height-32))
lableTitle:setColor(cc.c3b(255,255,40))
--SubTitle
local subLabelTitle = cc.Label:create(GetSubTitle(), s_thonburiPath, 16)
local subLabelTitle = cc.Label:createWithTTF(GetSubTitle(), s_thonburiPath, 16)
layer:addChild(subLabelTitle, 15)
subLabelTitle:setAnchorPoint(cc.p(0.5, 0.5))
subLabelTitle:setPosition(cc.p(size.width/2, size.height-80))

View File

@ -98,12 +98,12 @@ local function getBaseLayer()
emitter = nil
titleLabel = cc.Label:create("", s_arialPath, 28)
titleLabel = cc.Label:createWithTTF("", s_arialPath, 28)
layer:addChild(titleLabel, 100, 1000)
titleLabel:setAnchorPoint(cc.p(0.5, 0.5))
titleLabel:setPosition(s.width / 2, s.height - 50)
subtitleLabel = cc.Label:create("", s_arialPath, 16)
subtitleLabel = cc.Label:createWithTTF("", s_arialPath, 16)
layer:addChild(subtitleLabel, 100)
subtitleLabel:setAnchorPoint(cc.p(0.5, 0.5))
subtitleLabel:setPosition(s.width / 2, s.height - 80)

View File

@ -357,7 +357,7 @@ local function initWithMainTest(scene, asubtest, nNodes)
menu:setPosition(s.width / 2, s.height - 65)
scene:addChild(menu, 1)
infoLabel = cc.Label:create("0 nodes", s_markerFeltFontPath, 30)
infoLabel = cc.Label:createWithTTF("0 nodes", s_markerFeltFontPath, 30)
infoLabel:setColor(cc.c3b(0, 200, 20))
infoLabel:setAnchorPoint(cc.p(0.5, 0.5))
infoLabel:setPosition(s.width / 2, s.height - 90)
@ -389,7 +389,7 @@ local function initWithMainTest(scene, asubtest, nNodes)
scene:addChild(subMenu, 1)
-- add title label
titleLabel = cc.Label:create("No title", s_arialPath, 40)
titleLabel = cc.Label:createWithTTF("No title", s_arialPath, 40)
scene:addChild(titleLabel, 1)
titleLabel:setAnchorPoint(cc.p(0.5, 0.5))
titleLabel:setPosition(s.width / 2, s.height - 32)

View File

@ -338,14 +338,14 @@ local function runNodeChildrenTest()
local s = cc.Director:getInstance():getWinSize()
--Title
local pLabel = cc.Label:create(GetTitle(), s_arialPath, 40)
local pLabel = cc.Label:createWithTTF(GetTitle(), s_arialPath, 40)
pNewscene:addChild(pLabel, 1)
pLabel:setAnchorPoint(cc.p(0.5, 0.5))
pLabel:setPosition(cc.p(s.width/2, s.height-32))
pLabel:setColor(cc.c3b(255,255,40))
if (nil ~= GetSubTitle()) and ("" ~= GetSubTitle()) then
local pSubLabel = cc.Label:create(GetSubTitle(), s_thonburiPath, 16)
local pSubLabel = cc.Label:createWithTTF(GetSubTitle(), s_thonburiPath, 16)
pNewscene:addChild(pSubLabel, 1)
pSubLabel:setAnchorPoint(cc.p(0.5, 0.5))
pSubLabel:setPosition(cc.p(s.width/2, s.height-80))
@ -372,7 +372,7 @@ local function runNodeChildrenTest()
pNewscene:addChild(pMenuAddOrSub,1)
--InfoLayer
local pInfoLabel = cc.Label:create("0 nodes", s_markerFeltFontPath, 30)
local pInfoLabel = cc.Label:createWithTTF("0 nodes", s_markerFeltFontPath, 30)
pInfoLabel:setColor(cc.c3b(0,200,20))
pInfoLabel:setAnchorPoint(cc.p(0.5, 0.5))
pInfoLabel:setPosition(cc.p(s.width/2, s.height/2-15))
@ -828,7 +828,7 @@ local function runParticleTest()
pMenuAddOrSub:setPosition(cc.p(s.width/2, s.height/2+15))
pNewScene:addChild(pMenuAddOrSub,1)
local pInfoLabel = cc.Label:create("0 nodes", s_markerFeltFontPath, 30)
local pInfoLabel = cc.Label:createWithTTF("0 nodes", s_markerFeltFontPath, 30)
pInfoLabel:setColor(cc.c3b(0,200,20))
pInfoLabel:setAnchorPoint(cc.p(0.5, 0.5))
pInfoLabel:setPosition(cc.p(s.width/2, s.height - 90))
@ -867,7 +867,7 @@ local function runParticleTest()
pSubMenu:setPosition(cc.p(s.width/2, 80))
pNewScene:addChild(pSubMenu, 2)
local pLabel = cc.Label:create(GetTitle(), s_arialPath, 40)
local pLabel = cc.Label:createWithTTF(GetTitle(), s_arialPath, 40)
pNewScene:addChild(pLabel, 1)
pLabel:setAnchorPoint(cc.p(0.5, 0.5))
pLabel:setPosition(cc.p(s.width/2, s.height-32))
@ -1274,7 +1274,7 @@ local function runSpriteTest()
pMenuAddOrSub:setPosition(cc.p(s.width/2, s.height/2+15))
pNewScene:addChild(pMenuAddOrSub,1)
local pInfoLabel = cc.Label:create("0 nodes", s_markerFeltFontPath, 30)
local pInfoLabel = cc.Label:createWithTTF("0 nodes", s_markerFeltFontPath, 30)
pInfoLabel:setColor(cc.c3b(0,200,20))
pInfoLabel:setAnchorPoint(cc.p(0.5, 0.5))
pInfoLabel:setPosition(cc.p(s.width/2, s.height - 90))
@ -1313,7 +1313,7 @@ local function runSpriteTest()
pSubMenu:setPosition(cc.p(s.width/2, 80))
pNewScene:addChild(pSubMenu, 2)
local pLabel = cc.Label:create(GetTitle(), s_arialPath, 40)
local pLabel = cc.Label:createWithTTF(GetTitle(), s_arialPath, 40)
pNewScene:addChild(pLabel, 1)
pLabel:setAnchorPoint(cc.p(0.5, 0.5))
pLabel:setPosition(cc.p(s.width/2, s.height-32))
@ -1438,14 +1438,14 @@ local function runTextureTest()
end
--Title
local pLabel = cc.Label:create(GetTitle(), s_arialPath, 40)
local pLabel = cc.Label:createWithTTF(GetTitle(), s_arialPath, 40)
pLayer:addChild(pLabel, 1)
pLabel:setAnchorPoint(cc.p(0.5, 0.5))
pLabel:setPosition(cc.p(s.width/2, s.height-32))
pLabel:setColor(cc.c3b(255,255,40))
--Subtitle
local pSubLabel = cc.Label:create(GetSubtitle(), s_thonburiPath, 16)
local pSubLabel = cc.Label:createWithTTF(GetSubtitle(), s_thonburiPath, 16)
pLayer:addChild(pSubLabel, 1)
pSubLabel:setAnchorPoint(cc.p(0.5, 0.5))
pSubLabel:setPosition(cc.p(s.width/2, s.height-80))
@ -1605,7 +1605,7 @@ local function runTouchesTest()
pLayer:addChild(pTouchesTestMenu)
--Title
local pLabel = cc.Label:create(GetTitle(), s_arialPath, 40)
local pLabel = cc.Label:createWithTTF(GetTitle(), s_arialPath, 40)
pLayer:addChild(pLabel, 1)
pLabel:setAnchorPoint(cc.p(0.5, 0.5))
pLabel:setPosition(cc.p(s.width/2, s.height-32))
@ -1697,13 +1697,13 @@ local function runFuncRelateWithTable()
end
--Title
local title = cc.Label:create(GetTitle(), s_arialPath, 28)
local title = cc.Label:createWithTTF(GetTitle(), s_arialPath, 28)
layer:addChild(title, 1)
title:setAnchorPoint(cc.p(0.5, 0.5))
title:setPosition(cc.p(s.width/2, s.height-32))
title:setColor(cc.c3b(255,255,40))
--Subtitle
local subTitle = cc.Label:create(GetSubtitle(), s_thonburiPath, 16)
local subTitle = cc.Label:createWithTTF(GetSubtitle(), s_thonburiPath, 16)
layer:addChild(subTitle, 1)
subTitle:setAnchorPoint(cc.p(0.5, 0.5))
subTitle:setPosition(cc.p(s.width/2, s.height-80))
@ -1742,7 +1742,7 @@ local function runFuncRelateWithTable()
layer:addChild(menuAddOrSub,1)
--num
local numLabel = cc.Label:create("10000", s_markerFeltFontPath, 30)
local numLabel = cc.Label:createWithTTF("10000", s_markerFeltFontPath, 30)
numLabel:setColor(cc.c3b(0,200,20))
numLabel:setAnchorPoint(cc.p(0.5, 0.5))
numLabel:setPosition(cc.p(s.width/2, s.height/2-15))

View File

@ -1076,22 +1076,22 @@ local function PhysicsContactTest()
local s = cc.size(VisibleRect:getVisibleRect().width, VisibleRect:getVisibleRect().height);
local label = cc.Label:create(tostring(layer.yellowBoxNum), s_arialPath, 32);
local label = cc.Label:createWithTTF(tostring(layer.yellowBoxNum), s_arialPath, 32);
root:addChild(label, 1);
label:setAnchorPoint(cc.p(0.5, 0.5));
label:setPosition(cc.p(s.width/2, s.height-50));
label = cc.Label:create(tostring(layer.blueBoxNum), s_arialPath, 32);
label = cc.Label:createWithTTF(tostring(layer.blueBoxNum), s_arialPath, 32);
root:addChild(label, 1);
label:setAnchorPoint(cc.p(0.5, 0.5));
label:setPosition(cc.p(s.width/2, s.height-90));
label = cc.Label:create(tostring(layer.yellowTriangleNum), s_arialPath, 32);
label = cc.Label:createWithTTF(tostring(layer.yellowTriangleNum), s_arialPath, 32);
root:addChild(label, 1);
label:setAnchorPoint(cc.p(0.5, 0.5));
label:setPosition(cc.p(s.width/2, s.height-130));
label = cc.Label:create(tostring(layer.blueTriangleNum), s_arialPath, 32);
label = cc.Label:createWithTTF(tostring(layer.blueTriangleNum), s_arialPath, 32);
root:addChild(label, 1);
label:setAnchorPoint(cc.p(0.5, 0.5));
label:setPosition(cc.p(s.width/2, s.height-170));
@ -1213,7 +1213,7 @@ local function PhysicsContactTest()
menu1:setPosition(cc.p(s.width/2, s.height-50));
layer:addChild(menu1, 1);
local label = cc.Label:create("yellow box", s_arialPath, 32);
local label = cc.Label:createWithTTF("yellow box", s_arialPath, 32);
layer:addChild(label, 1);
label:setAnchorPoint(cc.p(0.5, 0.5));
label:setPosition(cc.p(s.width/2 - 150, s.height-50));
@ -1232,7 +1232,7 @@ local function PhysicsContactTest()
menu2:setPosition(cc.p(s.width/2, s.height-90));
layer:addChild(menu2, 1);
label = cc.Label:create("blue box", s_arialPath, 32);
label = cc.Label:createWithTTF("blue box", s_arialPath, 32);
layer:addChild(label, 1);
label:setAnchorPoint(cc.p(0.5, 0.5));
label:setPosition(cc.p(s.width/2 - 150, s.height-90));
@ -1251,7 +1251,7 @@ local function PhysicsContactTest()
menu3:setPosition(cc.p(s.width/2, s.height-130));
layer:addChild(menu3, 1);
label = cc.Label:create("yellow triangle", s_arialPath, 32);
label = cc.Label:createWithTTF("yellow triangle", s_arialPath, 32);
layer:addChild(label, 1);
label:setAnchorPoint(cc.p(0.5, 0.5));
label:setPosition(cc.p(s.width/2 - 150, s.height-130));
@ -1270,7 +1270,7 @@ local function PhysicsContactTest()
menu4:setPosition(cc.p(s.width/2, s.height-170));
layer:addChild(menu4, 1);
label = cc.Label:create("blue triangle", s_arialPath, 32);
label = cc.Label:createWithTTF("blue triangle", s_arialPath, 32);
layer:addChild(label, 1);
label:setAnchorPoint(cc.p(0.5, 0.5));
label:setPosition(cc.p(s.width/2 - 150, s.height-170));

Some files were not shown because too many files have changed in this diff Show More