java - Draw Enum values assigned to Sprite -
I am using a game in LibGDX and I've got 2 squares and an honman. My name looks like this:
public enum items {pen, glass, and, SO, ON; Private static item current = pen; Public static item getNext () {current = values () [current.ordinal ()]; Current return; }
In my first category, there are pieces of my game map, where some of them are started with value from the enum with this constructor:
Public Square Mappies {Private Sprite Phantom; Private item items; Public Mappings (Sprite Phantom, Item Items) {this.sprite = sprite; This.item = item; }
This category has a draw function that looks like this:
public zero draw (batch batch, float x, float y) {sprite . Set post (x, y); Sprite.draw (batch); } In the previous class I initialize pieces of my map and put them in 2D array like this: Code> Atlas = new texture Atlas ("Atlas Peak"); Map fragments [0] [0] = new mappits (AtlasCriteSite ("piece"), items .getNext (); map pieces [0] [1] = new mappiece (atlas.createSprite ("piec2"), item. GetNext ();
... and so on until I add all your pieces
The contents of the item are created like this:
For (item i: Item: Properties ()) {Edit Sprite Item = Atlas. Creditsprit ());
Here are the batch types:
int mapPieceSize = 100; for (int i = 0; i
Now for my problem. There are pieces but all are transparent, except for midday, where there is an item. I have made it so that it can make the situation easier.
What do I want to do, a phantom of the above objects To draw that map Detachment which assume the value of the item. For example, if I put mapPiece [0] [5]
value value PEN
then I want to get texture from my atlas
PEN
and then drag it to the same position as mapPiece [0] [5]
. I hope all this is not very misleading.
I am not completely convinced that I still understand this problem because I am not sure That's harder than what you've already done, but I think you can do this to do this.
Add texture area area to enum (not static)).
public enum items {pen, glass, and, SO, ON; Private static item current = pen; Public static item getNext () {current = values () ([current.ordinal () + 1)% value (). Length]; Current return; } Public Texture Area; }
Immediately after loading the atlas fill in your texture fields in enum instances.
Item.PEN.region = atlas.findRegion ("PEN"); item. GLASS.region = atlas.findRegion ("glass"); ...
And then when looping through the pieces of your map, drag the background tile, and the item's tile:
int mapPieceSize = 100; (Int i = 0; iPoce.length; i ++) for {int j = 0; j & lt; map grid [0]. Length; j ++) {// you Typo on line map [j] [ii] .sprite.draw (spratbatch, i * map grossy, j * map psecec); // A sprite frequency spriteBatch.draw (map piece [j] [ii] ITM area, I * map pieces, J * draw texture area directly without the use of map piesize;}}
In addition, you have mentioned that there is a bunch of invisible padding around your items, this invisible pixel can ruin the performance by placing a lot of depiction. If you want to move in and want to change your position You are you Examples of the can offset store or drawing for each Mappis example before time can add the X and Y locations.
Comments
Post a Comment