Spriteを使おう | Webプログラミング!

Time-stamp: "2014-10-14 Tue 19:00 JST hig"

Spriteのサンプル2

Spriteのサンプル2

sprite2.html

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
    <title>Test of Enchant.js</title>
    <style type="text/css">
      body { margin: 0; }
    </style>

    <script type="text/javascript" src="enchant.js"></script>
    <script type="text/javascript" src="plugins/ui.enchant.js"></script>
    <script type="text/javascript" src="sprite2.js"></script>
  </head>
  <body>
  </body>
</html>

sprite2.js

enchant();

window.onload = function() {
    var game = new Game(320,320);
    game.fps = 16;
    game.preload('chara1.png');

    game.onload = function() {
	var bear = new Sprite(32,32);
	bear.image = game.assets['chara1.png'];
	game.rootScene.addChild(bear);
	bear.frame = 7;

	bear.x=30;
	bear.y=50;
	bear.rotation=90;
	bear.scaleX=2;
	bear.scaleY=1;

	bear.addEventListener(Event.ENTER_FRAME, function() {
	    bear.y +=3;
	}
			     );

    };

    game.start();
};

Spriteのサンプル3

Spriteのサンプル3

sprite3.html

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
    <title>Test of Enchant.js</title>
    <style type="text/css">
      body { margin: 0; }
    </style>

    <script type="text/javascript" src="enchant.js"></script>
    <script type="text/javascript" src="plugins/ui.enchant.js"></script>
    <script type="text/javascript" src="sprite3.js"></script>
  </head>
  <body>
  </body>
</html>

sprite3.js

enchant();

window.onload = function() {
    var game = new Game(320,320);
    game.fps = 16;
    game.preload('chara1.png');

    game.onload = function() {
	var bear = new Sprite(32,32);
	bear.image = game.assets['chara1.png'];
	game.rootScene.addChild(bear);
	bear.frame_sequence = [5,6,5,7];
	bear.t=0;

	bear.x=30;
	bear.y=50;
	bear.rotation=0;
	bear.scaleX=1;
	bear.scaleY=1;

	bear.addEventListener(Event.ENTER_FRAME, function() {
	    bear.t=(bear.t+1)% bear.frame_sequence.length;
	    bear.x +=3;
	    bear.frame=bear.frame_sequence[bear.t];
	}
			     );

    };

    game.start();
};

このサイトのコンテンツ

QRcode to hig3.net

https://hig3.net