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
Clearly, the function eases in over time. Changing the definition of t
to
let t = 1 - Double(elapsedTime)/duration
and plotting p
gives
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
Completion block never called at end of SKAction sequence of groups
I want to focus your attention to these few lines:
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:
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:
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
Rxswift + Mvvm + Coordinator Pattern, How to Wait for Coordinator Result Sequentially
Tintcolor Not Changing for UIbarbuttonitem for .Normal Stage in Case of iOS 13.2
Tvos Button Inside Navigationlink Is Not Working
Swift Getnameinfo Unreliable Results for Ipv6
Show Status Bar Only for iPhone X
Using a Timer in The Background Thread to Update UI
Swift Initialization Rule Confusion
How to Convert an Array to List in Realm
Implement a Crosshair Kind Behaviour in Realitykit
Alamofire Request Not Working in Swift 4 Project
How to Disable a Button of a Nstoolbar of Macos X in Swift
Parse Migration Error to Mlabs and Heroku
Swift Error "Static Member Cannot Be Used on Instance of Type"
How to Use Nscalendar Range Function Within Calendar
Uitextfield with a Placeholder Containing an Image and Text
Tableview to Display Different Images on New Controller