今日のメニュー
・カウントダウン画面実装
・つぶやき機能にハッシュタグ実装
カウントダウン画面について
ゲーム画面に入る前にカウントダウン画面を挟みました。
この画面はあたらしいシーンとして定義作成し、
pushScene関数を使用して、ゲームシーンの上にかぶせています。
この時、カウントダウンシーンの背景に透明度の高い色を設定することで、
ゲームシーンをすかしてみせることができます。
このシーンのコードは以下の感じ
var createPrepareScene=function(){
game.fps=24;
var scene=new Scene();
scene.backgroundColor='rgba(0,0,0,0.7)';
const preCount=25;
var count=preCount;
var threeCount=2;
const quarterOfWindow=(WIDTH+CONTROLWIDTH)/4;
const height=HEIGHT/2;
var countChara=new Array();
for(var i=0;i<3;i++){
countChara.push(new Sprite(CHARASIZE,CHARASIZE));
countChara[i].image=game.assets['./img/charTip8dir.png'];
countChara[i].x=quarterOfWindow*(i+1)-CHARASIZE/2;
countChara[i].y=height-CHARASIZE/2;
scene.addChild(countChara[i]);
}
/*
var threeSprite=new Sprite(64,64);
threeSprite.image=game.assets['./img/charTip8dir.png'];
threeSprite.x=quarterOfWindow-CHARASIZE/2;
threeSprite.y=height;
scene.addChild(threeSprite);
var twoSprite=new Sprite(64,64);
twoSprite.image=game.assets['./img/charTip8dir.png'];
twoSprite.x=threeSprite.x+quarterOfWindow;
twoSprite.y=height;
scene.addChild(twoSprite);
var oneSprite=new Sprite(64,64);
oneSprite.image=game.assets['./img/charTip8dir.png'];
oneSprite.x=twoSprite.x+quarterOfWindow;
oneSprite.y=height;
scene.addChild(oneSprite);
*/
scene.onenterframe=function(){
count--;
if(count<0){
count=preCount;
threeCount--;
if(threeCount<0){
game.popScene();
}
}
if(threeCount>=0){
countChara[threeCount].frame=(countChara[threeCount].frame+1)%8;
countChara[threeCount].opacity=count/parseFloat(preCount);
}
};
return scene;
};
えんしゅつはてきとう
ハッシュタグ
昨日時点ではプリセットのつぶやきにハッシュタグをつけられずなやんでいました。
プリセットの文章はURLに書く事で設定できるのですが、
その文章に空白文字が入れられなかったのが原因でした。
この問題はURLをエンコードすれば解決するということを友人に教えてもらいました。
URLをエンコードすると日本語などの文字が全て置換され、%などを使用した文字列になります。
この状態では空白文字は置換されているため問題になりません。
実際のコードは以下のかんじ
tweetButton.addEventListener(Event.TOUCH_START,function(){
const hashtag=' #picoSnakeGame';
const gameUrl=' ';
var score=count+'人の子供達を育て上げました!';
var tweetText=encodeURIComponent(score+hashtag+gameUrl);
var url="https://twitter.com/share?text="+tweetText+"&";
var features='width=650, height=450, menubar=no, toolbar=no, scrollbars=yes';
var win = window.open(url,"twitter-share-button",features);
});
URLのエンコードについて参考
flat memo JavaScriptでURIエンコード(URLエンコード)を行う