この文書の現在のバージョンと選択したバージョンの差分を表示します。
両方とも前のリビジョン 前のリビジョン 次のリビジョン | 前のリビジョン 最新リビジョン 両方とも次のリビジョン | ||
wiki:defold2:tips:003 [2017/10/29 12:30] step |
wiki:defold2:tips:003 [2017/11/11 13:31] step |
||
---|---|---|---|
ライン 1: | ライン 1: | ||
- | ====== 公式チュートリアル War battles で学習する ====== | + | ====== 003 公式チュートリアル War battles で学習する ====== |
===== 概要 ===== | ===== 概要 ===== | ||
ライン 460: | ライン 460: | ||
- ui.gui_scriptを開きます。 | - ui.gui_scriptを開きます。 | ||
- | <sxh lua; title: ui.gui_script> | + | <sxh javascript; title: ui.gui_script> |
function init(self) | function init(self) | ||
- | self.score = 0 | + | -- score の変数を定義し0で初期化します。 |
+ | self.score = 0 | ||
end | end | ||
function on_message(self, message_id, message, sender) | function on_message(self, message_id, message, sender) | ||
+ | -- "add_score"メッセージが返された時に | ||
if message_id == hash("add_score") then | if message_id == hash("add_score") then | ||
+ | -- scoreを加算する。 | ||
self.score = self.score + message.score | self.score = self.score + message.score | ||
+ | -- score ノードを取得して、テキストを更新します。 | ||
local scorenode = gui.get_node("score") | local scorenode = gui.get_node("score") | ||
gui.set_text(scorenode, "SCORE: " .. self.score) | gui.set_text(scorenode, "SCORE: " .. self.score) | ||
ライン 475: | ライン 479: | ||
</sxh> | </sxh> | ||
- | + | - add_score メッセージを発火するためのスクリプトをrocket.gui_scriptに書きます。 | |
- | 執筆中.. | + | <sxh javascript; title: rocket.script> |
+ | function on_message(self, message_id, message, sender) | ||
+ | if message_id == hash("animation_done") then | ||
+ | go.delete() | ||
+ | -- Add | ||
+ | elseif message_id == hash("collision_response") then | ||
+ | explode(self) | ||
+ | go.delete(message.other_id) | ||
+ | -- スコアを100点追加。 | ||
+ | msg.post("/gui#ui", "add_score", {score = 100}) | ||
+ | end | ||
+ | end | ||
+ | </sxh> | ||
+ | これでロケットで戦車を倒すとスコアが100点加算される様になります。 | ||
+ | ===== 終わり ===== | ||
+ | - 公式チュートリアルはここで終了しています。 | ||
+ | - なんどもトライ&エラーを繰り返してコツを掴むことが大切です。 |