Hello,
I would like to create 6x6 board with toggleable sprites. They should be next to each other. On andEngine I base on anchorCenter which is (.5f,.5f) by default in every new object.
On andEngine I arrange it like this
for (int i = 0; i < BOARD_ROW; i++) {
for (int j = 0; j < BOARD_COLUMN; j++) {
Letter rLetter = rollLetter ();
float texWidth = rLetter.sprite.rect.width;
float texHeight = rLetter.sprite.rect.height;
Debug.Log (texWidth + "x" + texHeight); // 50 x 50
//Here I'm not sure which convert I should use. 2.5f because it's 2.5 texture width (50*2.5) form layer/scene center. It would be .5 if I want 2x2 board.
rLetter.position = Camera.main.ScreenToWorldPoint (new Vector2 ((-(texWidth * 2.5f) + (texWidth * j)), (texHeight * 2.5f) - (texHeight * i)));
lettersOnScreen.Add (rLetter);
}
}
And I got some thing like this
![alt text][1]
![alt text][2]
I can live with (0,0) on down left corner but space between sprites is too big.
Letter class
class Letter
{
private GameObject gameObject;
public Vector2 position {
get {
return this.gameObject.transform.localPosition;
}
set {
this.gameObject.transform.localPosition = value;
}
}
public Sprite sprite {
get;
set;
}
public BoardPosition boardPosition {
get;
set;
}
public float likelihood {
get;
set;
}
public Range likelihoodRange {
get;
set;
}
public string code {
get;
set;
}
public bool clicked {
get;
set;
}
public Letter ()
{
}
public Letter (GameObject go)
{
this.gameObject = go;
}
public Letter (Sprite sprite, string code, float likelihood, Range likelihoodRange)
{
this.sprite = sprite;
this.code = code;
this.likelihood = likelihood;
this.likelihoodRange = likelihoodRange;
}
BoardPosition getBoardPosition ()
{
return boardPosition;
}
void setBoardPosition (BoardPosition boardPosition)
{
this.boardPosition = boardPosition;
}
}
Can you tell me what I'm doing wrong?
[1]: http://i.imgur.com/cspCLqu.png
[2]: http://i.imgur.com/sVq6iio.png
↧