var res = { back:"res/nawatobi/back.png", back2:"res/galaxy/back.png", sachiko01:"res/nawatobi/sachiko01.png", sachiko02:"res/nawatobi/sachiko02.png", }; var MyLayer = cc.KidspodLayer.extend({ hito:null, hito_Vy:0, tap:0, time:200, timerText:null, ground_y:0, back:null, init:function(){ this._super(); this.scheduleUpdate(); var size = cc.director.getWinSize(); this.back = cc.Sprite.create(res.back); this.back.setPosition(size.width/2, size.height/2); this.addChild(this.back); console.log("start"); this.ground_y = 50; this.hito = cc.Sprite.create(res.sachiko01); this.hito.setPosition(size.width/2, this.ground_y); this.addChild(this.hito); var msg = cc.LabelTTF.create("スペースキーを連打!"+"\n"+"または画面を連続タップ!"); msg.setPosition(size.width/2, 400); this.addChild(msg); this.timerText = cc.LabelTTF.create(this.time+"sec"); this.timerText.setPosition(size.width/2, 370); this.addChild(this.timerText); return true; }, setResult:function() { console.log("setResult called"); var size = cc.director.getWinSize(); var height = this.tap*10; var msgStr = "ジャンプした高さは"+ height +"kmです"; var msg2 = cc.LabelTTF.create(msgStr); msg2.setPosition(size.width/2, 450); this.addChild(msg2); }, update:function(dt){ if (this.time>0) {this.time--;} this.timerText.setString(this.time+"sec"); var size = cc.director.getWinSize(); var hito_x = this.hito.getPosition().x; var hito_y = this.hito.getPosition().y; this.hito.setPosition(hito_x, hito_y + this.hito_Vy); if(this.hito.getPosition().y > this.ground_y) { this.hito_Vy -= 0.1; } else if( this.hito.getPosition().y <= 49) { this.setResult(); this.hito.setPosition(hito_x, this.ground_y); this.hito.setTexture(res.sachiko01); this.hito_Vy = 0; this.unscheduleUpdate(); } }, onMouseDown:function(event) { if(this.time>0){ this.tap++; } else{ this.hito.setTexture(res.sachiko02); this.back.setTexture(res.back2); this.hito_Vy = this.tap; } }, onKeyPressed:function(key, event) { if(this.time>0){ this.tap++; } else{ this.hito.setTexture(res.sachiko02); this.back.setTexture(res.back2); this.hito_Vy = this.tap; } }, onTouchBegan:function(touch, event) { if(this.time>0){ this.tap++; } else{ this.hito.setTexture(res.sachiko02); this.back.setTexture(res.back2); this.hito_Vy = this.tap; } }, onAccelerometer:function(accelero, event) { }, }); var MyScene = cc.Scene.extend({ onEnter:function (){ this._super(); var layer = new MyLayer(); layer.init(); this.addChild(layer); } });