objc2_sprite_kit/generated/
SKPhysicsBody.rs

1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::ffi::*;
4use core::ptr::NonNull;
5use objc2::__framework_prelude::*;
6#[cfg(feature = "objc2-core-foundation")]
7use objc2_core_foundation::*;
8#[cfg(feature = "objc2-core-graphics")]
9use objc2_core_graphics::*;
10use objc2_foundation::*;
11
12use crate::*;
13
14extern_class!(
15    /// A SpriteKit physics body. These are the physical representations of your nodes. These specify the area and mass and any collision masking needed.
16    ///
17    /// 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.
18    ///
19    /// See also [Apple's documentation](https://developer.apple.com/documentation/spritekit/skphysicsbody?language=objc)
20    #[unsafe(super(NSObject))]
21    #[derive(Debug, PartialEq, Eq, Hash)]
22    pub struct SKPhysicsBody;
23);
24
25unsafe impl NSCoding for SKPhysicsBody {}
26
27unsafe impl NSCopying for SKPhysicsBody {}
28
29unsafe impl CopyingHelper for SKPhysicsBody {
30    type Result = Self;
31}
32
33unsafe impl NSObjectProtocol for SKPhysicsBody {}
34
35unsafe impl NSSecureCoding for SKPhysicsBody {}
36
37impl SKPhysicsBody {
38    extern_methods!(
39        #[cfg(feature = "objc2-core-foundation")]
40        /// Creates a circle of radius r centered at the node's origin.
41        ///
42        /// Parameter `r`: the radius in points
43        #[unsafe(method(bodyWithCircleOfRadius:))]
44        #[unsafe(method_family = none)]
45        pub unsafe fn bodyWithCircleOfRadius(r: CGFloat) -> Retained<SKPhysicsBody>;
46
47        #[cfg(feature = "objc2-core-foundation")]
48        /// Creates a circle of radius r centered at a point in the node's coordinate space.
49        ///
50        /// Parameter `r`: the radius in points
51        #[unsafe(method(bodyWithCircleOfRadius:center:))]
52        #[unsafe(method_family = none)]
53        pub unsafe fn bodyWithCircleOfRadius_center(
54            r: CGFloat,
55            center: CGPoint,
56        ) -> Retained<SKPhysicsBody>;
57
58        #[cfg(feature = "objc2-core-foundation")]
59        /// Creates a rectangle of the specified size centered at the node's origin.
60        ///
61        /// Parameter `s`: the size in points
62        #[unsafe(method(bodyWithRectangleOfSize:))]
63        #[unsafe(method_family = none)]
64        pub unsafe fn bodyWithRectangleOfSize(s: CGSize) -> Retained<SKPhysicsBody>;
65
66        #[cfg(feature = "objc2-core-foundation")]
67        /// Creates a rectangle of the specified size centered at a point in the node's coordinate space.
68        ///
69        /// Parameter `s`: the size in points
70        #[unsafe(method(bodyWithRectangleOfSize:center:))]
71        #[unsafe(method_family = none)]
72        pub unsafe fn bodyWithRectangleOfSize_center(
73            s: CGSize,
74            center: CGPoint,
75        ) -> Retained<SKPhysicsBody>;
76
77        #[cfg(feature = "objc2-core-graphics")]
78        /// 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.
79        ///
80        /// Parameter `path`: the path to use
81        #[unsafe(method(bodyWithPolygonFromPath:))]
82        #[unsafe(method_family = none)]
83        pub unsafe fn bodyWithPolygonFromPath(path: &CGPath) -> Retained<SKPhysicsBody>;
84
85        #[cfg(feature = "objc2-core-foundation")]
86        /// 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.
87        ///
88        /// Parameter `p1`: start point
89        ///
90        /// Parameter `p2`: end point
91        #[unsafe(method(bodyWithEdgeFromPoint:toPoint:))]
92        #[unsafe(method_family = none)]
93        pub unsafe fn bodyWithEdgeFromPoint_toPoint(
94            p1: CGPoint,
95            p2: CGPoint,
96        ) -> Retained<SKPhysicsBody>;
97
98        #[cfg(feature = "objc2-core-graphics")]
99        /// 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.
100        ///
101        /// Parameter `path`: the path to use
102        #[unsafe(method(bodyWithEdgeChainFromPath:))]
103        #[unsafe(method_family = none)]
104        pub unsafe fn bodyWithEdgeChainFromPath(path: &CGPath) -> Retained<SKPhysicsBody>;
105
106        #[cfg(feature = "objc2-core-graphics")]
107        /// 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.
108        ///
109        /// Parameter `path`: the path to use
110        #[unsafe(method(bodyWithEdgeLoopFromPath:))]
111        #[unsafe(method_family = none)]
112        pub unsafe fn bodyWithEdgeLoopFromPath(path: &CGPath) -> Retained<SKPhysicsBody>;
113
114        #[cfg(feature = "objc2-core-foundation")]
115        /// 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.
116        ///
117        /// Parameter `rect`: the CGRect to use
118        #[unsafe(method(bodyWithEdgeLoopFromRect:))]
119        #[unsafe(method_family = none)]
120        pub unsafe fn bodyWithEdgeLoopFromRect(rect: CGRect) -> Retained<SKPhysicsBody>;
121
122        #[cfg(all(feature = "SKTexture", feature = "objc2-core-foundation"))]
123        /// Creates a body from the alpha values in the supplied texture.
124        ///
125        /// Parameter `texture`: the texture to be interpreted
126        ///
127        /// Parameter `size`: of the generated physics body
128        #[unsafe(method(bodyWithTexture:size:))]
129        #[unsafe(method_family = none)]
130        pub unsafe fn bodyWithTexture_size(
131            texture: &SKTexture,
132            size: CGSize,
133        ) -> Retained<SKPhysicsBody>;
134
135        #[cfg(all(feature = "SKTexture", feature = "objc2-core-foundation"))]
136        /// Creates a body from the alpha values in the supplied texture.
137        ///
138        /// Parameter `texture`: the texture to be interpreted
139        ///
140        /// Parameter `alphaThreshold`: the alpha value above which a pixel is interpreted as opaque
141        ///
142        /// Parameter `size`: of the generated physics body
143        #[unsafe(method(bodyWithTexture:alphaThreshold:size:))]
144        #[unsafe(method_family = none)]
145        pub unsafe fn bodyWithTexture_alphaThreshold_size(
146            texture: &SKTexture,
147            alpha_threshold: c_float,
148            size: CGSize,
149        ) -> Retained<SKPhysicsBody>;
150
151        /// Creates an compound body that is the union of the bodies used to create it.
152        #[unsafe(method(bodyWithBodies:))]
153        #[unsafe(method_family = none)]
154        pub unsafe fn bodyWithBodies(bodies: &NSArray<SKPhysicsBody>) -> Retained<SKPhysicsBody>;
155
156        #[unsafe(method(isDynamic))]
157        #[unsafe(method_family = none)]
158        pub unsafe fn isDynamic(&self) -> bool;
159
160        /// Setter for [`isDynamic`][Self::isDynamic].
161        #[unsafe(method(setDynamic:))]
162        #[unsafe(method_family = none)]
163        pub unsafe fn setDynamic(&self, dynamic: bool);
164
165        #[unsafe(method(usesPreciseCollisionDetection))]
166        #[unsafe(method_family = none)]
167        pub unsafe fn usesPreciseCollisionDetection(&self) -> bool;
168
169        /// Setter for [`usesPreciseCollisionDetection`][Self::usesPreciseCollisionDetection].
170        #[unsafe(method(setUsesPreciseCollisionDetection:))]
171        #[unsafe(method_family = none)]
172        pub unsafe fn setUsesPreciseCollisionDetection(
173            &self,
174            uses_precise_collision_detection: bool,
175        );
176
177        #[unsafe(method(allowsRotation))]
178        #[unsafe(method_family = none)]
179        pub unsafe fn allowsRotation(&self) -> bool;
180
181        /// Setter for [`allowsRotation`][Self::allowsRotation].
182        #[unsafe(method(setAllowsRotation:))]
183        #[unsafe(method_family = none)]
184        pub unsafe fn setAllowsRotation(&self, allows_rotation: bool);
185
186        #[unsafe(method(pinned))]
187        #[unsafe(method_family = none)]
188        pub unsafe fn pinned(&self) -> bool;
189
190        /// Setter for [`pinned`][Self::pinned].
191        #[unsafe(method(setPinned:))]
192        #[unsafe(method_family = none)]
193        pub unsafe fn setPinned(&self, pinned: bool);
194
195        /// 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
196        /// 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
197        /// then the simulation as a whole is "at rest".
198        #[unsafe(method(isResting))]
199        #[unsafe(method_family = none)]
200        pub unsafe fn isResting(&self) -> bool;
201
202        /// Setter for [`isResting`][Self::isResting].
203        #[unsafe(method(setResting:))]
204        #[unsafe(method_family = none)]
205        pub unsafe fn setResting(&self, resting: bool);
206
207        #[cfg(feature = "objc2-core-foundation")]
208        /// Determines the 'roughness' for the surface of the physics body (0.0 - 1.0). Defaults to 0.2
209        #[unsafe(method(friction))]
210        #[unsafe(method_family = none)]
211        pub unsafe fn friction(&self) -> CGFloat;
212
213        #[cfg(feature = "objc2-core-foundation")]
214        /// Setter for [`friction`][Self::friction].
215        #[unsafe(method(setFriction:))]
216        #[unsafe(method_family = none)]
217        pub unsafe fn setFriction(&self, friction: CGFloat);
218
219        #[cfg(feature = "objc2-core-foundation")]
220        /// Specifies the charge on the body. Charge determines the degree to which a body is affected by
221        /// electric and magnetic fields. Note that this is a unitless quantity, it is up to the developer to
222        /// set charge and field strength appropriately. Defaults to 0.0
223        #[unsafe(method(charge))]
224        #[unsafe(method_family = none)]
225        pub unsafe fn charge(&self) -> CGFloat;
226
227        #[cfg(feature = "objc2-core-foundation")]
228        /// Setter for [`charge`][Self::charge].
229        #[unsafe(method(setCharge:))]
230        #[unsafe(method_family = none)]
231        pub unsafe fn setCharge(&self, charge: CGFloat);
232
233        #[cfg(feature = "objc2-core-foundation")]
234        /// Determines the 'bounciness' of the physics body (0.0 - 1.0). Defaults to 0.2
235        #[unsafe(method(restitution))]
236        #[unsafe(method_family = none)]
237        pub unsafe fn restitution(&self) -> CGFloat;
238
239        #[cfg(feature = "objc2-core-foundation")]
240        /// Setter for [`restitution`][Self::restitution].
241        #[unsafe(method(setRestitution:))]
242        #[unsafe(method_family = none)]
243        pub unsafe fn setRestitution(&self, restitution: CGFloat);
244
245        #[cfg(feature = "objc2-core-foundation")]
246        /// Optionally reduce the body's linear velocity each frame to simulate fluid/air friction. Value should be zero or greater. Defaults to 0.1.
247        /// 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
248        /// 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.
249        #[unsafe(method(linearDamping))]
250        #[unsafe(method_family = none)]
251        pub unsafe fn linearDamping(&self) -> CGFloat;
252
253        #[cfg(feature = "objc2-core-foundation")]
254        /// Setter for [`linearDamping`][Self::linearDamping].
255        #[unsafe(method(setLinearDamping:))]
256        #[unsafe(method_family = none)]
257        pub unsafe fn setLinearDamping(&self, linear_damping: CGFloat);
258
259        #[cfg(feature = "objc2-core-foundation")]
260        /// Optionally reduce the body's angular velocity each frame to simulate rotational friction. (0.0 - 1.0). Defaults to 0.1
261        #[unsafe(method(angularDamping))]
262        #[unsafe(method_family = none)]
263        pub unsafe fn angularDamping(&self) -> CGFloat;
264
265        #[cfg(feature = "objc2-core-foundation")]
266        /// Setter for [`angularDamping`][Self::angularDamping].
267        #[unsafe(method(setAngularDamping:))]
268        #[unsafe(method_family = none)]
269        pub unsafe fn setAngularDamping(&self, angular_damping: CGFloat);
270
271        #[cfg(feature = "objc2-core-foundation")]
272        /// The density of the body.
273        ///
274        /// 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.
275        #[unsafe(method(density))]
276        #[unsafe(method_family = none)]
277        pub unsafe fn density(&self) -> CGFloat;
278
279        #[cfg(feature = "objc2-core-foundation")]
280        /// Setter for [`density`][Self::density].
281        #[unsafe(method(setDensity:))]
282        #[unsafe(method_family = none)]
283        pub unsafe fn setDensity(&self, density: CGFloat);
284
285        #[cfg(feature = "objc2-core-foundation")]
286        /// The mass of the body.
287        ///
288        /// 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.
289        #[unsafe(method(mass))]
290        #[unsafe(method_family = none)]
291        pub unsafe fn mass(&self) -> CGFloat;
292
293        #[cfg(feature = "objc2-core-foundation")]
294        /// Setter for [`mass`][Self::mass].
295        #[unsafe(method(setMass:))]
296        #[unsafe(method_family = none)]
297        pub unsafe fn setMass(&self, mass: CGFloat);
298
299        #[cfg(feature = "objc2-core-foundation")]
300        /// The area of the body.
301        ///
302        /// The unit is arbitrary, as long as the relative areas are consistent throughout the application.
303        #[unsafe(method(area))]
304        #[unsafe(method_family = none)]
305        pub unsafe fn area(&self) -> CGFloat;
306
307        /// 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.
308        ///
309        /// 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.
310        #[unsafe(method(affectedByGravity))]
311        #[unsafe(method_family = none)]
312        pub unsafe fn affectedByGravity(&self) -> bool;
313
314        /// Setter for [`affectedByGravity`][Self::affectedByGravity].
315        #[unsafe(method(setAffectedByGravity:))]
316        #[unsafe(method_family = none)]
317        pub unsafe fn setAffectedByGravity(&self, affected_by_gravity: bool);
318
319        /// Defines what logical 'categories' of fields this body responds to. Defaults to all bits set (all categories).
320        /// Can be forced off via affectedByGravity.
321        #[unsafe(method(fieldBitMask))]
322        #[unsafe(method_family = none)]
323        pub unsafe fn fieldBitMask(&self) -> u32;
324
325        /// Setter for [`fieldBitMask`][Self::fieldBitMask].
326        #[unsafe(method(setFieldBitMask:))]
327        #[unsafe(method_family = none)]
328        pub unsafe fn setFieldBitMask(&self, field_bit_mask: u32);
329
330        /// Defines what logical 'categories' this body belongs to. Defaults to all bits set (all categories).
331        #[unsafe(method(categoryBitMask))]
332        #[unsafe(method_family = none)]
333        pub unsafe fn categoryBitMask(&self) -> u32;
334
335        /// Setter for [`categoryBitMask`][Self::categoryBitMask].
336        #[unsafe(method(setCategoryBitMask:))]
337        #[unsafe(method_family = none)]
338        pub unsafe fn setCategoryBitMask(&self, category_bit_mask: u32);
339
340        /// Defines what logical 'categories' of bodies this body responds to collisions with. Defaults to all bits set (all categories).
341        #[unsafe(method(collisionBitMask))]
342        #[unsafe(method_family = none)]
343        pub unsafe fn collisionBitMask(&self) -> u32;
344
345        /// Setter for [`collisionBitMask`][Self::collisionBitMask].
346        #[unsafe(method(setCollisionBitMask:))]
347        #[unsafe(method_family = none)]
348        pub unsafe fn setCollisionBitMask(&self, collision_bit_mask: u32);
349
350        /// Defines what logical 'categories' of bodies this body generates intersection notifications with. Defaults to all bits cleared (no categories).
351        #[unsafe(method(contactTestBitMask))]
352        #[unsafe(method_family = none)]
353        pub unsafe fn contactTestBitMask(&self) -> u32;
354
355        /// Setter for [`contactTestBitMask`][Self::contactTestBitMask].
356        #[unsafe(method(setContactTestBitMask:))]
357        #[unsafe(method_family = none)]
358        pub unsafe fn setContactTestBitMask(&self, contact_test_bit_mask: u32);
359
360        #[cfg(feature = "SKPhysicsJoint")]
361        #[unsafe(method(joints))]
362        #[unsafe(method_family = none)]
363        pub unsafe fn joints(&self) -> Retained<NSArray<SKPhysicsJoint>>;
364
365        #[cfg(all(feature = "SKNode", feature = "objc2-app-kit"))]
366        #[cfg(target_os = "macos")]
367        /// The representedObject this physicsBody is currently bound to, or nil if it is not.
368        #[unsafe(method(node))]
369        #[unsafe(method_family = none)]
370        pub unsafe fn node(&self, mtm: MainThreadMarker) -> Option<Retained<SKNode>>;
371
372        #[cfg(feature = "objc2-core-foundation")]
373        #[unsafe(method(velocity))]
374        #[unsafe(method_family = none)]
375        pub unsafe fn velocity(&self) -> CGVector;
376
377        #[cfg(feature = "objc2-core-foundation")]
378        /// Setter for [`velocity`][Self::velocity].
379        #[unsafe(method(setVelocity:))]
380        #[unsafe(method_family = none)]
381        pub unsafe fn setVelocity(&self, velocity: CGVector);
382
383        #[cfg(feature = "objc2-core-foundation")]
384        #[unsafe(method(angularVelocity))]
385        #[unsafe(method_family = none)]
386        pub unsafe fn angularVelocity(&self) -> CGFloat;
387
388        #[cfg(feature = "objc2-core-foundation")]
389        /// Setter for [`angularVelocity`][Self::angularVelocity].
390        #[unsafe(method(setAngularVelocity:))]
391        #[unsafe(method_family = none)]
392        pub unsafe fn setAngularVelocity(&self, angular_velocity: CGFloat);
393
394        #[cfg(feature = "objc2-core-foundation")]
395        #[unsafe(method(applyForce:))]
396        #[unsafe(method_family = none)]
397        pub unsafe fn applyForce(&self, force: CGVector);
398
399        #[cfg(feature = "objc2-core-foundation")]
400        #[unsafe(method(applyForce:atPoint:))]
401        #[unsafe(method_family = none)]
402        pub unsafe fn applyForce_atPoint(&self, force: CGVector, point: CGPoint);
403
404        #[cfg(feature = "objc2-core-foundation")]
405        #[unsafe(method(applyTorque:))]
406        #[unsafe(method_family = none)]
407        pub unsafe fn applyTorque(&self, torque: CGFloat);
408
409        #[cfg(feature = "objc2-core-foundation")]
410        #[unsafe(method(applyImpulse:))]
411        #[unsafe(method_family = none)]
412        pub unsafe fn applyImpulse(&self, impulse: CGVector);
413
414        #[cfg(feature = "objc2-core-foundation")]
415        #[unsafe(method(applyImpulse:atPoint:))]
416        #[unsafe(method_family = none)]
417        pub unsafe fn applyImpulse_atPoint(&self, impulse: CGVector, point: CGPoint);
418
419        #[cfg(feature = "objc2-core-foundation")]
420        #[unsafe(method(applyAngularImpulse:))]
421        #[unsafe(method_family = none)]
422        pub unsafe fn applyAngularImpulse(&self, impulse: CGFloat);
423
424        #[unsafe(method(allContactedBodies))]
425        #[unsafe(method_family = none)]
426        pub unsafe fn allContactedBodies(&self) -> Retained<NSArray<SKPhysicsBody>>;
427    );
428}
429
430/// Methods declared on superclass `NSObject`.
431impl SKPhysicsBody {
432    extern_methods!(
433        #[unsafe(method(init))]
434        #[unsafe(method_family = init)]
435        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
436
437        #[unsafe(method(new))]
438        #[unsafe(method_family = new)]
439        pub unsafe fn new() -> Retained<Self>;
440    );
441}