Jun 20, 2013

Use multiline strings with Go

 For decelerate the string that contain line breaks, you close back quart.
 If you use the double quart, it arise error.
// string of multiline
var str string
str = `Welcome!
Multi lines message!
Good job!`


You can put the back quart by Shift + @ if you use Mac.



Jun 19, 2013

Go can't looks static files on GAE

 My work was disrupted by the problem that can't read files in static_dir from Go scripts.

 Be careful to below points.
  • Set "static" to files that are readed by web browsers from a user.
  • Must not set "static" to files that are read by go scripts.
 Files in static_dir can not  read  by go scripts. these read by web browsers.

by Google App Engine documents
For efficiency, App Engine stores and serves static files separately from application files. Static files are not available in the application's file system. If you have data files that need to be read by the application code, the data files must be application files, and must not be matched by a static file pattern.

 Therefore, must not put html files to static_dir if you will output a html file dynamically by use of template package.

Jun 18, 2013

Color Go source codes in Xcode 4.x

By default, Xcode does not syntax hightlight.
But, we can configure in the following way.

HOW TO
  1. Download the shell script
  2. Config the path
  3. Execute the shell script
  4. Check

1. Download the shell script

The script that empower Xcode syntax highlighting is distributed.

Download go4xcode.sh  from here.

There is no need to download go.sclangspec, because it is contained in SDK of Google App Engine.
By default, it is here.
/Applications/google_appengine/goroot/misc/xcode/4/go.xclangspec


2. Config the path

The script uses the environment variable $GOROOT.
Check whether it is configured correct path.
$ su
$ echo $GOROOT
If displayed path to goroot, there is no problem.
If else, set the path to goroot.
$ export GOROOT=/Applications/google_appengine/goroot/


3. Execute the shell script

Let's execute the shell script.
$ sh go4xcode.sh
Backing up plugindata file.
Adding Go language specification entry.
Duplicate Entry Was Skipped: Xcode.SourceCodeLanguage.Go
Installing Go language specification file for Xcode.
Run 'sudo rm -rf /var/folders/*' and restart Xcode to update change immediately.
Syntax coloring must be manually selected from the Editor - Syntax Coloring menu in Xcode. 

Remove trashes according to message.
$ rm -rf /var/folders/*

it's complete.


4. Check

Launch the Xcode.
If installing is succeed, there is a new menu Editor -> Syntax Coloring -> Go.



When click this, Xcode syntax highlighting source code.
But this is not configure automatic.

Apr 21, 2013

Apply the MIT License to software

This is a method to publish software that applied the MIT License.
In order to declare the software license,

  • Describe license in the file header comment
  • Include license text as text file
  • Display license text on the installer

And so on.

An easy way is to include text file.
Template of the MIT license is open to the public at the following websites.

Open Source Initiative
http://opensource.org/licenses/mit-license.php

Japanese translation by Open Source Group Japan
http://sourceforge.jp/projects/opensource/wiki/licenses%2FMIT_license

Copy the template and put your name in , and put also development year in
Save the file as "LICENSE.txt" and distribute software, and this method is complete.

Apr 20, 2013

Loop playback BGM with enchant.js

This is how to loop playback the BGM with enchant.js.

// Loop playback the bgm
game.assets['bgm.mp3'].play();
game.assets['bgm.mp3'].src.loop = true;

Be careful because loop parameter must set after play.

// This case not loop playback the bgm
game.assets['bgm.mp3'].src.loop = true;
game.assets['bgm.mp3'].play();

Apr 19, 2013

Trim images with Preview of Mountain Lion

This method is convenient to removing blank spaces from images.

Open the image with Preview.


Click the pencil icon to show tools.


Click the magical stick icon (instant alpha). If the icon is invisibility, widen window.


Drag area that you want remove, and make selected.


Press the Delete key and remove the area.


You can invert the selected area by command + shift + I.

Select the blank space with magical stick.

Press command + shift + I and invert the area.
You can remove the area that not selected by command + K.

Mar 13, 2013

Line-height is ignored on Canvas


    You can't set line-height on HTML5 Canvas. You can set the font of canvas in the same manner as CSS, but number of line-height is ignored.

    I bump into a this problem.

// output statements are skipped.
var message = 'Where is a pig! I am very hungry... Give me a pig!';
var label = new Label();
label.color = 'black';
label.text = message;

// both font-size and line-height are 75px, but those are ignored.
label.font = '75px/75px fantasy';

game.currentScene.addChild(message);


On Canvas API Specification, line-height number is automatically set 'normal'.
I done deal in such a way as to using array by hand.


var messages = [
    'Where is a pig!',
    'I am very hungry...',
    'Give me a pig!'
];
for(var i = 0; i < messages.length; i++) {
    var label = new Label();
    label.color = 'black';
    label.text = message;
    label.font = '75px fantasy';
    label.y = 75 * i;  // 手動で高さを調整
    game.currentScene.addChild(message);
}

Reference
- W3C HTML Canvas 2D Context, Level 2 Nightly 
http://www.w3.org/html/wg/drafts/2dcontext/html5_canvas/#text-styles

Feb 15, 2013

Minesweeper Gyakushiki

    I published a new browser game, "Minesweeper Gyakushiki". Gyakushiki is a japanese word that meanes "Reverse". Bombs are shown on display from the start of game. Your object is to open all number panels. This game is compatible with PC and SmartPhone. And it's MIT License.


    Source codes are opend on github page. The game is powered by enchant.js that is JavaScript library for HTML5 browser games from japan.