I've finished my game which uses the method + (SKAction *)moveToY:(CGFloat)y duration:(NSTimeInterval)sec to move sprites and when they collide with another sprite they disappear but when one of them collides with another object and disappears the other sprites that are falling down make some lag and I don't know if I could use another method to move sprites without lag.
PS: The sprites move a little bit fast(from y:0to y:568 in 0.5 seconds), is that maybe the problem?
Related
I am making an SpriteKit game involving sorting colored balls with a rotating funnel that rotates based off where you move your touch. Problem is if someone swipes across the screen really fast, balls will move right through the physicsBody on the funnel. I am changing the zRotation of the funnel with each call to touchesMoved(). Both the balls' physicsbody and the funnel's physicsbody has .usesPreciseCollisionDetection to true. .isDynamic is false for the funnel.
I figure when someone swipes across the screen, the animation is happening so fast that the framerate cannot keep up and as the funnel rotates, there is such a large gap in its rotation that the ball ends up on the other side of the physicsbody in a single frame.
Is there any way to fixing this? I am new to SpriteKit, any help is appreciated. My code is here
I guess someone must have asked this before, but I can't find it right now so in the meanwhile here goes.
Animations of SpriteKit overlay on SceneKit stops when SceneKit animations stop. This is unexpected. It's like the whole SCNView and its children goes into sleep as soon as the 3D contents don't move. How can I make the spritekit scene animate independently of what the scenekit scene does?
Update: I have confirmed that if I add a simple 3D box that rotates indefinitely and keep it in the view somewhere, the 3D scene does not "sleep" and neither does the overlay. Is there a setting somewhere to stop the SceneKit part from sleeping?
Background:
I use SCNView.overlaySKScene. I have a indefinitely repeating animation of one of the subnodes of that overlay. As soon as an action and/or animation goes on in the SceneKit scene, the overlay 2D stuff also animates, but stops as soon as the 3D animations stop.
iOS 9.2.1.
A SceneKit view runs its update/render loop only when it knows there's animation going on. (Because if there's no change in what's to be rendered, rendering just wastes CPU/GPU time and eats up battery power.)
SceneKit is rather conservative in guessing when it should run the render loop. It runs if there are CAAnimations or SCNActions in the scene or if the physics engine is doing something, but I think that's about it.
If you've got other stuff that wants to run the render loop (like an overlay SKScene that needs to run its own game loop), just set the view's playing property to true.
I have a game where a user is dragging around my main sprite. The main sprite collides with other sprites just fine except when the user drags the main sprite very quickly. Sometimes when the main sprite is moving quickly, the physics bodies just pass right through each other and the two sprites suddenly overlap. I have a breakpoint set that logs the hit count at didBeginContact, and it is not hit.
Is there a limit to how fast a sprite can move and still be covered by didBeginContact? Am I allowing the user to move the sprite faster than the game cycle can handle the collisions?
Again, when the sprite is moving at slow speeds, the physics are working perfectly.
Remember, these things are all calculated frame by frame. You're probably moving the sprite so fast that its ending up on the other side of the screen in too few frames to count as a collision. If someone is spastically moving their finger around it might not catch it. You could put some kind of speed limit on the sprite or something.
try to set physic body with usesPreciseCollisionDetection = YES
The problem I am facing is that I have absolutely no idea how to create multiple balls that move with their own speed, have their own location. That kind of thing. When I click the screen, a ball should start moving up. When I click again, another ball should start moving up. You get the idea. I've looked at several source codes and tutorials but I really don't understand how this is achieved?
You should probably be doing this with SpriteKit (see video)
But if you want to keep it really simple, your approach could be something like:
Create a Ball class (object) (this could, if you want, contain the image of the ball)
Initiate a new Ball object on every touch: Ball *ball = [Ball alloc] init]];
Start animating the newly created ball (using basic animation for instance)
I'm implementing a side scrolling game with SpriteKit:
As long as my sprite stays in the middle of the screen, I'm moving the sprite
When the sprite reaches the left or the right part of the screen, I'm moving the level instead of my sprite:
This works quite well, unless my sprite collides with another object. In that case the level (triggered by my code) and the sprite (triggered by the physics engine) are moved and the sprite moves outside the screen:
I tried to stop the impulse which is applied from the physics engine. This hasn't worked.
Any idea how to handle this?
Thanks
Stefan
I suppose by "moving the level" you mean moving the background view.
Why don't you just have an area in which your sprite moves that is the same size as your background? You can scroll to keep the sprite visible without disturbing the logic of physics and other manipulation of the movement.