SpriteKit Collision lag - ios

I've got a scene where a certain number of nodes spawn at the top of the screen and another batch of nodes at the bottom. Now if they collide, I want the game to end which it does, the only problem is that the collision causes a major frame drop or stutter/lag whatever you can think. It basically stops the game for a second and it continues.
The nodes don't have textures. There are no sounds playing when the nodes collide. I've stripped everything down and left just the nodes to collide and the problem persists. I can't point a finger at where it's really coming from since i've left nothing unturned and the scene is not complex 8/9 nodes most at a time.
This doesn't always happen sometimes the nodes collide and everything runs smooth. The only other information i can provide is that the nodes are moving rather fast so they fly in and out of the scene within 0.05 seconds which i tried setting it to a longer duration the problem still persists just more rarely. When the game is over the user has the option to present the scene again which adds the scene from the beginning.
This question leans more toward people who might have had a similar issue , since I don't know what more information I can provide. (Square nodes collide right away the game stops for a second and continues). Thanks.

Related

Unity deferred point lights disappear at distance

Summary including updates:
Unity 5 scene using deferred lighting, containing approximately 200 lights spread along 800 units of space.
Most of the lights are point lights, some are spots - the spots work fine.
The point lights cut instantly to dark at around 150-200 units away from the camera.
If large numbers of point lights are moved inside this range they work without issue.
Switching the Render Priority between Auto and Important makes no difference.
If I play a different scene in the editor which allows me to load this scene, it displays correctly! It still does not display correctly when played directly or when running the build.
I've got a basic scene together, which consists of 5 cloned sections of corridor, each with 12 lights, so 60 total.
However, only the first couple of sections show properly, the others are almost completely dark:
(please be kind, I only started this one today :P)
And from the editor, with the end section highlighted to show the distance better:
As you can faintly see, the lights are actually there, just very, very dim:
When you walk down the corridor, they snap to full brightness as you approach.
This is on a build with deferred lighting set, and the pixel light count turned right up, just in case.
I' guessed this might relate to LOD or camera range in some way, but I can't seem to get anything to effect the issue currently.
(This scene is actually based around the lights cutting out and switching to emergency lighting so I really do need to be able to control them!)
UPDATE
The lights you can see are spot lights. The lights that are disappearing are all point lights.
You can just see the spot lights uplighting onto the ceiling in the distance, but the main ceiling lights just go completely dark.
UPDATE 2
I've added a frankly silly number of lights into the scene and extended the corridor, to run some tests.
There are now 24 lights per section, and a total of 8 sections, making 192 lights in all:
I wanted to check if more lights would cut out, and they don't. It seems to be entirely based around range - around 150-200 units in my scene.
To confirm this, I also walked to the center of the tunnel to see if the number of lights visible would effectively double, including ones behind - they do.
I also moved all of the sections close to the camera to confirmed that all the lights can be displayed at once without problems, and this works as well.
UPDATE 3
I have found a situation where the scene displays correctly!
If I press play in the editor on my main menu scene, then press the UI button that loads this scene, it displays correctly!
It still does not display correctly either when playing the scene directly, or when running the final build.
My solution for this problem is (I'm new, but I found this helped):
Go to quality settings
Search for Pixel Light Count
Raise this number to actual number of your lights in your scene.
This parameter establishes number of sources of light which can be displayed at they same time - I think.

Is it possible to determine that all Sprite Kit scene collisions have played out?

I've made my way through the pages of SO questions regarding sprite-kit, the docs, available demos, and the vast empty space that is my brain to try and figure this one out but have come up short.
Working on a proof-of-concept that is a turn-based (using Game Center), physics-based game. Players take turns placing a node amongst a collection of other nodes and letting the physics play out. Where I'm flummoxed is in determining that all collisions have played out and the turn has ended.
It would seem that the nodes never stop colliding.
This is a tricky task with physics simulations.
First of all, with gravity enabled you always have a force acting upon bodies that may prevent it from resting. So you need to test every body every couple of steps (or every frame if you must) to see whether its velocity vector length is smaller than a given threshold. Then manually set the body's resting state to YES.
The bodies may wake up again during contacts, so it is crucial to perform this step after contact resolution in didSimulatePhysics.
The trick is in finding a threshold that is large enough to guarantee an end to the "physics entanglements" while not being too high to make objects stop where they clearly shouldn't.
Even then you probably also need to set a timer that starts when every body's velocity is below another (higher) threshold indicating that there will likely be little forces coming from those bodies anyway, and if after a grace period (ie 10 seconds) the bodies are still not all resting but below this threshold, consider the collisions resolved (as far as the game is concerned).
Also the number of bodies still not resting may be an indicator to end the game, ie if there are only 3 or 4 bodies of dozens still moving, there's probably not much going to happen as well.

Transferring billiard game state from player to player with box2d

Im using Union server for my iOS (Starling) billiard game.
So far the connections work great.
My question is:
How would you handle the transfer of the ball positions from the opponent.
Lets say I make the break, and I want to copy that shot to the other player?
Do you think its a good idea to send a message over union every frame (x, y)?
Will this cause latency problems?
First about your question:
The game is installed on both devices, the rules are same. So on shot send the white balls force and all other properties you modify. On the receiving device add that force etc. and the ball will repeat the action done by the sending user.
Now the sad part:
I will be the first one to disappoint you - even if you solve your problem and send the message from player to player with out problems the result won't be pleasant: box2d calculations are optimised for performance, but the result will differ as it's calculated with approximate accuracy. As a result even on the same device the balls will end up in a different location on different runs. You won't notice it in one-two hits, but after playing for a minute you'll end up with deferent ball locations.
You can also try to send a message of every ball position in space after all balls stop moving and relocate the remote users ball positions. After that "correcting" message was received return the control to the player.
We had a similar game and I just wrote my own 2d engine. If you're working only with ball to ball and ball to rectangle collisions it's easy to write your own engine.

Cocos2dx 2.1.4 Game, Continuos FPS drop and never recovers

I am creating a game using cocos2dx 2.1.4. Its FPS drops continuously , and never recover.
Please find the details as follows
Background about the way I am doing things:-
Its game about scrolling down some shapes, each shape is made up of some square blocks.I have 7 kind of blocks. All loaded in a Sprite Sheet and using these blocks from this sprite sheet I create a shape.
A level file is consist of these shapes. I load two levels at the same time one onscreen and another off screen to make it seamless scrolling. For loading two levels at the same time I used two different CCSprite game batch nodes as :-
CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("56blackglow.plist");
_gameBatchNode1 = CCSpriteBatchNode::create("56blackglow.png", 200);
_gameBatchNode1->retain();
this->addChild(_gameBatchNode1,kForeground);
_gameBatchNode2= CCSpriteBatchNode::create("56blackglow.png", 200);
_gameBatchNode2->retain();
this->addChild(_gameBatchNode2,kForeground);
The problem I am facing is that as I keep on playing the game frame rate drops continuously , from 60 fps till 10 fps and never recovers or might recover in near future , as I observed for 20 minutes but its too much time to wait.
My observations:-
1> I used Time profiler it shows maximum time is in draw() calls. Also if I play game very fast the peak of time increases in track, that should be fine as I am giving more work to do, but once a peak is attained it remains approximately at that height only, even if I leave the game Idle. Is it normal ? According to me it should have returned to its normal peak once the current work is done.
2> Some where I thought its happening because I used two batch nodes and removing its children on a user touch immediately might causing it slow but then after removing the children it should run normal. to give an idea is it ok to remove 10 children from batch node immediately ? some guys say its very slow process. Just to check if this causing problem , I did :-
Instead of removing them I just set visibility of the children to false.But still FPS drops and never recovers.
Please share your thoughts on this.
Though SpriteBatchNodes are generally quite good for drawing a lot of elements efficiently, I think there are best used for static/not-so-dynamic elements. In your case, if you have a lot of elements which go out of the screen but are still alive the draw() function will have to make some checks, thus hogging your performance (even if you set isVisible(false); explicitly, it still nedds to be checked).
In your case I think it would be better if you simply added new shapes outside of screen via some time-based function, and if they scroll outside of view simply remove them from scene, without using batchNodes.
Just found that with every touch, I am adding 8 new sprites to the layer, and its adding every time I touch . So with time I am giving more and more work to do. This is the problem
Actually I wanted to replace the sprite at 8 places with a touch, the way I was doing every time :-
_colorBottom1=CCSprite::createWithSpriteFrameName(png[0]);
this->addChild(_colorBottom1,kForeground);
_colorBottom1->setPosition(ccp((_colorPanelLeftPad)*_blockWidth,_blockWidth));
It was causing this sprite to be added with every touch.
but it should have been (Replace the texture instead of creating the Sprite again):-
CCSpriteFrame *frame1=CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(png0);
_colorBottom1->setDisplayFrame(frame1);

btRigidBody objects behave strangely when colliding at slow speeds

I'm trying to use Bullet Physics in my iOS game. The engine appears to be correctly compiled in that the demos work fine.
In my game I have the player's ship and some enemy ships. They're defined as btRigidBody objects and btCollisionObjects and I'm using btSphereShapes for collision.
At 'fast' speeds, collisions appear to happen sensibly - things collide and nothing goes 'weird'. If the speeds are very slow though and the player's ship touches a non-moving object the collision happens, but then the player's ship moves at incredible speed over the next few frames and appears a long distance from where it collided - completely out of proportion to the speed it was moving before impact.
To move the things around I'm using setLinearVelocity() each frame, ticking the physics engine, then using getMotionState() to update the rendering code I have.
Part of the issue might be I don't quite understand how to set the correct mass or what the best speeds are to use for anything. I'm mostly sticking numbers in and seeing what happens.
Should I be using Bullet in this way, and are there any guidelines for deciding on the mass of objects? (am I right in assuming that in collisions heavier objects will force lighter objects to move more)
I'm no expert yet in bullet, but I would not use setLinearVelocity. This is just for initial state, once in the world, if you want to give something a push in the right direction, give it an impulse. This is like being hit with an invisible object so is completely compatible with other collisions. Setting the velocity every frame will completely override the physics engines calculations.
I have noticed that when two objects overlap, they repel each other with a force relative to how much they overlap by. I think your setVelocity method is causing objects to overlap, then eventually the physics engine resolves this in an undesirable way.
I am making a space ship game, I make impulses to cancel out the current movement direction, plus impulses to move it in the new direction as long as the ship is not already moving at my chosen max speed.

Resources