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