hi all
i'm beginner to iOS
i'm trying to make a game when i use NSTimer for action a Ball (for example)
and use CGPointMake for posing in the view its so unreal i mean its like an
old pc with low ram (frame frame) i thought i need to use a Framework for THIS
Can any body help me?
-(void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration{
xValue = acceleration.x*80.0;
yValue = acceleration.y*80.0;
ball.center = CGPointMake(ball.center.x + xValue, ball.center.y);
if (ball.center.x < 24.0) {
ball.center = CGPointMake(24.0 , ball.center.y);
}
if (ball.center.x > 296.0) {
ball.center = CGPointMake(296.0 , ball.center.y);
}
}
Definitely go for cocos2d and Box2D for your physics:
http://www.cocos2d-iphone.org/
http://www.box2d.org/
There are plenty of tutorials out there on both.
I'm not sure I completely understand your question.
OpenGL is a good framework to use for game creation, especially graphics rendering on iOS devices.
Here is a good tutorial you might like to follow.
Here:
http://www.iphonedevbook.com/
If you register on the forum, you can download the sample code from the book "Beginning iPhone 3 Development".
Chapter 15 is called "Ball", and has code which rolls a ball around the screen, based on input from the accelerometer.
cocos2d is a nice framework for writing iPhone games
http://www.cocos2d-iphone.org/
Related
I know there a many questions regarding this topic but they are all very old and I can't find a resource explaining how to do it in cocos2d v3.x and in Swift. I have some PNGs in a folder in SpriteBuilder and I have made it a Smart Sprite Sheet but I don't know what to do from there. The other questions' answers made me believe this would work:
hero.setSpriteFrame("image.png")
I have tried it but there is no method called that.
Thanks
SWIFT CODE
var hero = CCSprite.spriteWithImageNamed("hero.png") as CCSprite;
var frame = CCSpriteFrame.frameWithImageNamed("ImageName.png") as CCSpriteFrame
hero.spriteFrame = frame;
Obj.C CODE
#define SPRITE_CACHE ([CCSpriteFrameCache sharedSpriteFrameCache])
carSprite.spriteFrame = [SPRITE_CACHE spriteFrameByName:#"redCar.png"]
I've been searching some information about Core motion and gyroscope, and I haven't yet found any proper answer.
I'm working with Xcode 5
My question:
How can I make an image (or in this case a player) to go left or right by tilting the iPhone, just like the character in the game called "Doodle Jump"?
I've already got it jumping, but I can't make it move left or right by tilting the iPhone.
I also have a developer account, and I've tried it with an actual device.
Any sort of help would be much appreciated!
1.Create a new Spritekit project:
2.Add the Core Motion Framework
3.Add this code in the 'touchesBegan' method of you MyScene.m file:
sprite.size=CGSizeMake(20, 20);
4.Add this code in the 'update' method of you MyScene.m file:
CMMotionManager* _motionManager;
-(void)update:(CFTimeInterval)currentTime {
if (_motionManager==nil) {
_motionManager=[[CMMotionManager alloc]init];
_motionManager.deviceMotionUpdateInterval=0.25;
[_motionManager startDeviceMotionUpdates];
}
SKSpriteNode *sprite;
for (int i=0; i<self.children.count;i++) {
sprite=[self.children objectAtIndex:i];
sprite.position = CGPointMake(sprite.position.x * _motionManager.deviceMotion.attitude.pitch*10, sprite.position.y);
}
}
You can find a more detailed version here.
Here's a small video with the result of this code
I'm developing an opengl es game for ios that requires accelerometer and multitouch.
I have an EAGLView, that uses an ESRenderer where the drawing occurs.
the EAGLView implements the accelerometer and receives touches:
#interface EAGLView : UIView <UIAccelerometerDelegate> { ...
touchesBegan, touchesMoved and touchesEnded are also in this class.
All the logic for the game is split in several c++ classes for cross-platform reasons, in the drawView i send the acc. values to the game logic:
- (void)drawView:(id)sender
{
appAccelEvent(ax, ay, az);
if (sys_call == S_TOUCH_EVENT) {
appTouchEvent(eventType, 0, cx0, cy0);
}
[renderer render];
}
I have been using an iphone with version 3.1.3 as testing device and everything is ok. but now i'm testing it on ipod touch with version 4.2.1 and the delay for the touch and accelerometer events to respond in the game is too large, sometimes between 1 and 2 segs.
I've been thinking it might be some kind of buffer for the accelerometer update interval that slows down the renderer. What else could be causing this lag?. i really appreciate any suggestions to fix it.
You should use CMMotionManager on iOS 4+, it's heavily tuned by Apple for performance and accuracy. Use it in poll mode (calling -deviceMotion periodically) in your game loop, it'll be much more performant than async notifications and just as accurate.
I'm about to begin building an iPhone game that will make use of Game Center Achievements and high scores, but I'd also like to have a version that works on iPhones that don't have Game Center (i.e. iOS version < 4.1). Can I have two versions of the same app in the app store, one for game center, one for without? Or should I design the app such that if the iPhone doesn't have Game Center, it won't make use of it, and if it does, it will make use of it?
I'm going to continue researching this, just thought I'd post this question and get some feedback in the meantime. Thanks so much!
Here's the definitive response I received from one of the Apple engineers...
"We'd recommend making one version of the app which dynamically detects whether Game Center is available and uses it (or not) based on that."
Maybe create a game without it, then create the capabilities for the game center, but disable them, and only enable them if they have the right version.
I am doing the same thing. If you have GameCenter capabilities, you can use the features. If you don't, you can't.
I would not program a game without and then add it later. In my case I disable Multiplayer for non-GC users.
Also, you may want your game to work if the device has GC capabilities, but the user cannot, for whatever reason, connect to GC currently.
You can use the following function to detect if the device supports Game Center:
BOOL isGameCenterAvailable()
{
// Check for presence of GKLocalPlayer API.
Class gcClass = (NSClassFromString(#"GKLocalPlayer"));
// The device must be running running iOS 4.1 or later.
NSString *reqSysVer = #"4.1";
NSString *currSysVer = [[UIDevice currentDevice] systemVersion];
BOOL osVersionSupported = ([currSysVer compare:reqSysVer options:NSNumericSearch] != NSOrderedAscending);
return (gcClass && osVersionSupported);
}
However I found that a lot of people have not updated to iOS 4.1 or are naive about Game Center. The number of users in my game is quite small even though there are so many downloads. I was actually considering moving over to Open Feint which is very much easier to implement than Game Kit and also supports older devices.
HI to all,
I am new in game developing part .Can any one help me out how to develop the game .Because Till toady i am on the normal iphone application developing .Can i develop the game by choosing window or view based application .If yes then give me some kind of sample code or link for that.
Thanks in advance
Its better to use a game engine like cocos2d. But u can make games by choosing view based application also. Refer "Apress Beginning iPhone Games Development" it helps u a lot.
you're probably best off using a games engine (google cocos2d) or similar to be honest. They come with their own starting templates that you can use, rather than using a view or window based application.
You should make the object with help of sprite class.You can make Sprite and AtlasSprite classes with help of Apress book. and read all about these classes before use.
Sprite *obj; (in .h file)
//in .m file
obj = [AtlasSprite fromFile:#"img.png" withRows:1 withColumns:1];
//now set the properties of the obj.
//for moving set
obj.x = 20; obj.y = 25; //by default x,y is 0,0
obj.speed = 120; //120 is just for example
obj.angle = 0; //for left to right movement
obj.angle = 180; //for right to left movement
timer = [NSTimer scheduledWithTimeInterval:1/10 target:self selector:#selector(func) userInfo:nil repeats:YES];
-(void)func {
[obj tic:1/20]; //for moving obj. 1/20 is just for example
}