-
Notifications
You must be signed in to change notification settings - Fork 28
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
Type definition for sprite #316
Comments
@nighca The following are some of Unity's API interfaces: public static RaycastHit2D Raycast(Vector2 origin, Vector2 direction, float distance)
public static RaycastHit2D[] RaycastAll(Vector2 origin,Vector2 direction,float distance,int layerMask)
public static Collider2D OverlapBox(Vector2 point, Vector2 size, float angle)
public static Collider2D[] OverlapBoxAll(Vector2 point,Vector2 size,float angle,int layerMask,float minDepth) |
@JiepengTan These seem to be more basic definitions, like What I propose to add is a type definition which just describes a sprite. All public methods that a sprite has, e.g., |
And, it is expected to trigger auto-binding with code like this: var (
Enemy Sprite
) spx will try to load sprite with name |
Consider a modified version of the game AircraftWar where instead of firing bullets, the aircraft uses lasers to destroy enemies. The laser immediately eliminates the nearest enemy at the same
xpos
when fired.Implementing this using the
touching
andonTouched
API is not feasible because:laser
sprite is created and the "touching" event is utilized between the laser and enemies, it becomes challenging to identify "the nearest enemy" since each enemy cannot determine its proximity.In this scenario, game developers may need to manage a global sprite array, which simplifies the logic:
However, there’s a complication:
spx
lacks an appropriate type definition forSprite
.The
Sprite
type currently refers to astruct
, while any enemy in the game is an instance ofEnemy
:So it is inappropriate to use
[]Sprite
to store enemy instances.Using
[]Enemy
for the enemies array is inappropriate either because:[]*Enemy
to store the correct data, while we want to avoid pointer usage by game developers.[]*SmallEnemy
or[]*BigEnemy
?I propose renaming the existing
type Sprite struct{}
toSpriteImpl
and defining a new typeSprite
:With this structure, the sprite array logic will function as intended.
Please share your ideas here, @xushiwei @JiepengTan.
The text was updated successfully, but these errors were encountered: