SpriteKit - scene "exploding" under certain conditions - sprite-kit

I got a weird one. I'm making a game that involves stacking. Player touches the screen to drop objects and they need to stack up. My scene has a container view that is 10x bigger than the screen in both dimensions.
A woodpecker periodically drifts in from the left and bumps into the stack, threatening to topple it. I make the woodpecker stick to the stack by adding a fixed joint to one of the objects in the stack, the first one it makes contact with.
Here's what's happening: the play goes along fine for a while. As the player stacks up objects, I scroll the container down so that it appears to be panning up, to follow the top of the stack. When the stack gets to about 1500 points offset, weird things start happening. When the woodpecker bumps into the left side of the stack, suddenly the whole thing explodes! The items in the stack and woodpeckers seem to have been hit by a baseball bat. They suddenly fly away at some incredible speed. There is nothing in my code that would make it do that that I know of, and nothing particular about the offset of 1500.
I've NSLogged the X and Y positions and rotations of the woodpeckers and stack items. After one of these 'explosions', I see several sprites at very high number positions (abs value), like hundreds of thousands, and they're spinning wildly (as if they had been hit with an explosions!)
This can go on for a few explosions, then, eventually the X and Y positions of 1 to 3 sprites becomes "nan". This is correlated with a drastically reduced frame rate, like down to 0.1.
There's way too much code to include, and this problem is so weird I have no idea which snippets are most relevant. If someone has an idea of how to approach debugging this, would greatly appreciate it. Or let me know which bits of code you'd like to see if needed.
I've tried removing the fixed joint. When there are no fixed joints, the problem doesn't happen. It's also worth noting, that the woodpeckers do not respond to gravity but the stack items do. I've tried changing this too, but same problem.

Related

UnityVR - Having the both renders display the exact same image for each eye

When Unity builds a VR project, by default it is set to make the two views stereoscopic. It slightly offsets the camera position of one eye to give the user a sense of depth.
For example a square will appear slightly to the left on the right view compared to the left view.
I want to make the camera truly monoscopic by removing the offset that is created when i build the project. Each camera should render all objects in exactly the same position for both eyes.
One of things i tried was creating two camera and setting them to the left and right eye. Then i manually set the position/rotation of one camera until it looked monoscopic
It worked fine on my pixel phone, but as soon as i put the project on my test phone i noticed that the difference in resolutions messed up the view i was going for. The blocks were not in the same position when i looked at both renders.
If anyone has any solutions or ideas as to how i can go about this, i would greatly appreciate it.
Thank you!
You can still use 2 cameras, but instead of offsetting them, you can just make the width of the camera half.
Make 2 cameras, set their positions to exactly the same.
On the left eye camera, set the width to 0.5 and the x position to 0.
On the right eye camera, set the width to 0.5 and the x position to 0.5.
You should now have 2 cameras rendering the exact same thing, but twice across the screen, with no sense of depth.

Sprites are disappearing when I zoom in Unity

In the scene view when I zoom in past a certain point all the sprites (apart from one) disappear and it makes it near impossible for me to edit them because they become too small to see clearly.
This only just started happening everything was fine before and I don't think I have really changed anything that could have affected their ability to show when zoomed in.
The z positions have to be same as that of the canvas I am using
Press the F key a couple of times after selecting the sprite... it's for focus or something after you see it focus ...you will be able to zoom in endlessly to edit this is for sure a bug....I tried restarting unity first..then I tried adjusting the clipping low rate on the camera that is usually 0.3 to pure 0...and that was not it... the F key always gets it done I don't know why...also I changed the cameras near clipping plane back to 0.3 because it was not the issue.

Scrollviews and Cocos2D

I'm trying to develop a scrollable tile map in Cocos2D which uses an UIPanGestureRecognizer to do the dirty work, but while developing it, stumbled upon some problems for which I would like to ask for an advice.
The basic scrolling management works fine, it's precise and accurate and works by adding the translation recognized by the pan gesture manager to the tiles of the map. The problem is that the map is large and I just draw a small viewport of it, while I want to manage it like it's scrollable without any problem.
What I was thinking about is that, as soon as a whole row or column get out of the visible screen, it is moved to the opposite side, the corresponding texture rects are updated (I'm working entirely with a CCSpriteBatchNode), so that it will continuously update the viewport to make the whole thing work. This seems fine but I've found many problems in dealing with when to move the row/column, how to keep track of this issue (eg when pan changes direction from forth to back) and many little details which make me think that I should find a better approach.
Is there a common solution to my problem? That is: managing a scrollable viewport of a tilemap which should move over the whole map so the to the end user it seems like as if the map is infinite.
Thanks in advance
I solved my issue by developing a viewport in which rows and columns are effectively moved from left side to right side and from top side to bottom side.
This is done automatically when a new column or row enters the viewport and it's made by expanding the drawn viewport over the real one by an amount which is enough to avoid any graphical issue to the user.

Blinking UIView

For my iPhone app I'm creating some rotating gears with the help of some subclassed UIViews.
I have created subclasses that rotate themselves triggered by a timer.
In one place I have one of these subclasses within another one (so rotation within rotation, think moon rotation around earth and it's own axle). It all rotates fine and dandy, but sometime, like once or twice a minute, I see a very quick white blink in the area of the UIViews. Sometimes in the upper half, sometimes in the lower one and sometimes the whole area (which is only about 128 x 128 pixels).
I rotate by using CGAffineTransformMakeRotation.
I guessed it was due to performance problem, but after simplifying images (no more photoshop made drop shadows in PNG for example) and reducing the number per second the timer is called (2 times per second instead of 5) I still have the problem. CPU load is now down to between 9-25% (from around 47%) when measured in Instruments on a iPhone 3G. Still blinking!
Any clues on where to begin troubleshooting or any better way to rotate images within a view?
All ideas appreciated!
Basically I had an animation in an animation. Not technically skilled enough to say WHY that caused a problem, but removing the second animation solved the problem. My animations were of the type [UIView animateWithDuration... in which I did several CGAffineTransformMakeRotation's

Infinite maps/scrolling question

I'm using cocos2d for the iPhone to create an infinitely scrolling horizontal tile map. To achieve this, I've generated a library of 'segments', which are basically horizontal chunks of levels that I randomly choose from and append to the end of that particular levels tile map. When tiles scroll off of the left of the screen they are removed from the layer and released. This all works fine.
My question revolves around the legitimacy of the scrolling method I've chosen. Following guidance from this article, I've been scrolling my map by updating the layers position at regular intervals (subtracting from the x axis to move the layer to the left). And while this works, I'm concerned that there's probably some finite limit to the positioning of a layer. Am I going to run into issues after a certain amount of time has passed (when the layers x-axis position is considerably large?)
Any thoughts on my approach would be appreciated.
This is a good question. What I would do is run some tests on how far you can position the layer. I placed a sprite and focused the camera to ccp(1000000000000000, 1000000000000000) with no issues.
Do you really think this would be an issue in real gameplay? Seems like it would take a very long game to reach a position like that.