ホームに戻る
 enchant.js のサンプル

// 左右キー、zキー、マウスクリックに反応

enchant();

window.onload = function()
{
  var game = new Game(200, 100);
  game.fps = 5;
  game.rootScene.backgroundColor = 'rgb(255, 255, 255)';
  game.keybind(90, 'a'); //z
  game.preload('shikaku.gif');
  game.onload = function(){
    var xPos = 0;
    var circles = [];

    for(var i = 0; i < 6; i++){
      var circle = new Circle(game);
      circle.x = 0;
      circle.y = i * 16;
      circles.push(circle);
      game.rootScene.addChild(circle);
    }

    game.rootScene.addEventListener('enterframe', function(){
      if(game.input.left){
        xPos = 0;
      }
      else if(game.input.right){
        if(xPos < 100){
          xPos++;
        }
      }
      else if(game.input.a){
        xPos = Math.random() * 100;
      }
      for(var i = 0; i < circles.length; i++){
        circles[i].x = xPos;
      }
    });
  }
  game.start();
}

var Circle = Class.create(Sprite,
{
  initialize : function(game)
  {
    Sprite.call(this, 16 ,16);

    this.image = game.assets['shikaku.gif'];
    
    this.addEventListener(Event.TOUCH_START, this.onTouch);
  },
  
  onTouch : function(){
    this.frame++;
  }
});

inserted by FC2 system