public void UpdateTransform() { if (body != null && parent != null) { if (hasXChange || hasYChange || hasRChange) { V2DTransform t = transforms[transformIndex]; if (hasXChange || hasYChange) { Vector2 newPos = body.GetPosition(); if (hasXChange) { //newPos.X = (State.Position.X + parent.CurrentState.Position.X + t.Position.X) / worldScale; newPos.X = (State.Position.X + parent.CurrentState.Position.X) / V2DScreen.WorldScale; } if (hasYChange) { //newPos.Y = (State.Position.Y + parent.CurrentState.Position.Y + t.Position.Y) / worldScale; newPos.Y = (State.Position.Y + parent.CurrentState.Position.Y) / V2DScreen.WorldScale; } body.Position = newPos; } if (hasRChange) { body.Rotation = State.Rotation - parent.CurrentState.Rotation + t.Rotation; } hasXChange = false; hasYChange = false; hasRChange = false; } } }
public static V2DTransform[] GetV2DTransformArray(V2DGenericTransform[] t) { V2DTransform[] result = new V2DTransform[t.Length]; for (int i = 0; i < t.Length; i++) { result[i] = t[i]; } return result; }
public static V2DTransform[] GetV2DTransformArray(V2DGenericTransform[] t) { V2DTransform[] result = new V2DTransform[t.Length]; for (int i = 0; i < t.Length; i++) { result[i] = t[i]; } return(result); }
protected override void SetCurrentState() { if (body == null) { base.SetCurrentState(); } else { for (int i = 0; i < transforms.Length; i++) { if (transforms[i].StartFrame <= parent.CurChildFrame && transforms[i].EndFrame >= (parent.CurChildFrame)) { transformIndex = i; break; } } V2DTransform t = transforms[transformIndex]; if (hasRChange || hasXChange || hasYChange) { UpdateTransform(); } Vector2 bPosition = body.GetPosition() * V2DScreen.WorldScale; //new Vector2((int)(body.GetPosition().X * V2DScreen.WorldScale), (int)(body.GetPosition().Y * V2DScreen.WorldScale)); float br = body.GetAngle(); Vector2 com = body.GetLocalCenter() * V2DScreen.WorldScale; //Vector2 comOrg = Origin - com; //float angle = (float)Math.Atan2(com.Y, com.X) + br; //float length = (float)com.Length(); CurrentState.Scale = Vector2.One; // parent.CurrentState.Scale * State.Scale * t.Scale; CurrentState.Rotation = br; // -parent.CurrentState.Rotation + t.Rotation; CurrentState.Position = bPosition; // -new Vector2((float)Math.Cos(angle), (float)Math.Sin(angle)) * length;// -parent.CurrentState.Position;// +t.Position; //Origin = new Vector2(0, -20);// origin; //children[0].Origin = -Origin; //((DisplayObjectContainer)children[0]).children[0].Origin = new Vector2(83, 47);// +Origin; //CurrentState.Origin = Origin; State.Position = CurrentState.Position - parent.CurrentState.Position; State.Rotation = CurrentState.Rotation - parent.CurrentState.Rotation; State.Origin = CurrentState.Origin; CurrentState.Alpha = parent.CurrentState.Alpha * State.Alpha * t.Alpha; if (color.A != (byte)(CurrentState.Alpha * 255)) { color.A = (byte)(State.Alpha * 255); } } }
private static int idCounter = 0;//int.MinValue; public DisplayObject() { id = idCounter++; this.instanceName = "_inst" + id; transforms = new V2DTransform[]{State}; }