You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
cocos2d-js の場合 Position オブジェクト にはメソッドがない.
そもそも Position オブジェクトの説明に new cc.Position (コンストラクタ) を使わずに cc.p メソッドを使ってと書いてあったことに気づかなかった.今までのコードも直す.
Position を足すには cc.pAdd を使い,
最小/最大を制限した Position を得るにはcc.pClamp を使う.
コールバックの中での this
コールバックの中での this は,そのままだと直感的に考えているような this にならない.
例えば今回の場合でいうと onTouchMoved の this がMainSceneLayer を指していると考えてしまうだろう.しかし,そうはならない.
JavaScript でよくあるハマりどころである.
これを回避するために関数に .bind(this) を追加して(この場合の this は MainSceneLayer を指している)
コールバックの中での this も MainSceneLayer を指すようにする.
イディオム(慣用表現)として,コールバックには全て .bind をつけてしまってかまわない.
The text was updated successfully, but these errors were encountered:
Position に関連した処理
cocos2d-js の場合 Position オブジェクト にはメソッドがない.
そもそも Position オブジェクトの説明に
new cc.Position
(コンストラクタ) を使わずにcc.p
メソッドを使ってと書いてあったことに気づかなかった.今までのコードも直す.Position を足すには
cc.pAdd
を使い,最小/最大を制限した Position を得るには
cc.pClamp
を使う.コールバックの中での this
コールバックの中での this は,そのままだと直感的に考えているような this にならない.
例えば今回の場合でいうと onTouchMoved の this がMainSceneLayer を指していると考えてしまうだろう.しかし,そうはならない.
JavaScript でよくあるハマりどころである.
これを回避するために関数に
.bind(this)
を追加して(この場合の this は MainSceneLayer を指している)コールバックの中での this も MainSceneLayer を指すようにする.
イディオム(慣用表現)として,コールバックには全て
.bind
をつけてしまってかまわない.The text was updated successfully, but these errors were encountered: