0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Lanica Platino を使ってみる(タッチイベント)

Last updated at Posted at 2013-11-01

セットアップが終わり、Platinoが動くようになったので、少しいじってみる。
画面に赤い四角が表示されている状態なので、このSpriteにタッチイベントを付けることにする。

Spriteにタッチイベント

「Platino.ruble」で作成されたプロジェクトの中を見ると、以下の3つのJSファイルができている。

  • app.js
  • ApplicationWindow.js
  • HomeScene.js

app.js

アプリを実行すると最初に呼ばれる、Titaniumのいつものやつ。特に変更しない。

ApplicationWindow.js

Platinoの基本設定周りを記述するJSっぽい。FPSとか画面サイズとか諸々を設定できそう。
必要に応じて変更する必要がありそうだが、とりあえずそのまま。

HomeScene.js

最初のシーンとなるファイル。ApplicationWindow.jsから呼ばれている。今回はこれを変更。


さて、HomeScene.jsの中を見てみると、赤い四角はcreateSpriteで作成しているっぽい。

HomeScene.js
red = platino.createSprite({
    width: 64,
    height: 64
});

API DocumentでSpriteの項目を見てみると、なんかtouch系のイベント(touchend, touchmove, touchstart)がありそうなのでやってみる。

HomeScene.js
red.addEventListener("touchstart", function(e) {
    Ti.API.info("red " + e.type + " : x=" + e.x + "y=" + e.y);
});

…なんかダメっぽい。改めてサンプルを参考にしてみる。
Events Sample Codeっていうのを見てみると、どうも直接Spriteにtouchイベントを付けられないみたい。

gameViewにtouchイベントを付ける必要がありそうなので、以下のように修正

HomeScene.js
red.addEventListener("touchstart", function(e) {
    Ti.API.info("red " + e.type + " : x=" + e.x + "y=" + e.y);
});

game._touches = {
    red : red
};
game.addEventListener("touchstart", function(e) {
    if (this._touches.red.contains(e.x, e.y)) {
        this._touches.red.fireEvent(e.type, e);
    }
});

[参考にしたソース] (https://github.com/Lanica/Platform/blob/master/platino/Engine/Events/Resources/MainScene.js)

以上

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?