// Manually trigger new rotation
    public void UpdateRotation(Vector2? facingDir = null)
    {
        Vector2 dir = Vector2.zero;

        // Setup direction
        if (facingDir == null)
        {
            // No direction given, take direction from rigidbody
            var rb = GetComponent<Rigidbody2D>();
            if (rb)
            {
                dir = rb.velocity.normalized;
            }
        }
        else
        {
            // Use the direction given
            dir = facingDir.GetValueOrDefault(Vector2.zero);
        }

        if (dir == Vector2.zero)
        {
            // No rotation if no dir
            //transform.rotation = Quaternion.Euler(0, 0, 0);
            return;
        }
        float degree = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg - m_Offset;
        transform.rotation = Quaternion.Euler(0, 0, degree);
    }
Beispiel #2
0
        public void Draw(
            Texture2D texture, Vector2 position,
            Rectangle? sourceRectangle = null, Color? multiplyColor = null, Color addColor = default(Color),
            float rotation = 0, Vector2? scale = null, Vector2 origin = default(Vector2),
            bool mirrorX = false, bool mirrorY = false, float sortKey = 0,
            int? layer = null, bool? worldSpace = null, 
            BlendState blendState = null, SamplerState samplerState = null
        )
        {
            var drawCall = new BitmapDrawCall(texture, position);
            if (sourceRectangle.HasValue)
                drawCall.TextureRegion = texture.BoundsFromRectangle(sourceRectangle.Value);
            drawCall.MultiplyColor = multiplyColor.GetValueOrDefault(Color.White);
            drawCall.AddColor = addColor;
            drawCall.Rotation = rotation;
            drawCall.Scale = scale.GetValueOrDefault(Vector2.One);
            drawCall.Origin = origin;
            if (mirrorX || mirrorY)
                drawCall.Mirror(mirrorX, mirrorY);
            drawCall.SortKey = sortKey;

            Draw(ref drawCall, layer: layer, worldSpace: worldSpace, blendState: blendState, samplerState: samplerState);
        }
Beispiel #3
0
 public PP_BlurGaussian(uint blur = 5, Vector2? offset = null, bool blur2d = true,
                        SurfaceFormat? surface = null, DepthFormat? depth = null, bool mipmap = false)
     : base(surface, depth, mipmap)
 {
     Blur2D = true;
     BlurGauss(blur, offset.GetValueOrDefault(Vector2.UnitX * 0.00125f));
 }
Beispiel #4
0
 public void Draw(SpriteBatch pSpriteBatch, Vector2 pos, float rot = 0, Vector2? v2RotationCenter = null)
 {
     Draw(pSpriteBatch, pos, rot, v2RotationCenter.GetValueOrDefault(), Color.White, SpriteEffects.None);
 }
Beispiel #5
0
 public Image(Texture2D tex, Rectangle? texCoords = null, Vector2? size = null)
 {
     Texture   = tex;
     TexCoords = texCoords;
     Size      = size.GetValueOrDefault(SizeDefault);
 }
Beispiel #6
0
 public void Draw(SpriteBatch pSpriteBatch, Vector2 pos, float rot = 0, Vector2? v2RotationCenter = null, float z = 0)
 {
     Draw(pSpriteBatch, pos + v2RotationCenter.GetValueOrDefault(), rot, v2RotationCenter.GetValueOrDefault(), Tint, SpriteEffects.None, z);
 }