speed up timer game in Xcode - ios

hi i am building my first basic game in Xcode for the iPhone i have one issue its facing me
the game is snake eating food i need the correct way to speed up UIimageView .
i had try to speed up the NSTimer but ever time the level 1 work fine then when i go to level 2 the snake and the score not working correct ??
so please i need the correct way to increasing the speed of image without effecting the next level
or the correct way to speed up the timer ..
if any one can help me i am ready to sure the code with him by e-mail need some help pleeeeeeease .

It's not possible to synthetically speed up the iOS simulator.
Your only option is to increase the firerate of your NSTimer.

Related

How to know how much time the player is in air (Roblox)?

I just created a Roblox game of shooting. The main target of the game is to stay alive as long as possible. But I recently noticed while playing other games that people use mods for flying in air. (In simple words 'hacking').
If the people use that in my game also they might be the one and only winner always.
So I decided to check when a player is not touching any object (In air) for more than 5 seconds the the player should die.
But then I searched In Google if there are any ways that I can do that. But found none. If anyone know how to achieve that can please help me...
Thanks in advance
This is the result of my 1 minute google search, no idea what you searched for...
From: https://developer.roblox.com/en-us/api-reference/property/Humanoid/FloorMaterial
When the Humanoid is not standing on a floor, the value of this
property will be set to Air.
The code sample below demonstrates how to listen to when this property
changes using Instance:GetPropertyChangedSignal
So if the material changed to Air you start a 5 second timer.
If the player lands stop the timer. When the timer finishes, kill the player.
There are some comments that FloorMaterial might be problematic if the player is swimming. So probably use https://developer.roblox.com/en-us/api-reference/event/Humanoid/StateChanged to start and stop the timer.
That should give you plenty of starting points. I won't give you any code. Make yourself familiar with the examples and you'll come up with a solution quickly.

Scaling (zooming) CameraNode lags overtime

Im using Swift 3.0 and I'm attempting to use the SKCameraNode class as a camera for my game.
I move it around, rotate, and zoom in and out a lot. For some reason, it goes in and out of having these rough patches (about 30 seconds) where it's super etchy, as if it were only being updated a tenth of the usual time. Note that NOTHING else in the game is lagging except camera movement.
However this is only extremely noticeable when I'm trying to zoom in and out.
The occurrence usually happens after a burst of moving it around a lot, but not always. Sometimes it happens the second the app is started, and other times never.
Here is my code, which is running in didFinishUpdate:
camera.run(SkAction.scale(to: size, duration time))
time is usually 0.0, but sometimes not, so I would like to try to keep this as an SKAction if possible. However, I assume the problem resides in using this SKAction. (I'm like 99% sure the problem isn't that I'm accidentally not passing 0.0 for time)
So what should I do to either fix or work my way around this problem? Is this just a limitation of a Swift?
EDIT: I have now also tried using it in other update functions. I also tested to see the run time of didFinishUpdate (To see if it was lag), but it remained consistent. Also, this happens when i try to rotate the camera as well.
ANOTHER EDIT: I've also tried setting gamePhysics speed to 0.9999 which was suggested in another post with a lag problem
Thanks!

My game app is running slow on my iOS device

I've been encountering some problems when testing my app from XCode to my iOS 6.1.6 iPod touch 32GB. For my game, images frequently fall and I am not sure if that is the problem. Someone told me that my app could be running slow because I have too much memory on my iPod, but I already cleared most of my memory.
My question is, how can I make my app run fast on my device?
It runs really smooth on my iOS Simulator but it's terrible after 5 seconds when tested on my device.
The code that makes my images fall is like this
imageView1.center = CGPointMake(imageView1.center.x+pos.x,imageView1.center.y+pos.y);
imageView2.center = CGPointMake(imageView2.center.x+pos.x,imageView2.center.y+pos.y);
imageView3.center = CGPointMake(imageView3.center.x+pos.x,imageView3.center.y+pos.y);
imageView4.center = CGPointMake(imageView4.center.x+pos.x,imageView4.center.y+pos.y);
pos = CGPointMake(0.0, 3.0);
I also have a timer set at 0.03.
Also, when every image falls, when it hits the bottom, a new image is made out of random. It's a loop.
Any UIKit operations frequently occur take a load on your iPods processor. Your mac CPU is so much faster and you've got a ton of more ram so that's why it works on the simulator. You could try reducing the frame rate (the timer interval) and see if that solves the problem. I'd suggest you stay away from UIKit for making games and instead use the new iOS 7 framework, SpriteKit. (A google search will find the documentation) Frameworks like SpriteKit or Cocos2d are slightly more difficult to learn, but they have engines optimized for running games and using your iPods gpu. How complex is your game? If it's more than just one screen with moving objects I'd consider rewriting the entire thing in SpriteKit. Sorry to let you down on your first game but UIKit is nearly never the way to go when making games. Good luck!

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);

Input Delay at start of iOS game

When I run my iOS game on a device, for a minute from the start approximately there is a delay in input: when I touch the screen somewhere, the game recognizes that touch only after 2 to 3 seconds; the accelerometer also shows the current orientation from 3 seconds ago!
I know it's not my coding, because after the first minute (approximately), the game starts behaving correctly, with input recognized at real time.
I suspect it also has something to do with my game running slow, but I can't find what's causing it. Is there something general that could be causing the delay, or can it be something specific to my code?
There is so many reasons for this, but as a start try using Instruments to record the performance of the game, and u could postpone the actual start of the game a few seconds till everything gets properly loaded.
it is very likely that there is a loop somewhere that is doing quite more iterations than it is supposed to.

Resources