Class SKPhysicsBody

  • All Implemented Interfaces:
    NSCoding, NSCopying, NSSecureCoding, NSObject

    public class SKPhysicsBody
    extends NSObject
    implements NSCopying, NSSecureCoding
    A SpriteKit physics body. These are the physical representations of your nodes. These specify the area and mass and any collision masking needed. All bodies have zero, one or more shapes that define its area. A body with no shapes is ethereal and does not collide with other bodies.
    • Constructor Detail

      • SKPhysicsBody

        protected SKPhysicsBody​(org.moe.natj.general.Pointer peer)
    • Method Detail

      • accessInstanceVariablesDirectly

        public static boolean accessInstanceVariablesDirectly()
      • allocWithZone

        public static java.lang.Object allocWithZone​(org.moe.natj.general.ptr.VoidPtr zone)
      • automaticallyNotifiesObserversForKey

        public static boolean automaticallyNotifiesObserversForKey​(java.lang.String key)
      • bodyWithBodies

        public static SKPhysicsBody bodyWithBodies​(NSArray<? extends SKPhysicsBody> bodies)
        Creates an compound body that is the union of the bodies used to create it.
      • bodyWithCircleOfRadius

        public static SKPhysicsBody bodyWithCircleOfRadius​(double r)
        Creates a circle of radius r centered at the node's origin.
        Parameters:
        r - the radius in points
      • bodyWithCircleOfRadiusCenter

        public static SKPhysicsBody bodyWithCircleOfRadiusCenter​(double r,
                                                                 CGPoint center)
        Creates a circle of radius r centered at a point in the node's coordinate space.
        Parameters:
        r - the radius in points
      • bodyWithEdgeChainFromPath

        public static SKPhysicsBody bodyWithEdgeChainFromPath​(CGPathRef path)
        Creates an edge chain from a path. The path must have no self intersection. Edges have no volume and are intended to be used to create static environments. Edges can collide with bodies of volume, but not with each other.
        Parameters:
        path - the path to use
      • bodyWithEdgeFromPointToPoint

        public static SKPhysicsBody bodyWithEdgeFromPointToPoint​(CGPoint p1,
                                                                 CGPoint p2)
        Creates an edge from p1 to p2. Edges have no volume and are intended to be used to create static environments. Edges can collide with bodies of volume, but not with each other.
        Parameters:
        p1 - start point
        p2 - end point
      • bodyWithEdgeLoopFromPath

        public static SKPhysicsBody bodyWithEdgeLoopFromPath​(CGPathRef path)
        Creates an edge loop from a path. A loop is automatically created by joining the last point to the first. The path must have no self intersection. Edges have no volume and are intended to be used to create static environments. Edges can collide with body's of volume, but not with each other.
        Parameters:
        path - the path to use
      • bodyWithEdgeLoopFromRect

        public static SKPhysicsBody bodyWithEdgeLoopFromRect​(CGRect rect)
        Creates an edge loop from a CGRect. Edges have no volume and are intended to be used to create static environments. Edges can collide with body's of volume, but not with each other.
        Parameters:
        rect - the CGRect to use
      • bodyWithPolygonFromPath

        public static SKPhysicsBody bodyWithPolygonFromPath​(CGPathRef path)
        The path must represent a convex or concave polygon with counter clockwise winding and no self intersection. Positions are relative to the node's origin.
        Parameters:
        path - the path to use
      • bodyWithRectangleOfSize

        public static SKPhysicsBody bodyWithRectangleOfSize​(CGSize s)
        Creates a rectangle of the specified size centered at the node's origin.
        Parameters:
        s - the size in points
      • bodyWithRectangleOfSizeCenter

        public static SKPhysicsBody bodyWithRectangleOfSizeCenter​(CGSize s,
                                                                  CGPoint center)
        Creates a rectangle of the specified size centered at a point in the node's coordinate space.
        Parameters:
        s - the size in points
      • bodyWithTextureAlphaThresholdSize

        public static SKPhysicsBody bodyWithTextureAlphaThresholdSize​(SKTexture texture,
                                                                      float alphaThreshold,
                                                                      CGSize size)
        Creates a body from the alpha values in the supplied texture.
        Parameters:
        texture - the texture to be interpreted
        alphaThreshold - the alpha value above which a pixel is interpreted as opaque
        size - of the generated physics body
      • bodyWithTextureSize

        public static SKPhysicsBody bodyWithTextureSize​(SKTexture texture,
                                                        CGSize size)
        Creates a body from the alpha values in the supplied texture.
        Parameters:
        texture - the texture to be interpreted
        size - of the generated physics body
      • cancelPreviousPerformRequestsWithTarget

        public static void cancelPreviousPerformRequestsWithTarget​(java.lang.Object aTarget)
      • cancelPreviousPerformRequestsWithTargetSelectorObject

        public static void cancelPreviousPerformRequestsWithTargetSelectorObject​(java.lang.Object aTarget,
                                                                                 org.moe.natj.objc.SEL aSelector,
                                                                                 java.lang.Object anArgument)
      • classFallbacksForKeyedArchiver

        public static NSArray<java.lang.String> classFallbacksForKeyedArchiver()
      • classForKeyedUnarchiver

        public static org.moe.natj.objc.Class classForKeyedUnarchiver()
      • debugDescription_static

        public static java.lang.String debugDescription_static()
      • description_static

        public static java.lang.String description_static()
      • hash_static

        public static long hash_static()
      • instanceMethodSignatureForSelector

        public static NSMethodSignature instanceMethodSignatureForSelector​(org.moe.natj.objc.SEL aSelector)
      • instancesRespondToSelector

        public static boolean instancesRespondToSelector​(org.moe.natj.objc.SEL aSelector)
      • isSubclassOfClass

        public static boolean isSubclassOfClass​(org.moe.natj.objc.Class aClass)
      • keyPathsForValuesAffectingValueForKey

        public static NSSet<java.lang.String> keyPathsForValuesAffectingValueForKey​(java.lang.String key)
      • new_objc

        public static java.lang.Object new_objc()
      • resolveClassMethod

        public static boolean resolveClassMethod​(org.moe.natj.objc.SEL sel)
      • resolveInstanceMethod

        public static boolean resolveInstanceMethod​(org.moe.natj.objc.SEL sel)
      • setVersion_static

        public static void setVersion_static​(long aVersion)
      • superclass_static

        public static org.moe.natj.objc.Class superclass_static()
      • version_static

        public static long version_static()
      • affectedByGravity

        public boolean affectedByGravity()
        Bodies are affected by field forces such as gravity if this property is set and the field's category mask is set appropriately. The default value is YES. If this is set a force is applied to the object based on the mass. Set the field force vector in the scene to modify the strength of the force.
      • allContactedBodies

        public NSArray<? extends SKPhysicsBody> allContactedBodies()
        Returns an array of all SKPhysicsBodies currently in contact with this one
      • allowsRotation

        public boolean allowsRotation()
      • angularDamping

        public double angularDamping()
        Optionally reduce the body's angular velocity each frame to simulate rotational friction. (0.0 - 1.0). Defaults to 0.1
      • angularVelocity

        public double angularVelocity()
      • applyAngularImpulse

        public void applyAngularImpulse​(double impulse)
      • applyForce

        public void applyForce​(CGVector force)
      • applyForceAtPoint

        public void applyForceAtPoint​(CGVector force,
                                      CGPoint point)
      • applyImpulse

        public void applyImpulse​(CGVector impulse)
      • applyImpulseAtPoint

        public void applyImpulseAtPoint​(CGVector impulse,
                                        CGPoint point)
      • applyTorque

        public void applyTorque​(double torque)
      • area

        public double area()
        The area of the body. The unit is arbitrary, as long as the relative areas are consistent throughout the application.
      • categoryBitMask

        public int categoryBitMask()
        Defines what logical 'categories' this body belongs to. Defaults to all bits set (all categories).
      • charge

        public double charge()
        Specifies the charge on the body. Charge determines the degree to which a body is affected by electric and magnetic fields. Note that this is a unitless quantity, it is up to the developer to set charge and field strength appropriately. Defaults to 0.0
      • collisionBitMask

        public int collisionBitMask()
        Defines what logical 'categories' of bodies this body responds to collisions with. Defaults to all bits set (all categories).
      • contactTestBitMask

        public int contactTestBitMask()
        Defines what logical 'categories' of bodies this body generates intersection notifications with. Defaults to all bits cleared (no categories).
      • copyWithZone

        public java.lang.Object copyWithZone​(org.moe.natj.general.ptr.VoidPtr zone)
        Specified by:
        copyWithZone in interface NSCopying
      • density

        public double density()
        The density of the body. The unit is arbitrary, as long as the relative densities are consistent throughout the application. Note that density and mass are inherently related (they are directly proportional), so changing one also changes the other. Both are provided so either can be used depending on what is more relevant to your usage.
      • fieldBitMask

        public int fieldBitMask()
        Defines what logical 'categories' of fields this body responds to. Defaults to all bits set (all categories). Can be forced off via affectedByGravity.
      • friction

        public double friction()
        Determines the 'roughness' for the surface of the physics body (0.0 - 1.0). Defaults to 0.2
      • isDynamic

        public boolean isDynamic()
      • setDynamic

        public void setDynamic​(boolean value)
      • isResting

        public boolean isResting()
        If the physics simulation has determined that this body is at rest it may set the resting property to YES. Resting bodies do not participate in the simulation until some collision with a non-resting object, or an impulse is applied, that unrests it. If all bodies in the world are resting then the simulation as a whole is "at rest".
      • setResting

        public void setResting​(boolean value)
        If the physics simulation has determined that this body is at rest it may set the resting property to YES. Resting bodies do not participate in the simulation until some collision with a non-resting object, or an impulse is applied, that unrests it. If all bodies in the world are resting then the simulation as a whole is "at rest".
      • linearDamping

        public double linearDamping()
        Optionally reduce the body's linear velocity each frame to simulate fluid/air friction. Value should be zero or greater. Defaults to 0.1. Used in conjunction with per frame impulses, an object can be made to move at a constant speed. For example, if an object 64 points in size and default density and a linearDamping of 25 will slide across the screen in a few seconds if an impulse of magnitude 10 is applied every update.
      • mass

        public double mass()
        The mass of the body. The unit is arbitrary, as long as the relative masses are consistent throughout the application. Note that density and mass are inherently related (they are directly proportional), so changing one also changes the other. Both are provided so either can be used depending on what is more relevant to your usage.
      • node

        public SKNode node()
        The representedObject this physicsBody is currently bound to, or nil if it is not.
      • pinned

        public boolean pinned()
      • restitution

        public double restitution()
        Determines the 'bounciness' of the physics body (0.0 - 1.0). Defaults to 0.2
      • setAffectedByGravity

        public void setAffectedByGravity​(boolean value)
        Bodies are affected by field forces such as gravity if this property is set and the field's category mask is set appropriately. The default value is YES. If this is set a force is applied to the object based on the mass. Set the field force vector in the scene to modify the strength of the force.
      • setAllowsRotation

        public void setAllowsRotation​(boolean value)
      • setAngularDamping

        public void setAngularDamping​(double value)
        Optionally reduce the body's angular velocity each frame to simulate rotational friction. (0.0 - 1.0). Defaults to 0.1
      • setAngularVelocity

        public void setAngularVelocity​(double value)
      • setCategoryBitMask

        public void setCategoryBitMask​(int value)
        Defines what logical 'categories' this body belongs to. Defaults to all bits set (all categories).
      • setCharge

        public void setCharge​(double value)
        Specifies the charge on the body. Charge determines the degree to which a body is affected by electric and magnetic fields. Note that this is a unitless quantity, it is up to the developer to set charge and field strength appropriately. Defaults to 0.0
      • setCollisionBitMask

        public void setCollisionBitMask​(int value)
        Defines what logical 'categories' of bodies this body responds to collisions with. Defaults to all bits set (all categories).
      • setContactTestBitMask

        public void setContactTestBitMask​(int value)
        Defines what logical 'categories' of bodies this body generates intersection notifications with. Defaults to all bits cleared (no categories).
      • setDensity

        public void setDensity​(double value)
        The density of the body. The unit is arbitrary, as long as the relative densities are consistent throughout the application. Note that density and mass are inherently related (they are directly proportional), so changing one also changes the other. Both are provided so either can be used depending on what is more relevant to your usage.
      • setFieldBitMask

        public void setFieldBitMask​(int value)
        Defines what logical 'categories' of fields this body responds to. Defaults to all bits set (all categories). Can be forced off via affectedByGravity.
      • setFriction

        public void setFriction​(double value)
        Determines the 'roughness' for the surface of the physics body (0.0 - 1.0). Defaults to 0.2
      • setLinearDamping

        public void setLinearDamping​(double value)
        Optionally reduce the body's linear velocity each frame to simulate fluid/air friction. Value should be zero or greater. Defaults to 0.1. Used in conjunction with per frame impulses, an object can be made to move at a constant speed. For example, if an object 64 points in size and default density and a linearDamping of 25 will slide across the screen in a few seconds if an impulse of magnitude 10 is applied every update.
      • setMass

        public void setMass​(double value)
        The mass of the body. The unit is arbitrary, as long as the relative masses are consistent throughout the application. Note that density and mass are inherently related (they are directly proportional), so changing one also changes the other. Both are provided so either can be used depending on what is more relevant to your usage.
      • setPinned

        public void setPinned​(boolean value)
      • setRestitution

        public void setRestitution​(double value)
        Determines the 'bounciness' of the physics body (0.0 - 1.0). Defaults to 0.2
      • setUsesPreciseCollisionDetection

        public void setUsesPreciseCollisionDetection​(boolean value)
      • setVelocity

        public void setVelocity​(CGVector value)
      • usesPreciseCollisionDetection

        public boolean usesPreciseCollisionDetection()
      • supportsSecureCoding

        public static boolean supportsSecureCoding()
      • _supportsSecureCoding

        public boolean _supportsSecureCoding()
        Description copied from interface: NSSecureCoding
        This property must return YES on all classes that allow secure coding. Subclasses of classes that adopt NSSecureCoding and override initWithCoder: must also override this method and return YES. The Secure Coding Guide should be consulted when writing methods that decode data.
        Specified by:
        _supportsSecureCoding in interface NSSecureCoding