Skease Action, How to Use Float Changing Action Setter Block

SKEase action, how to use Float changing Action Setter Block?

If you type let fn = SKEase.getEaseFunction( and then a dot for the enum types for curve-type and ease-type you'll get completion.

With the SKNode to SKShapeNode you'll have to cast.

Here's some code:

    let fn = SKEase.getEaseFunction(.curveTypeQuadratic, easeType: .easeTypeInOut)
let easeFat = SKEase.createFloatTween(2.5, end: 30.0, time: easeTime/2, easingFunction: fn) { (node: SKNode, param: CGFloat) in
let spinny = node as! SKShapeNode
spinny.lineWidth = param
}
let easeThin = SKEase.createFloatTween(30.0, end: 2.5, time: easeTime/2, easingFunction: fn) { (node: SKNode, param: CGFloat) in
let spinny = node as! SKShapeNode
spinny.lineWidth = param
}

if let spinnyNode = self.spinnyNode {
spinnyNode.lineWidth = 2.5

let rotate = SKAction.rotate(byAngle: CGFloat(M_PI) * CGFloat(2.0), duration: easeTime)
let easeFatThin = SKAction.sequence([easeFat, easeThin])
let rotateAndEase = SKAction.group([rotate, easeFatThin])

spinnyNode.run(SKAction.repeatForever(rotateAndEase))
spinnyNode.run(SKAction.sequence([SKAction.wait(forDuration: easeTime),
SKAction.fadeOut(withDuration: easeTime),
SKAction.removeFromParent()]))
}

And a complete project on my GitHub.

EaseOut action with custom SKAction

We can modify the following code to allow the custom action to ease-out instead of ease-in

let t = Double(elapsedTime)/duration
...
let p = t*t*t*t*t

To get a better understanding of p, it is helpful to plot it as a function of t

Sample Image

Clearly, the function eases in over time. Changing the definition of t to

let t = 1 - Double(elapsedTime)/duration

and plotting p gives

Sample Image

The action now eases out, but it starts at 1 and ends at 0. To resolve this, change the definition of p to

let p = 1-t*t*t*t*t

Sample Image

Completion block never called at end of SKAction sequence of groups

I want to focus your attention to these few lines:

Sample Image

The offending code is:

curtain.run(fadeMoveWipeAndReveal, completion: {
onDone()
print("I'm done!!!!")
})

where you can substitute fadeMoveWipeAndReveal with one of the other action like simply show:

let show = SKAction.run(reveal)

and you will see the completion is never called. Why? Because it run the first time during the WipeCurtain initialization but the action is removed before it completes, so the next time you re-call this one to run through touchesBegan, completion will never called.

You can test it by putting a breakpoint to the curtain.run code and launch the project:

Sample Image

as you can see the breakpoint stop the project immediatly during initialization, in this phase, action is removed before it completes.

About your workaround,that's correct, it works because you remove completion and use the simply SKAction.sequence that is executed correctly every time you call it.


Details:
The copy method works for me, I suspect some people have problems with it because around internet there are more versions about the SKEase and maybe some of that could have a problem, but this version works well as demonstrated by these two screenshots below:

Sample Image

Sample Image

Check if SCNNode SCNAction is finished

I ended up using a .customAction:

I added a class variable isJumping

then at front of the function code I added:

 isJumping = true

and added the SCNAction:

 let jumpDone: SCNAction = SCNAction.customAction(duration: 0, action: {_,_ in self.isJumping = false})

then changed the sequence to:

 let sequenceLook = SCNAction.sequence([lookDown, noLook, lookBack, jumpDone])

then I just do an if on isJumping to see if the jump movement has completed.

Why doesn't objectAnimator doesn't call setter method

As said in the developers guide:

The object property that you are animating must have a setter function
(in camel case) in the form of set(). Because the
ObjectAnimator automatically updates the property during animation, it
must be able to access the property with this setter method.

The getter (if needed) and setter methods of the property that you are
animating must operate on the same type as the starting and ending
values that you specify
to ObjectAnimator.

For example, you must have targetObject.setPropName(float) and targetObject.getPropName(float) if you construct the following ObjectAnimator:

ObjectAnimator.ofFloat(targetObject, "propName", 1f)

So you need to change your method to:

setCurnum(float f)

Protecting numpy attributes using setters and getters in Python

Your speculations are essentially correct. There is no such thing in Python as "protecting" a mutable object from modification, and NumPy arrays are mutable. You could do the exact same thing with plain Python lists:

@property
def my_list(self):
return self._my_list # = [1, 2, 3, 4]

@my_list.setter
def my_list(self, value):
self._my_list = [float('inf') if x < 0 else x for x in value]

It's not exactly clear to me what you want here, but if you want the numpy array returned by your attribute to be immutable you could set array.setflags(write=False) on the array. This will also make slices of the array immutable so long as the slices are created after setting the write=False flag.

However, if you want some kind of magically bounded NumPy array, where any operation on the array will enforce the bounds you've set, this is possible with an ndarray subclass, but non-trivial.

Still, none of these options would prevent someone from just re-casting the underlying data to a mutable array.

The only way to completely protect the underlying data is to use a read-only mmap as the underlying array buffer.

But TL;DR there is nothing magical about accessing a Python object through property that can make that object immutable. If you really want an immutable data type you have to use an immutable data type.

Unity getter setter limitation doesn't work

Besides you not checking value as you have already figured actually your code can be simplified a lot by simply using Mathf.Clamp

private float TouchX
{
get { return touchX; }
set
{
touchX = Mathf.Clamp(value, -10, 10);
}
}


Related Topics



Leave a reply



Submit