/** * Draws a world's sprites * * @param world the world to draw */ protected virtual void drawSprites(World world) { foreach (Actor a in world.actors) { //Get actor's texture Handle tex = a.sprite; if (tex == null) { continue; } Texture2D texture = tex.getResource <Texture2D>(); if (texture == null) { return; } //Get the tile actor is on Vector2 spritePos = a.position + a.world2model; Vector2 aMiddle = new Vector2(texture.width / 2, texture.height / 2); Tile t = world.getTileAt(spritePos + aMiddle); //If the tile actor is on isn't visible, don't draw actor if (t == null || t.color.a < 0.00001f) { t = world.getTileAt(spritePos); } if (t == null || t.color.a + world.ambientLight < 0.00001f) { continue; } //Merge the actor's lighting with the tile a.color += (t.getFinalColor() + (a.color * -1f)) * a.colorChangeRate; a.color += world.ambientLight; Color actorTint = a.tint * a.color; //Default drawing if (a.defaultDraw) { drawTex(tex, (int)(spritePos.x + a.xoffset), (int)(spritePos.y + a.yoffset), actorTint); } //Custom drawing (if any) if (a.customDraw != null) { a.customDraw(a); } //Editor erasor selector draw if (engine.editorComponent.isActive && engine.editorComponent.eraseTool.active) { engine.graphicsComponent.drawRect((int)(a.position.x - 2), (int)(a.position.y + (a.diameter / 4)), 4, 4, new Color(1f, 0, 1f)); } } }
/* * Draws a single tile, incrementally if needed * * @param tile the tile to draw * @param viewRect the view to consider */ protected virtual void drawTile(Tile tile, RectangleF viewRect) { if (tile.texture.key != "") { //Get the size of the tile in increments of Tile.size int tilesWide = (int)((float)tile.imageWidth / Tile.size); int tilesHigh = (int)((float)tile.imageHeight / Tile.size); int fTilesWide = tilesWide; int fTilesHigh = tilesHigh; if (tile.xIndex + fTilesWide > tile.world.width) { fTilesWide -= ((tile.xIndex + fTilesWide) - tile.world.width); } if (tile.yIndex + fTilesHigh > tile.world.height) { fTilesHigh -= ((tile.yIndex + fTilesHigh) - tile.world.height); } //Draw the single tile by increments of Tile.size, in order to draw larger-than-a-tile tiles for (int x = 0; x < fTilesWide; x++) { for (int y = 0; y < fTilesHigh; y++) { //Merge the lighting of the current tile and the incremental tile Tile t = tile.world.tileArray[tile.xIndex + x, tile.yIndex + y]; if (t != tile && t.texture.key != "") { continue; } if (t.color.a < 0.0001f) { continue; } //Final tint Color tint = t.getFinalColor();//glowOutput; //getfinalcolor //Get the specific bounds for this increment RectangleF bounds = new RectangleF((float)x * Tile.size / tile.imageWidth, (float)y * Tile.size / tile.imageHeight, (float)Tile.size / tile.imageWidth, (float)Tile.size / tile.imageHeight); Color tint1 = Color.Avg((t.left == null) ? tint : t.left.getFinalColor(), (t.up == null) ? tint : t.up.getFinalColor()); Color tint2 = Color.Avg((t.right == null) ? tint : t.right.getFinalColor(), (t.up == null) ? tint : t.up.getFinalColor()); Color tint3 = Color.Avg((t.left == null) ? tint : t.left.getFinalColor(), (t.down == null) ? tint : t.down.getFinalColor()); Color tint4 = Color.Avg((t.right == null) ? tint : t.right.getFinalColor(), (t.down == null) ? tint : t.down.getFinalColor()); drawTex(tile.texture, t.x, t.y, Tile.size, Tile.size, Color.Avg(tint, tint1), Color.Avg(tint, tint2), Color.Avg(tint, tint3), Color.Avg(tint, tint4), bounds); } } } }