Created
July 11, 2014 05:00
-
-
Save omas/d56022cb1860a31287e1 to your computer and use it in GitHub Desktop.
enchant Class sample
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| enchant(); | |
| var gs = { //ゲームウィンドウの幅,高さ,fpsを定義 | |
| width:320 | |
| ,height:320 | |
| ,fps:15 | |
| }; | |
| var direction = { | |
| right:1,left:-1 | |
| }; | |
| var ga = {}; | |
| var eSprite = enchant.Class.create(enchant.Sprite,{ | |
| initialize:function(gasset){ | |
| enchant.Sprite.call(this,gasset.width,gasset.height); | |
| this.image = game.assets[gasset.image]; | |
| this.frame = gasset.frame; | |
| game.currentScene.addChild(this); | |
| } | |
| }); | |
| ga.bear = { | |
| image : "images/chara1.png" | |
| ,width: 32 | |
| ,height:32 | |
| ,frame: [5,6,5,7] | |
| ,speed:3 | |
| } | |
| var Bear = enchant.Class.create(eSprite ,{ | |
| initialize:function(){ | |
| eSprite.call(this,ga.bear); | |
| this.speed = ga.bear.speed; | |
| }, | |
| onenterframe:function(){ | |
| if (this.scaleX == direction.right){ | |
| this.x += this.speed; | |
| if (this.x > gs.width - this.width) | |
| this.scaleX = direction.left; | |
| } | |
| else { | |
| this.x -= this.speed; | |
| if (this.x < 0) | |
| this.scaleX = direction.right; | |
| } | |
| } | |
| }); | |
| window.onload = function(){ | |
| game = new Core(gs.width,gs.height); | |
| game.fps = gs.fps; | |
| game.preload(ga.bear.image); | |
| var stage = game.rootScene; | |
| game.onload = function(){ | |
| var bear = new Bear(); | |
| }; | |
| game.start(); | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment