Work Records

日々の作業記録です。iPhone・androidアプリなど作っています。http://waremon.parseapp.com/

カウンタ作ってみた

ゲームアプリを作るにあたり、まあまあ必要になりそうなカウンタ。得点とか。
TiledSprite & TiledTextureが便利すぎる。

[使用画像]numbers.png


package org.example.sample;

import android.view.MotionEvent;

import com.e3roid.E3Activity;
import com.e3roid.E3Engine;
import com.e3roid.E3Scene;
import com.e3roid.drawable.sprite.TiledSprite;
import com.e3roid.drawable.texture.TiledTexture;

public class Sample extends E3Activity {

private final static int WIDTH = 320;
private final static int HEIGHT = 480;
private final static int DIGIT = 4;
private int SCORE = 0;
private TiledSprite[] numTile = new TiledSprite[DIGIT];
private TiledTexture numbersTexture;

@Override
public E3Engine onLoadEngine() {
E3Engine engine = new E3Engine(this, WIDTH, HEIGHT);
engine.requestFullScreen();
engine.requestPortrait();
return engine;
}

@Override
public E3Scene onLoadScene() {
E3Scene scene = new E3Scene();
scene.addEventListener(this);
scene.setBackgroundColor(0f, 0f, 0f, 1);

int numbersWidth = numbersTexture.getTileWidth();
int numbersHeight = numbersTexture.getTileHeight();
for (int i =0; i numTile[i] = new TiledSprite(numbersTexture, (WIDTH-numbersWidth*DIGIT)/2 + numbersWidth*i, (HEIGHT-numbersHeight)/2, 0, 0);
scene.getTopLayer().add(numTile[i]);
}
return scene;
}

@Override
public void onLoadResources() {
numbersTexture = new TiledTexture("numbers.png", 40, 40, 0, 0, 0, this);
}

@Override
public boolean onSceneTouchEvent(E3Scene scene, MotionEvent motionEvent) {
if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
SCORE ++;
int TMP_SCORE = SCORE;
for (int i=0; i int NUM = TMP_SCORE / (int)Math.pow(10, DIGIT-i-1);
numTile[i].setTile(NUM, 0);
TMP_SCORE -= NUM*(int)Math.pow(10, DIGIT-i-1);
}
}
return false;
}
}

自作アプリ紹介コーナー
iTunes App Store で見つかる iPhone、iPod touch、iPad 対応 ときめきエキスプレスStation
f:id:kenjiszk:20130706222734p:plain