So, I am developing a game in Sprite Kit for the first time ever. This is a great learning experience for me!
However, I have encountered an issue :( I do not know how to make it so that a function is called repeatedly while a touch is active (for example, a function is called every 0.5 sec that touch is 'touching'). So, I was considering having an SKAction run and then cancel/delete it when touch is released... but I decided against that.
Instead, I was hoping for a function that checks if there is a touch, but not necessarily that a touch was pressed, released, or changed location, i.e. check if a touch is touching, period.
If this is not possible, is the easiest way for me to overcome this quandary what I was thinking of initially, or is there something easier?
Thanks so much in advance!
答案 0 :(得分:1)
If I was you, I would use an window.onload=function(){
var frames=document.getElementsByClassName('devices')[0].getElementsByTagName('iframe');
for(var i=0; i<frames.length; i++){
frames[i].setAttribute('src','http://roostergrin.com');
}
}
(or several) because, in my opinion, it helps keep my code cleaner; you run an SKAction
in one place and then you don't have to worry about it again. This helps keep the SKAction
method free of lots of game logic.
In your comment you mentioned not being sure how to call a function using an update
. You can use SKAction
for that; it takes a closure (or function) that has no arguments and returns SKAction.runBlock
.
Alternatively, you could use Void
to create your own action running a function, although it's not appropriate in this situation. The documentation has more information on custom actions, here's a quick example though: How to create custom SKActions?
Anyhow, Here's how I'd achieve what you were after:
SKAction.customAction...
Hope that helps!