Compiling cocos2d-x on Windows 10 (win32)

Just a quick tip here to share something that needed setting to get cocos2d-x to compile properly for win32. I’m on Windows 10 pro, with Visual Studio Community 2015.

If you see a Timespec redefinition error, add HAVE_STRUCT_TIMESPEC to the preprocessor directives found here:

Project->Properties->C/C++->Preprocessor->Preprocessor Definitions

 

Cocos2d iOS Javascript Bindings and Subclassing

So I started to port the work-in-progress Solar Jetways to iOS this week, to see just how easily the HTML5 code can be ported. It’s been pretty painful so far (again due to a lack of community support I guess), but here’s a very valuable tip for anyone who’s getting “Invalid Proxy object” errors when starting their code. This happens when you’ve subclassed a Cocos2d native class and haven’t then called cc.associateWithNative() in the class constructor. Another gotcha is making sure that the class init() function is called before anything else.

As an example, here’s an excerpt from my subclassed cc.Scene:

var MyScene = cc.Scene.extend({
  ctor:function(){
    cc.associateWithNative(this, cc.Scene);
    this.init();
  },

  onEnter:function () {
    this._super();
    ...

Hope that helps someone. Now back to the ongoing cross-platform coding saga…

Cocos2d HTML5 gl.clearColor (glClearColor)

Just a quick note cos it took me bloody ages to find, but here’s the Cocos2d HTML5 (js) way of setting the GL clear color to something other than black. Originally on the iPhone I’d use glClearColor(), so the equivalent in JavaScript is:

var gl = cc.renderContext;
gl.clearColor(0.5, 0.4, 0.2, 0);

 

The parameters are R, G, B, and alpha as you’d expect.

New Technology – Cocos2D HTML5 and Screen Coordinates

It’s always interesting to start using some new tech, and I’ve just started dabbling with Cocos2d-html5:

http://www.cocos2d-x.org/projects/html5

It’s nice because you now write in JavaScript and easily port your game across iPhone, Android and browser. However, it is *nowhere* near as well-supported by the community as Cocos2D for iPhone is. As such, a particular headache of mine recently has been trying to get accurate screen coordinates from a moving mouse pointer. Bascially I want to orient a sprite to point at the mouse pointer when it’s hovered over the game area. The problem I was having is that the onMouseMoved() event returns the coordinates in the browser window, not the game area. Also, coordinates were in window format rather than the game world, so some conversion was needed there. The following function is my solution (with a little help from the forums), and should return world coordinates when the mouse is hovered. It takes the event passed to onMouseMoved() as a parameter.

convertMouseCoords:function(mouse)
{
    var scale = cc.Director.getInstance().getContentScaleFactor();
    var origin = cc.EGLView.getInstance().getViewPortRect();
    mouse.getLocation().x -= origin.origin.x;
    mouse.getLocation().y -= origin.origin.y;
    mouse.getLocation().x /= scale;
    mouse.getLocation().y /= scale;
    var location = mouse.getLocation();
    // work out proportion into screen of mouse coords, then apply to world dimensions to get "proper" touch location
    size = cc.Director.getInstance().getWinSize();
    var propX = location.x / origin.width;
    var propY = location.y / origin.height;
    location.x = size.width * propX;
    location.y = size.height * propY;
    return location;
}

DoodleBod and Danger Tank! Updates Complete

Well, DoodleBod has received a major update which now means it’s pretty much where I had imagined it would be in terms of functionality. Disappointingly, none of the ~15 iPhone game review sites selected it for review, and in fact only one of them responded at all. The crushing realisation that I may actually have to spend money to get my games noticed is starting to dawn on me… That said, Danger Tank! still gets about 4x as many downloads as DoodleBod, and is the only one that really sells at all (~3 a month at the moment). I’m considering going back to Danger Tank! for another update to add Internet play, which I think my 130 paying customers may appreciate. Also it would be another fine display of my talents for any potential employers :-) In the meantime I’m starting a new project with some new tech (Cocos2d-HTML5) which is cool, I’ll post about that soon. Turrah!

Physics and Stuff

Hello everyone! Been a long time since the last update, I’ve been beavering away on an update for both DoodleBod and Danger Tank! For DoodleBod, I’ve added some new features and tidied up the multiplayer (Game Center) code. It will be submitted to Apple this week. For Danger Tank! I’ve added a new physics engine, so that the in-game objects react (somewhat) realistically to explosions etc. I used the awesome Chipmunk physics library for this:

http://chipmunk-physics.net/

I’m just finishing up with the Danger Tank update and it should be submitted at the end of the week. A small update in terms of sales – DoodleBod isn’t really selling at all in it’s current state, but Danger Tank! continues to shift 3-4 units a month. I’m hoping these updates will stir some purchase activity as they’re great improvements to both games. We’ll see.

On a final technical note, it’s worth mentioning that I had some trouble using chipmunk to get my tanks to move uphill properly. Their wheels kept slipping back down any surface that was more than about a 30 degree incline. Thanks to the very responsive admin “slembcke” from the Cocos2d forums, this was solved quite quickly by increasing the wheel friction to 4. E.g.

wheel.shape->u = 4.0f;

I didn’t realise it could be increased past 1.0!

DoodleBod nears completion

Greetings all! That time has arrived, when the fun of creating a new app gives way to the pain of bug fixing and tidying up the UI :-( However, KingChimp’s second release – DoodleBod – is now in final testing and looks like being released almost exactly on KingChimp’s first birthday! Yay!

To follow will be some more iPhone tech tips I’ve picked up on this project (still learning all the time), including:

  • Game Center integration (turn-based matches)
  • Compression (deflate and byte-packing)
  • Cocos2d RenderTextures
  • Facebook integration
  • In-app purchase
  • Ad integration (Mobclix and Admob)

So expect an epic post once DoodleBod is released to the world.

Danger Tank! v1.2 causes small sales spike

Version 1.2 has been out for a couple of weeks, and its initial release caused a small sales spike :-) I’m guessing this is because the free version now gives a few single-player missions to get stuck into. Total sales have now cleared 70 (woooooooooo!) and I’m looking forward to the 100 sales party where I will be spending part of the profits on a celebratory can of Tennent’s Super. KingChimp now has 3 projects in development (count ‘em!) and I’m hoping the first to be released will be available by the end of May. It’s got a social slant to it, so I’m getting to grips with Facebook integration and all that fun stuff. Laters!

Danger Tank! version 1.1 released, and we reach 50 sales

An update to Danger Tank! has been released that will fix the display issues on iPad. Go ahead and update, let me know if it works for you. It should! A fix for older iPhones and iPods should be out next week, which will add support for iPhone 3G and up, and 2nd generation iPods. However, I don’t really recommend playing it on such old hardware. It’s a bit slow :-) Danger Tank! has now sold 53 copies and counting, which I’m pretty pleased with as I haven’t yet started to try and push it online. That said, sales are threatening to flatline any day now…

Danger Tank! is now available on the App Store

EDIT: Also, it appears that the full version can be downloaded for older iPhones and iPods, which wasn’t supposed to happen! My apologies again if this has affected you, an update should be out next week which will fix the game for you. All I can say is it’s been a learning experience, especially where Apple’s surprisingly lax review process is concerned. Sorry!

Danger Tank! was accepted this week, and both versions are now available globally on the App Store.

http://itunes.apple.com/uk/artist/kingchimp/id484075771

In some very exciting news, 9 downloads have already been made for the free version across the USA, Canada and Mexico, and I have a single customer who bought the full one in the USA (but actually I think that might be an error and in fact it’s my friend Andy)… Anyways, please try it out if you have an iPhone 4 or above, any iPad, or a 4th-generation iPod Touch. Check out the YouTube video on the Danger Tank! page of this site.

Happy blasting!