Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Camera Anchor fix #615

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open

Camera Anchor fix #615

wants to merge 2 commits into from

Conversation

XANOZOID
Copy link
Member

This is to fix a problem that happened with the anchor system since we've had the Vector2 changes: #596

Once an instance was converted into a Vector2 its reference was lost and the camera would not follow it.

The new approach

This adds some congitive complexity that I wish could have been avoided, but I don't think there's anyway to combine Vector2's position and positionObj in a nice way.

So what has been done is using a crude sort of tuple implementation and exposing the PositionObj in Vector2's implementation. Fortunately there's no real impact on the overall structure by doing thaat.

Once we have a tuple in place, and being that there is only two types of data Vector2 uses, we actually have a way to sync to any of the anchorable types and update is working again.

What's been changed

I've had to change the method signature for anchor to support a crude type of overloading.

It accepts a PositionObj or a Vector2. I originally tried using OneOf as a way to accept both and unwrap later but Haxe through compile errors about that approach. It's not exactly a perfect run time tuple.

Once anchor has been called it is stored in an abstract tuple and later unwrapped to grab its position inside of update. The tuple's left contains a PositionObj so this is where we would have access to retrieving entities (like centerX and the like ).

Possible breaks

Running the tests show that nothing has actually broke, but if there is any reference in HaxePunk to the original Camera.anchorTarget it will be incompatible. So old code that utilized this element would be removed.

This could be easily fixed by making anchorTarget a Vector2 again and wrapping it around the tuple.

This is to fix a problem that happened with the anchor system since we've had the Vector2 changes.

Once an instance was converted into a Vector2 its reference was lost.

## The new approach
This adds some congitive complexity that I wish could have been avoided, but I don't think there's anyway to combine Vector2's position and positionObj in a nice way.

So what has been done is using a crude sort of tuple implementation and exposing the PositionObj in Vector2's implementation. Fortunately there's no real impact on the overall structure by doing thaat.

Once we have a tuple in place, and being that there is only two types of data Vector2 uses, we actually have a way to sync to any of the anchorable types and update is working again.

## What's been changed
I've had to change the method signature for anchor to support a crude type of overloading.

It accepts a PositionObj or a Vector2. I originally tried using `OneOf` as a way to accept both and unwrap later but Haxe through compile errors about that approach. It's not exactly a perfect run time tuple.

Once anchor has been called it is stored in an abstract tuple and later unwrapped to grab its position inside of update. The tuple's left contains a PositionObj so this is where we would have access to retrieving entities (like centerX and the like ).

## Possible breaks
Running the tests show that nothing has actually broke, but if there is any reference in HaxePunk to the original Camera.anchorTarget it will be incompatible. So old code that utilized this element would be removed.

This could be easily fixed by making anchorTarget a Vector2 again and wrapping it around the tuple.
@XANOZOID XANOZOID changed the title Anchor fixed Anchor fix Dec 27, 2018
@XANOZOID XANOZOID changed the title Anchor fix Camera Anchor fix Dec 27, 2018
added a space . . .
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant