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.

Dec 21, 2012

OkaTimer is released



OkaTimer is timer application for doing your task more quickly.
It display the target time and elapsed time from start.
You can use this application by either desktop or smartphone.

Usage

  1. After input to task name and choose target times, push start button.
  2. You can switch RUN and Stop by toggle switch.
  3. Finish your task, check the elapsed time.
  4. If you want next task, push back button and input next one.

Notice

  • This application can runs one task only.
  • Target time is limited from "0h 5min" to "24h 55min".
  • No alert when the smartphone is slept.

Contact

Dec 20, 2012

Janken Shooting is released


    I released Janken Shooting on GitHub.
    http://yokano.github.com/JankenShooting/

    It is browser game for Google Chrome written by Javascript.
    And it working on Google App Engine.

    You can see source codes form my GitHub page.

Nov 30, 2012

How to hide the keyboard when user taps the return key

     When user taps UITextField object, then soft keyboard appears from bottom. But there is no way to hide the keyboard by default. Let's make hide the keyboard when user taps the return key.

 

     We can be achieved in 4 steps.
  1. Set ViewController as delegate of UITextField
  2. Adopt UITextFieldDelegate Protocol
  3. Get a message of return key from UITextField
  4. Hide the keyboard

1. Set ViewController as delegate of UITextField

     UITextField object sends a message for its delegate when user taps the return key. First, we set VewController as the delegate. 

     Please open Xcode, and click a storyboard file. And drag from UITextField to ViewController while holding down the control key. There is a blue line on screen while you holding down the control key.



     Click "delegate" from pop up menu.


     OK. It's done. You can look see the connection of delegate on Utilities pane.



2. Adopt UITextFieldDelegate Protocol

     UITextField and its delegate communicate each other with UITextFieldDelegate Protocol. Adopt UITextFieldDelegate protocol to ViewController by writing following code.
#import <UIKit/UIKit.h>
@interface TaskViewController : UIViewController <UITextFieldDelegate>
@end
     UIViewController declared that is adopting UITextFieldDelegateProtocol itself.

3. Get a message of return key from UITextField

     UITextField sends "textfieldShouldReturn:" message to its delegate when user taps the return key.  Now, implement to this method to confirmation whether a message has actually arrived. Edit ViewController as below.

     xxxxViewController.h
#import <UIKit/UIKit.h>
@interface TaskViewController : UIViewController  <UITextFieldDelegate>

// ADD HERE
- (BOOL)textFieldShouldReturn:(UITextField *)textField;

@end

     xxxxViewController.m
#import "TaskViewController.h"

@interface TaskViewController ()

@end

@implementation TaskViewController

// ADD HERE
-(BOOL)textFieldShouldReturn:(UITextField *)textField {
 NSLog(@"tapped return key!");
 return YES;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
}

@end
     Run this code, and tap UITextField. When you tap the return key, log is output in debug area.



4. Hide the keyboard

     Finally, add the process of hiding the keyboard. Edit textFieldShouldReturn: method as below.
-(BOOL)textFieldShouldReturn:(UITextField *)textField {
 [textField resignFirstResponder];
 return YES;
}
     If we want to hide the keyboard, send resignFirstResponder: message to the keyboard object.

References - iOS Developer Library