Skip to Main Content
Learning iPhone Game Development with Cocos2D 3.0
book

Learning iPhone Game Development with Cocos2D 3.0

by Kirill Muzykov
June 2014
Beginner to intermediate content levelBeginner to intermediate
434 pages
9h 49m
English
Packt Publishing
Content preview from Learning iPhone Game Development with Cocos2D 3.0

Time for action – making the bird move

It is nice to have a cute bird on the screen, but our hunter can't shoot an unmoving bird, as this is simply not sportsman-like. So, before we give our hunter the ability to shoot, we're going to make the bird fly.

  1. Open the GameScene.m file and add the following update: method below all other methods:
    -(void)update:(CCTime)dt { //1 CGSize viewSize = [CCDirector sharedDirector].viewSize; //2 if (_bird.position.x < 0) _bird.flipX = YES; //3 if (_bird.position.x > viewSize.width) _bird.flipX = NO; //4 float birdSpeed = 50; float distanceToMove = birdSpeed * dt; //5 float direction = _bird.flipX ? 1 : -1; //6 float newX = _bird.position.x + direction * distanceToMove; float newY = _bird.position.y; //7 _bird.position ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Beginning Swift Games Development for iOS: Develop 2D and 3D games Using Apple's SceneKit and SpriteKit

Beginning Swift Games Development for iOS: Develop 2D and 3D games Using Apple's SceneKit and SpriteKit

James Goodwill, Wesley Matlock

Publisher Resources

ISBN: 9781782160144Supplemental Content