Things I didn’t know about Cocos2d-x, but I probably could have read in the docs somewhere #1

If you run an Effect, by creating a NodeGrid, and then adding a sprite or something to it, and then each frame, you keep calling runAction on it with a new Effect, it’ll never start, because each action is constantly getting replaced.

To solve this, I added a boolean flag on the object to see if an effect was running or not, and then only ran the effect if the flag was false.

How to add vibration to any cocos2dx 3.3 Android app

I had originally avoided using vibration in my game, because I had found several different posts trying to figure out exactly what you needed to do, and I wasn’t able to find any tutorials that really broke down the process, so I chugged some coffee and dug into the code that was linked on the official forums. forum post. I can’t overstate how helpful it was to have a sub 10 second turn around time, between using Visual Studio to write the code, cocos to compile it (cocos compile -p android) and then to push it to my android phone with adb (adb install -r debug.apk), and then monitoring what was happening with logcat (adb logcat *:w), filtering only for warnings, errors and anything higher). Before we jump into it though, here’s a rough summary:

  1. You need to add a header in your Classes/ folder where you just have the vibrate function declared but not defined.
  2. Add a vibration function definition in the, in a .cpp file. I used , which I believe is the default for a starter cocos2dxv3 project. In this method you call the method you’ve defined in your java, in this case it was defined as a static method on your Activity. The default was named AppActivity .
  3. make sure you’ve got the vibration permission on your , <uses-permission android:name= android.permission.VIBRATE>”

So, in one of your standard C++ headers in the Classes/ folder, add

    void vibrate(int milliseconds);

and in the associated <tt>.cpp</tt> file, call it: 

    void get_hit()

In your , you’ll want to add that line

      <uses-permission android:name="android.permission.VIBRATE"/>

In a cpp file the jni will deal with, say , you’ll need to define the connection between the Java and C++ by calling the Java method:

    /* this function should already exist though */
    void cocos_android_app_init (JNIEnv* env, jobject thiz) {
        AppDelegate *pAppDelegate = new AppDelegate();

    /* this is the new one you're adding, where org/cocos2dx/cpp/AppActivity
       is the java file where your Activity with the vibrate static method is defined
    void vibrate(int milliseconds)
        JniMethodInfo minfo;
        CCAssert(JniHelper::getStaticMethodInfo(minfo, "org/cocos2dx/cpp/AppActivity", "vibrate", "(I)V"), "Function doesn't exist");
        minfo.env->CallStaticVoidMethod(minfo.classID, minfo.methodID, (jint)milliseconds);

Finally, here’s the .java file where the android call to vibrate is made. Mine was

    /* default imports */
    package org.cocos2dx.cpp;

    import org.cocos2dx.lib.Cocos2dxActivity;

    /* imports needed for vibration stuff */
    import android.os.Vibrator;
    import android.content.Context;
    import android.util.Log;
    import android.os.Bundle;

    public class AppActivity extends Cocos2dxActivity {

        private static volatile Cocos2dxActivity mainActivity;
        public static void setMainActivity(Cocos2dxActivity activity)
            mainActivity = activity;

        public static Cocos2dxActivity getMainActivity()
            if(mainActivity == null)
                Log.w("MY_APP_NAME_GOES_HERE", "Warning : null main Activity");
            return mainActivity;

    	protected void onCreate(Bundle savedInstanceState)

        public static void vibrate(int milliseconds)
            Vibrator v = (Vibrator) getMainActivity().getSystemService(Context.VIBRATOR_SERVICE);
            if (getMainActivity().getSystemService(Context.VIBRATOR_SERVICE) != null)

Hope this helped you!

Going from nothing to an employed Python programmer in a few years

This is what I did in about 2 or 3 years of programming, from nothing to employed at a kick ass company.

tl;dr is that I just worked on things over time that I felt to lazy to do myself, or things that interested me, and got going.

When I started out the only library I think I was using was requests and beautifulsoup for making a bunch of web requests. Scraping reddit and downloading wallpapers automatically. I started off wanting to learn how to make a game, so I made a little roguelike in libtcod, which really taught me a bunch of stuff about Python, since I was motivated, and the tutorial on RogueBasin is fantastic.

After a little while of making little scripts like a sleeptimer, I tried making a music player, because I was sick of WMP’s poor shuffling, and Winamp didn’t respect my media keys and since I was on XP at the time, didn’t have that sweet toolbar integration that WMP did. I then moved to working with the Imgur and reddit APIs downloading even more images, making things like detecting if a user has any posts on gonewild and other creepy stuff like that.

I wanted to get back into gamedev, so I learned PyGame to make a topdown shooter but wasn’t happy with the performance (which I now realize is probably due to the way I designed it rather than Python’s fault) but then learned C# because I wanted to make a game on the xbox using XNA.

From there I made a site like in C#s ASP.NET MVC4, learning about web development proper, like how to do anything in HTML, CSS and JS. I also made a few Chrome extensions using that JS knowledge, like one that scrapped Steam for the account history to get an accurate total of the money you’ve spent on your games, before that was integrated into Steam, an extension to count down from when you get into work and pop up 8 hours later and most recently an extension that tweaks Project Free TVs site to make it a bit more readable.

I’ve used the WordPress XMLRPC API via a library to purge spammy posts from my blog, which makes my own life a lot easier because I’m not about to go through 1000 comments a month by hand.

A few years ago I learned how to use vim because I’m super lazy and want to speed up doing everything I do, and I love the idea of getting better at navigating text as I get better at programming.

Last summer I decided I want to do a proper game, to learn C++, a language I always thought was one of those things that a real could do, sorta like how you can’t call your self a car enthusiast without being able to drive stick. So far it’s been a blast, and I’ve got a kick ass site dedicated to the game. It’s actually in the same library that I used to learn python, which is fun.

This all sounds like a lot, now that I’ve laid it out, but its a pretty standard experience for a lot of programmers to just tinker with things they want to play around with, or to automate some things they do every day. I don’t think there’s a fast track to getting employed other than simply working at it day by day.