topical media & game development
mobile-graphic-enchant-examples-plugins-box2d-main.js / js
enchant();
var game, physicsWorld;
window.onload = function () {
game = new Game(320, 320);
game.fps = 30;
game.preload("mobile-graphic-enchant-examples-plugins-box2d-chara1.gif", "mobile-graphic-enchant-examples-plugins-box2d-icon1.png", "mobile-graphic-enchant-examples-plugins-box2d-map2.gif");
game.onload = function () {
physicsWorld = new PhysicsWorld(0, 9.8);
for(var i = 0; i < 20; i++){
//床を生成
var floor = new PhyBoxSprite(16, 16, enchant.box2d.STATIC_SPRITE, 1.0, 0.5, 0.3, true);
floor.image = game.assets["map2.gif"];
floor.frame = 2;
floor.position = { x: i*16, y: 300 };
game.rootScene.addChild(floor);
}
game.rootScene.addEventListener("enterframe", function () {
physicsWorld.step(game.fps);
if(game.frame % game.fps == 0){
//ボールを生成
var ball = new PhyCircleSprite(8, enchant.box2d.DYNAMIC_SPRITE, 1.0, 0.5, 0.2, true);
ball.image = game.assets["mobile-graphic-enchant-examples-plugins-box2d-icon1.png"];
ball.frame = 4;
ball.position = { x: 0, y: 120 };
ball.applyImpulse(new b2Vec2(Math.random(), 0));
game.rootScene.addChild(ball);
ball.addEventListener("enterframe", function(){
if(ball > 320)ball.destroy();
})
}
});
game.rootScene.addEventListener("touchstart", function (evt) {
//ボールを生成
var ball = new PhyCircleSprite(8, enchant.box2d.DYNAMIC_SPRITE, 1.0, 0.5, 0.2, true);
ball.image = game.assets["mobile-graphic-enchant-examples-plugins-box2d-icon1.png"];
ball.frame = 3;
ball.position = { x: evt.x, y: evt.y };
ball.applyImpulse(new b2Vec2(Math.random() * 0.1, 0));
game.rootScene.addChild(ball);
ball.addEventListener("enterframe", function(){
if(ball > 320)ball.destroy();
})
});
};
game.start();
};
(C) Æliens
04/09/2009
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.