Given an RGBA image, this returns points that make up a hit box around it. Attempts to trim out transparent pixels.
image – Image get hit box from.
Given an RGBA image, this returns points that make up a hit box around it. Attempts to trim out transparent pixels.
image – Image get hit box from.
hit_box_detail – How detailed to make the hit box. There’s a trade-off in number of points vs. accuracy.
Bases:
The base class for hit box algorithms.
Hit box algorithms are intended to calculate the points which make up a hit box for a given Image
. However, advanced users can also repurpose them for other tasks.
Shorthand allowing any instance to be used identically to the base type.
args –
The same positional arguments as __init__
The same keyword arguments as __init__
A new HitBoxAlgorithm instance
Whether points for this algorithm should be cached
A string representation of the parameters used to create this algorithm.
It will be incorporated at the end of the string returned by Texture.create_cache_name
. Subclasses should override this method to return a value which allows distinguishing different configurations of a particular hit box algorithm.
Calculate hit box points for a given image.
Warning
This method should not be made into a class method!
Although this base class does not take arguments when initialized, subclasses use them to alter how a specific instance handles image data by default.
image – The image to calculate hitbox points for
kwargs – keyword arguments
Create points for a simple bounding box around an image. This is often used as a fallback if a hit box algorithm doesn’t manage to figure out any reasonable points for an image.
image – The image to create a bounding box for.
Bases:
A basic hit box class supporting scaling.
It includes support for rescaling as well as shorthand properties for boundary values along the X and Y axes. For rotation support, use create_rotatable()
to create an instance of RotatableHitBox
.
points – The unmodified points bounding the hit box
position – The center around which the points will be offset
scale – The X and Y scaling factors to use when offsetting the points
Calculates the bottommost adjusted y position of this hit box
Create a rotatable instance of this hit box.
The internal PointList
is transferred directly instead of deep copied, so care should be taken if using a mutable internal representation.
angle – The angle to rotate points by (0 by default)
Return the positions of points, scaled and offset from the center.
Unlike the boundary helper properties (left, etc), this method will only recalculate the values when necessary:
The first time this method is called
After properties affecting adjusted position were changed
Calculates the leftmost adjusted x position of this hit box
The raw, unadjusted points of this hit box.
These are the points as originally passed before offsetting, scaling, and any operations subclasses may perform, such as rotation.
The center point used to offset the final adjusted positions.
Calculates the rightmost adjusted x position of this hit box
The X & Y scaling factors for the points in this hit box.
These are used to calculate the final adjusted positions of points.
Calculates the topmost adjusted y position of this hit box
Bases: HitBox
A hit box with support for rotation.
Rotation is separated from the basic hitbox because it is much slower than offsetting and scaling.
points – The unmodified points bounding the hit box
position – The translation to apply to the points
angle – The angle to rotate the points by
scale – The X and Y scaling factors
The angle to rotate the raw points by in degrees
Return the offset, scaled, & rotated points of this hitbox.
As with HitBox.get_adjusted_points()
, this method only recalculates the adjusted values when necessary.
Bases: HitBoxAlgorithm
A simple hit box algorithm that returns a hit box around the entire image.
Whether points for this algorithm should be cached
Given an RGBA image, this returns points that make up a hit box around it without any attempt to trim out transparent pixels.
image – Image get hit box from.
Bases: HitBoxAlgorithm
Simple hit box algorithm. This algorithm attempts to trim out transparent pixels from an image to create a hit box.
Given an RGBA image, this returns points that make up a hit box around it. Attempts to trim out transparent pixels.
image – Image get hit box from.
Bases: HitBoxAlgorithm
Hit box point algorithm that uses pymunk to calculate the points.
This is a more accurate algorithm generating more points. The point count can be controlled with the detail
parameter.
Create a new instance with new default values
Given an RGBA image, this returns points that make up a hit box around it.
image – Image get hit box from.
detail – How detailed to make the hit box. There’s a trade-off in number of points vs. accuracy.
The default detail when creating a new instance.
Given a list of line sets, return the one that covers the most of the image.
line_sets – List of line sets.
Convert a line set to a list of points.
Coordinates are offset so (0,0)
is the center of the image.
image – Image to trace.
line_set – Line set to convert.
Trace the image and return a :py:class:~collections.abc.Sequence` of line sets.
The returned object will be a pymunk
PolylineSet
. Each list
inside it will contain points as pymunk.vec2d.Vec2d
instances. These lists may represent:
the outline of the image’s contents
the holes in the image
When this method returns more than one line set, it’s important to pick the one which covers the largest portion of the image.
image – A PIL.Image.Image
to trace.
A pymunk
object which is a Sequence
of PolylineSet
of line sets.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4