Skip to content

Instantly share code, notes, and snippets.

@tklee1975
tklee1975 / gist:d6cca60bf94a6ddc4088
Last active August 29, 2015 14:01
Setup Multiple Resolution in cocos2d-x 3.0
void setupResolutionPolicy(float designW, float designH)
{
GLView *view = Director::getInstance()->getOpenGLView();
Size screenSize = view->getFrameSize();
float designRatio = designW / designH;
float screenRatio = screenSize.height / screenSize.width;
ResolutionPolicy resolutionPolicy = screenRatio < designRatio ?
ResolutionPolicy::FIXED_HEIGHT : ResolutionPolicy::FIXED_WIDTH;
@tklee1975
tklee1975 / list_src.sh
Created February 3, 2015 01:38
Shell to list all cpp and h for Android.mk used by cocos2d-x project
# Script to generate the src file and include used by jni/Android.mk
#
# Please define the Main source directory
# ---------------------------------------
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
SRC_DIR=$DIR/../Classes
OUT_FILE=$DIR/jni/Sources.mk
EXCLUDE_DIR="Win32|UnitTest\+\+\/tests"
@tklee1975
tklee1975 / Android.mk
Created February 3, 2015 01:41
Sample Android.mk that include a source list
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_CPPFLAGS := -DENABLE_TDD
LOCAL_MODULE := cocos2dcpp_shared
LOCAL_MODULE_FILENAME := libcocos2dcpp
@tklee1975
tklee1975 / SubLayerColor
Created February 4, 2015 16:34
Sample Sub class of LayerColor in cocos2d-x
//
// MyLayerColor.h
//
#include "cocos2d.h"
USING_NS_CC;
class MyLayerColor : public cocos2d::LayerColor
{
public:
static MyLayerColor *create(const Color4B& color, float width, float height);
@tklee1975
tklee1975 / TokenGenerator
Created April 15, 2015 02:38
Token Generator; Example usage: pageToken for a long result set like the APIs of Google Place API
public static String generateToken(String prefix, int uid)
{
long now = System.currentTimeMillis();
// Shorten integer values
String nowStr = Base64.encodeLong(now);
String uidStr = Base64.encodeInt(uid);
// Concatenate
String token = prefix + nowStr + uidStr;
@tklee1975
tklee1975 / cronscp
Created May 29, 2015 07:07
A simple script to test scp working correct by Cronjob
#!/bin/sh
TIME_FILE=/etc/temp/datetime.txt
USER=admin
REMOTE_SERVER=192.168.0.1
REMOTE_PORT=22
REMOTE_PATH=/home/admin/temp
# Make a file and then send to Lab server
date > $TIME_FILE
@tklee1975
tklee1975 / AppHelper.cpp
Created August 15, 2015 08:18
Determine Debug or Release Build in Code
#include "AppHelper.h"
#include "cocos2d.h"
bool AppHelper::isDebugMode()
{
#if COCOS2D_DEBUG > 0
return true;
#else
return false;
@tklee1975
tklee1975 / AdHelper.cpp
Last active August 29, 2015 18:31
AdMob Helper Classes for iOS
//
// AdHelper.cpp
// TapToJump
//
// Created by Ken Lee on 25/8/15.
//
//
#include "AdHelper.h"
@tklee1975
tklee1975 / AdHelper.java
Last active August 29, 2015 18:50
Cocos2d-x Admob Android Code
package org.cocos2dx.cpp;
import android.app.Activity;
import android.graphics.Color;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.widget.LinearLayout;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdSize;
@tklee1975
tklee1975 / render.cpp
Created September 7, 2015 18:34
Snippet of using RenderTexture with CocosStudio UI
void RenderTexTest::testUsingCocos(Ref *sender)
{
Node *rootNode = CSLoader::createNode("GameOverDialog.csb");
rootNode->setScaleY(-1);
rootNode->setAnchorPoint(Vec2(0, 1.f));
RenderTexture *texture = RenderTexture::create(320, 400, Texture2D::PixelFormat::RGB888);