ja.TextClass | jAction

ja.TextClass



文字を表示する、テキストオブジェクトを生成するためのクラス。

使うときは、ja.TextClassをnewで生成して使います。

作られたテキストオブジェクトは画像オブジェクトで、他の画像オブジェクトにaddChildして使いますが、テキストオブジェクトに他の画像オブジェクトをaddChildする事はできません。

(例)var textObj = new ja.TextClass();

 

プロパティ値

px    : テキストの文字の大きさ(文字列)フォント指定 : フォント指定(文字列)

x : X座標(ピクセル)

y : Y座標(ピクセル)

color : 文字の色(16進を文字列で記入)

text : 表示する文字t列

 

・ポイントの指定
textObj.px = ポイント指定

 (例)textObj.px = “18px”;

・文字の色の指定
textObj.color= 色の指定(16進)

(例)textObj.color= “#FFFFFF”;

・座標指定
textObj.x = X座標
textObj.y = Y座標

(例)textObj.x = 150;

・表示する文字列の指定
textObj.text = 文字列

(例)textObj.text = "これはテストです。";
  • http://www.facebook.com/people/Yoshihiro-Kimura/100000040801410 Yoshihiro Kimura

    たびたびすみません。これまた趣味の問題なのかもしれませんが・・、
    またまた感想です。

    できれば、オブジェクトは

    text1= new TextClass({
    x : 110,y : 220
    text : “効果音を再生する”})

    ============= (coffeescriptでは) ===========
    text1= new TextClass
    x : 110
    y : 220
    text : “効果音を再生する”
    ========================================
    と言った風に初期化できれば素敵、と思います。
    ※JSONで指定する変数は、任意に省略可)

    これは、例えば、
    TextClass= function(J) {
    var _ref, _ref2, _ref3, _ref4, _ref5, _ref6, _ref7;
    this.px = (_ref = J.px) != null ? _ref : “18px”;
    this.font = (_ref2 = J.font) != null ? _ref2 : “‘MS Pゴシック’”;
    this.fillStyle = (_ref3 = J.fillStyle) != null ? _ref3 : “#000000″;
    this.x = (_ref4 = J.x) != null ? _ref4 : 0;
    this.y = (_ref5 = J.y) != null ? _ref5 : 0;
    this.text = (_ref6 = J.text) != null ? _ref6 : “”;
    this.visible = (_ref7 = J.visible) != null ? _ref7 : true;
    this.draw = function() {
    var rate, ua;
    if (this.visible) {
    context.save();
    ua = navigator.userAgent;
    if (ua.indexOf(“Android 2.1″) > 0) {
    rate = Math.sqrt(320 / screen.width);
    context.scale(rate, rate);
    }
    context.font = this.px + ” ” + this.font;
    context.fillStyle = this.fillStyle;
    context.globalAlpha = this.alpha;
    context.fillText(this.text, this.x, this.y);
    context.restore();
    }
    };
    };

    と定義すると実現できます。

    ============= (coffeescriptでは) ===========
    TextClass = (J)->
    @px = J.px ? “18px”
    @font = J.font ? “‘MS Pゴシック’”
    @fillStyle = J.fillStyle ? “#000000″
    @x = J.x ? 0
    @y = J.y ? 0
    @text = J.text ? “”
    @visible = J.visible ? true

    @draw = ()->
    if @visible
    G.context.save()
    ua = navigator.userAgent
    if ua.indexOf(“Android 2.1″) > 0
    # 縮小
    rate = Math.sqrt(320 / screen.width)
    G.context.scale( rate, rate)

    G.context.font = @px + ” ” + @font
    G.context.fillStyle = @fillStyle
    G.context.globalAlpha = @alpha
    G.context.fillText(@text, @x , @y)
    G.context.restore() #戻す
    return
    return
    =====================================

    自前で試しに定義してみたりしてます、、

  • http://www.facebook.com/people/Yoshihiro-Kimura/100000040801410 Yoshihiro Kimura

    おっと、インデントが反映されないのですね・・読みにくくて失礼です。

  • http://www.facebook.com/people/Akito-Oofuchiwaki/100000970894059 Akito Oofuchiwaki

    お~ ありがとうございます。
    定義の仕方勉強になります。

    実はjavaScriptってあんまりやったことなくて、じゃあなんでjAction書いてるのかというと、ほとんどFlashのActionScript1の知識で構築してます。 やってみると、ほとんど同じなのですが。

    そのFlashは、ActionScript3になって久しいので、まさか今頃その知識が役に立つとは思ってなかった。
    でも、この定義の仕方は知らなかった・・・ これは色々応用効きそうですね。

    色んな情報をいただけると、非常に助かります。
    ありがとうございます。