Files
OpenRA/OpenRa.Game/Traits/RenderUnit.cs
Matthew Bowra-Dean fe78e22747 Fixed the building placement to have the cursor in the centre. Replaced magic numbers with Game.CellSize
Using the building footprint, the placement overlay is offset from the cursor so the cursor is in the approximate middle of the overlay (not precisely due to overlay snapping to tiles). The tile size (24) was used as a magic number in a lot of places, they have been replaced with Game.CellSize.
2009-10-15 03:16:44 +13:00

33 lines
937 B
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OpenRa.Game.Graphics;
using IjwFramework.Types;
namespace OpenRa.Game.Traits
{
class RenderUnit : RenderSimple
{
public RenderUnit(Actor self)
: base(self)
{
anim.PlayFetchIndex("idle", () => self.traits.Get<Mobile>().facing);
}
protected static Pair<Sprite, float2> Centered(Sprite s, float2 location)
{
var loc = location - 0.5f * s.size;
return Pair.New(s, loc.Round());
}
public override IEnumerable<Pair<Sprite, float2>> Render(Actor self)
{
var mobile = self.traits.Get<Mobile>();
float fraction = (mobile.moveFraction > 0) ? (float)mobile.moveFraction / mobile.moveFractionTotal : 0f;
var centerLocation = new float2(12, 12) + Game.CellSize * float2.Lerp(mobile.fromCell, mobile.toCell, fraction);
yield return Centered(anim.Image, centerLocation);
}
}
}