Ok I am using unity3D and the Futile framework. I have everything drawing and working correctly with Futile, but I am trying to attach a circle collision class to the FSprite that I have. I must be missing something but I have tried everything I can think of.
Right now, it positions itself offset from the center of the texture. The picture below shows what I am talking about. (The blue circle filled circle is my round Planet and the red circle is the circle class)

Below is my Planet class constructor
public Planet(string texture, Vector2 position, Team team, Level level = Level.One)
: base(texture)
{
Debug.Log("Texture Rect width: " + this.textureRect.width.ToString());
//this.anchorX = .5f;
//this.anchorY = .5f;
this.Position = position;
collision = new Circle(this.textureRect.width / 2, this.Position);
collision.Position = this.Position;
FAtlasManager am = Futile.atlasManager;
levelOneTexture = am.GetElementWithName("Circle.png");
levelOneTexture = am.GetElementWithName("Planet_1.png");
levelTwoTexture = am.GetElementWithName("Planet_2.png");
levelThreeTexture = am.GetElementWithName("Planet_3.png");
ChangePlanetTeam(team);
ChangePlanetLevel(level);
SetPlanetLevelTexture(level);
float rot = RXRandom.Range(0, 2 * Mathf.PI);
this.rotation = rot;
}
And here is my Circle class
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
public class Circle
{
private float radius = 1f;
private Vector2 position = Vector2.zero;
private Vector2 origin = Vector2.zero;
public float Radius
{
get { return radius; }
set { radius = value; }
}
public Vector2 Position
{
get { return position; }
set
{
float x = value.x + Radius;
float y = value.y + Radius;
position = new Vector2(x, y);
//position = value;
}
}
public float X { get { return Position.x; } }
public float Y { get { return Position.y; } }
public Circle(float radius, Vector2 position)
{
Debug.Log("Circle position: " + position.ToString());
this.Position = position;
this.radius = radius;
Debug.Log("Radius: " + radius.ToString());
}
public void DrawRadius()
{
Debug.DrawLine(new Vector3(this.X, this.Y, 0), new Vector3(this.X + Radius, this.Y + radius,0));
}
/// <summary>
/// Test if two circles are currently colliding.
/// </summary>
/// <param name="a">One of the circles to test</param>
/// <param name="b">The other circle to test</param>
/// <returns>True if collision is present</returns>
public static bool CircleToCircleCollision(Circle a, Circle b)
{
return ((a.Radius + b.Radius) > Vector2.Distance(a.Position, b.Position));
}
/// <summary>
/// Test if a certain circle contains a point
/// </summary>
/// <param name="a">The circle to test</param>
/// <param name="point">The point to test</param>
/// <returns>Returns true if circle contains the point</returns>
public static bool CircleContainsPoint(Circle a, Vector2 point)
{
return a.Radius > Vector2.Distance(new Vector2(a.X, a.Y), point);
}
public bool CircleContainsPoint(Vector2 point)
{
return Circle.CircleContainsPoint(this, point);
}
}
I guess my collision code could be wrong but I dont believe so. I am passing in a point to determine if the click was inside of the circle.
Perhaps my math is wrong, or i dont understand the Futile coordinate system like I should, but I am at a loss.
I have checked to ensure that the texture I use for the planet is square(128x128), and that the actual circle is perfectly centered.
I can get the circle close but not perfect. There is always a registered click where it shouldnt be.
Also I tried to tag this post with "Futile" but it would not let me due to reputation.
