IOS Sprite Kit Latest features Physics field virtual Physics field Swift test

Source: Internet
Author: User

On the WWDC2014, the Sprite kit has a lot of new improvements!

One of the very interesting things is physics field! That's the physics field!

This means that our game of writing virtual physics on the Sprite kit will become very simple!

Here I'm based on the demo on WWDC2014 's official video on what's new in the Sprite kit,

I made a demo with Swift language.

As follows:


Put the GitHub link first:

Https://github.com/songrotek/PhysicsFieldsWorld.git

I also recorded the effect of the video you can first see as fast:

Http://v.youku.com/v_show/id_XNzI2MzUzNzYw.html


Here's a look at physics field!

1. Overall situation

The physics field of the Sprite Kit Physics field has 10 altogether:


Enum fieldtype{

Case Lineargravityfield//Linear gravity field

Case Radialgravityfield//radiation gravity field

Case Dragfield//Resistance field

Case Vortexfield//Eddy Current Field

Case Velocityfield//velocity field

Case Noisefield//noise field

Case Turbulencefield//disorder field

Case SpringField//Spring field

Case Electricfield//electronics field

Case Magneticfield//magnetic field

}


2. General parameters of the field

Then all types of farms are created and set up in the Skfieldnode class!

Regardless of the type of field, there are some common parameter settings. As follows

field, the object beyond the area is not affected by the field, the default is unlimited

var region: skregion!

Field strength, default is 1

var strength: cfloat

The attenuation exponent of a field used to calculate the force magnitude of a distance, starting from the minimum radius. Default is 0

var falloff: cfloat

The minimum impact radius of the field, which is a very small number by default

var minimumradius: cfloat

If enabled, the farm works by default is true (seemingly less well under swift, estimating beta issues

var enabled: Bool

The exclusivity of the field, if true, the other field cannot function in the region of the field. If there are two fields that have a coincident effect, it is impossible to determine which field action

var exclusive: Bool

The Action object category of the field, default is all

@see Skphysicsbody.fieldbitmask

@see Skemitternode.fieldbitmask

var categorybitmask: UInt32


3. Creation of the Farm

For example, create a spring field:

Let SpringField = skfieldnode. SpringField ()

SpringField. Strength = 0.05

SpringField. falloff =-5

SpringField. position = Fieldcenter

SpringField. name = "SpringField"

AddChild (SpringField)


The same way as the other farm, is that the parameter settings are different depending on the specific needs


4. Every kind of field!

4.1 Linear field linear Gravity field

is in accordance with Newton's second law F=ma

It can be used to create gravity in all directions, of course, with physics world gravity can also be set, but this field can set the range.



4.2 Radiation Gravity Field Radial Gravity fields

To simulate the moon going around the earth, it has to use this, the gravitational field at one point.

4.3 Resistance field Drag field

In this field, like an object, the friction slows down and the friction depends on the speed of the object.



4.4 Eddy Current Field Vortex field

This field can be used to make a tornado effect, the field of force around the center, if the strength is positive is counterclockwise, if the negative is clockwise



4.5 Noise field Noise field and disturbance field turbulence field

The noise field is the force of each position at random, there is a smoothness parameter to adjust the noise force smoothness degree

The noise field is very close to the disturbance, but the effect on the object is small.



4.6 Spring Field

Can make an object like a spring connected to the center of the field and move around the center of the scene.



4.7 Speed Field

You need to add a sktexture texture that determines the force direction of each field location point by the texture.

The effect that can be achieved is, for example, the velocity field of a river, where an object can be moved along a river.


4.8 electric field electric field and magnetic field magnetic field

is Lorenz Force f=q (E * VB), where QE is the electric field Force, QVB is the magnetic force

In order to simulate the electric field and the magnetic field, the physicsbody of the Sprite kit adds charge, which is the charged amount.

But at the moment, in my personal experiment, there's no simulation of electromagnetic fields under Swift, wait for Apple to be perfect.


5 Summary

Physics field is a cool feature that is worth using, very convenient!


Note: This article is original article, if need reprint, please indicate source, from Songrotek's blog "




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.