Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Mastering iOS Game Development

You're reading from   Mastering iOS Game Development Mastering iOS Game Development

Arrow left icon
Product type Paperback
Published in Dec 2015
Publisher Packt
ISBN-13 9781783554355
Length 228 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Authors (2):
Arrow left icon
Peter Ahlgren Peter Ahlgren
Author Profile Icon Peter Ahlgren
Peter Ahlgren
Miguel DeQuadros Miguel DeQuadros
Author Profile Icon Miguel DeQuadros
Miguel DeQuadros
Arrow right icon
View More author details
Toc

Gravity – player movement

For now, import the Player images (in the sprites.atlas file) I have provided in the resources section of this book. Unless you have your own! Then by all means use yours.

Let's go back to our GameLevelScene.m file and import yet another file. This time, it will be #import "Player.h". Then, after the @interface section that we added earlier, we are going to add another property similar to the map property we just added: @property (nonatomic, strong) Player *player1. I used player1 because we will be adding in some multiplayer features later!

Then again, inside the initWithSize function we will add the following code:

self.player = [[Player alloc] initWithImageNamed:@"P1Idle"];
self.player.position = (CGPointMake(100, 50);
self.player.zPosition = 15;
[self.map addChild: self.player];

When we build and run our project, we should get similar results as seen in the following image. I think it's starting to look pretty cool!

Gravity – player movement

Hold on cowboy...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime