I have a birdNode(spriteNode) traveling horizontally across a portrait scene.
The birdNode is dropping an egg(spriteNode) towards a cgPoint at the bottom of the screen.
I want the birdNode to randomely drop his egg at any time/position.
I have considered creating an NSTimeInterval with a random number between 2 seconds(time it takes birdNode to travel across screen), making the eggNode spawn at birdNode position, and invoking dropEgg function.
I have also considered generating a random CGPoint, loading the eggNode at
birdNode.position.x = randomPoint
and then invoking the dropEgg function.
My question is should I use a certain approach over another? Where exactly should I call the dropNode function. Right now i can not get it to work.
I have tried to consider randomTime/randomPosition in the currentTime update function below and drop the Node, but it makes eggs at every frame render so I don't think thats the right way.
override func update(currentTime: CFTimeInterval) {
}
Here is my code for dropping the egg, and creating a random dropPoint float, and bird flying across screen.
func dropEgg(){
//aim
let dx = eggNodeTarget.position.x - birdNode.position.x
let dy = eggNodeTarget.position.y - birdNode.position.y
let angle = atan2(dy, dx)
dragonProjectileNode.zRotation = angle
//Seek
var vx = turretNode.position.x
var vy = turretNode.position.y
//creates eggNodeSprite
loadEggNode()
//shoot
let shootAction = SKAction.moveTo(CGPointMake(vx, vy),duration: 0.75)
eggNode.runAction(shootAction)
}
func loadRandDropLocationX() -> CGFloat{
//or minNodeTimeValue?
var MinNodeSpawnValue = self.frame.size.width * 0.2
//or maxNodeTimeValue?
var MaxNodeSpawnValue = self.frame.size.width * 0.8
//or randomTime?
var randomPointUInt32 = UInt32(MaxSpawnValue - MinSpawnValue)
return (CGFloat(arc4random_uniform(randomPointUInt32)) + MinNodeSpawnValue)
}
func dragonMoveRight(){
let moveDragon = SKAction.moveTo(loadRandDestinationRight(), duration: 2.3)
dragonNode.runAction(moveDragon)
}
Aucun commentaire:
Enregistrer un commentaire