CocosCreatorをVer1.9.4からVer2.0.4に
アップデートしてから
作成したデータがうまく動かなかったのを修正しました。
(一部、V2.0.5)
今回載せる項目は少ないですが、参考に。
−−−−−−−−−−−−−−−−−−−−
*2018/11/20 14:52 追記*
■cc.randomMinus1To1()
こちらに関してはJavaScriptで
Math.random()があるのでそちらを使う方が
非推奨だとか廃止になりにくそうなので良いのではないかと
思っております。
例:Math.floor(Math.random()*range);
※rangeは乱数の範囲
−−−−−−−−−−−−−−−−−−−−
■[廃止]getVisibleSize()
×cc.director.getVisibleSize().width
×cc.director.getWinSize().width
○cc.winSize.width
┗別の例として
var wsize=cc.winSize;
wsize.width(height);
winSizeの場合は()は不要なので注意。
━━━━━━━━━━
■[廃止]getPositionY()
×(Node).getPositionY()
○(Node).getPosition().y
━━━━━━━━━━
■AudioClip(こちらはV2.0.5で確認)
旧仕様×url:cc.AudioClip
新仕様○type:cc.AudioClip
(urlで出ていた警告等が消えます)
━━━━━━━━━━
■[廃止]listener(eventManager)
(動くが不安定なので早急に変更する必要あり)
-----廃止サンプル-----
(以下、使用してはいけないコレダメ)
var self=this;
cc.eventManager.addListener({
event:cc.EventListener.TOUCH_ONE_BY_ONE,
swallowTouch:true,
onTouchBegan:function(touch,event){
//処理
return true;
}
},self.node);
-----ここまで-----
**新仕様**
#(node | cc.system).onを使用
◆キーボード入力
cc.systemEvent.on(cc.SystemEvent.EventType.KEY_DOWN,function(event){
cc.log("KEY_DOWN ="+event.keyCode);
},this);
もしくは
cc.systemEvent.on(cc.SystemEvent.EventType.KEY_DOWN,this.myFunc,this);
myFunc(event){
cc.log("hogehoge ="+event.keyCode);
},
※第二引数に直接function関数を書けるが
個人的には別に関数を作ってやって、そちらに飛ばす方が
再利用も出来るし、リスナーをremove(off)する際に
楽なのではと思う。
◆タッチ・マウスダウン
this.node.on(cc.Node.EventType.TOUCH_START,function(event){
cc.log("TOUCH_START");
},this);
*マウスダウン
cc.Node.EventType.MOUSE_DOWN
(this.node.on(cc.Node.EventType.MOUSE_DOWN,[関数],[target]))
*マウスダウンのもう一つのやり方
this.node.on('mousedown'〜
(this.node.on('mousedown',[関数],[target]))
ちなみにコレダメのやり方でシーン移動などをすると
前のシーンのリスナーが生きてて、遷移後のシーンで
変に動いてシーン移動を繰り返すっていうアホな挙動にwww
(V1.9.4では正常に動作していたモノと記憶している)
さらに途中でリスナーが消えるwwwww(エラー発生)
TOUCH_STARTはflashでいう「onPress」、
TOUCH_ENDはflashでいう「onRelease」
なのではないかという感じ。
参考URL
[getWinSize]
http://docs.cocos2d-x.org/creator/manual/en/release-notes/upgrade-guide-v2.0.html
[winSize]
https://discuss.cocos2d-x.org/t/solved-how-to-get-size-of-drawable-area-of-view/32552/5
[getPosition]
http://docs.cocos2d-x.org/creator/api/en/classes/Node.html#getposition
[入力・タッチ等]
http://docs.cocos2d-x.org/creator/manual/en/scripting/internal-events.html
他:(CocosCreator、Exampleデータ)