Getting Started with Animations


Dave
 

Hi All,

I’m about to add some animations to my game and was wondering if any could give me some advice on the implementation given my App. This is for iOS Landscape only at present but I am intending on doing a Mac version too, so if it can be made as compatible as possible that would be good.

The App is a Board Game, there are two main views, the left had side is a Player Area and the right hand side is the Board. The View Hierarchy is something like this:

RootView
LeftAreaView
BoardView
CellView’s (81 in total - 9 x 9).
RightAreaView
BagView
ScrollView Containing the Host layer’s current Pieces
Scroll View Containing the Player has the current turn.

The way the game works is that Players pick pieces at Random from the Bag - the Actually “Picking” is done by the GameEngine and the View Controller gets sent a “Player X picked Piece Y” type message. When this occurs I want to Animate the piece Dropping from the “Bag” into the Players “Stash” (One of the Scroll Views). When a player makes a Move, the View Controller gets sent “Player X Moved Piece Y into Cell X” type message, in this case I want to animate the Piece being removed from the “Stash” and Placed on the board.

What is the best way to achieve this? Do I use CALayer?

All the Best
Dave


 


On Jul 13, 2017, at 6:13 AM, Dave <dave@...> wrote:

What is the best way to achieve this? Do I use CALayer? 

Yup, I would recommend using CALayers for the whole UI, pretty much. Back when Core Animation first came out I wrote a framework for building board/card games:
It hasn’t been updated since 2011 so it probably needs some fixes for API changes, but I still think the basic design is pretty well thought out. The goal was that you could implement a simple game UI in <200 lines of code, and there are examples included for checkers, tic-tac-toe, Klondike solitaire, and a few others.

—Jens


Dave
 

Thanks a lot Jens. I’ll download it now and take a look.

All the Best
Dave

On 13 Jul 2017, at 15:13, Dave <dave@looktowindward.com> wrote:

Hi All,

I’m about to add some animations to my game and was wondering if any could give me some advice on the implementation given my App. This is for iOS Landscape only at present but I am intending on doing a Mac version too, so if it can be made as compatible as possible that would be good.

The App is a Board Game, there are two main views, the left had side is a Player Area and the right hand side is the Board. The View Hierarchy is something like this:

RootView
LeftAreaView
BoardView
CellView’s (81 in total - 9 x 9).
RightAreaView
BagView
ScrollView Containing the Host layer’s current Pieces
Scroll View Containing the Player has the current turn.

The way the game works is that Players pick pieces at Random from the Bag - the Actually “Picking” is done by the GameEngine and the View Controller gets sent a “Player X picked Piece Y” type message. When this occurs I want to Animate the piece Dropping from the “Bag” into the Players “Stash” (One of the Scroll Views). When a player makes a Move, the View Controller gets sent “Player X Moved Piece Y into Cell X” type message, in this case I want to animate the Piece being removed from the “Stash” and Placed on the board.

What is the best way to achieve this? Do I use CALayer?

All the Best
Dave




Dave
 

Hi Again,

I’ve taken a look at Geek Game Board and I’m finding it a but hard to know where to start. I’ve developed my game to the point where the game engine sends messages to the Game View Controller which cause a Subview to the Game Cell. I now just want to animate that process, so basically in my view controller I want the View to fly across the screen from the left player area to a position in the board view. In order to do this, do I create a new CALayer or do I use the CALayer of the View I’m moving. I’m just having problems seeing where I add the code, simplified, the it looks like this:

GameViewController
RootView
LeftView
ScrollView
PieceView This View is taken from the Scroll View and 
RightView
BoardView
CellView1 to CellView81  Added as a Subview of one of these Views.


If anyone knows of a really simple Sample App that shows how to do this I’d be really grateful if you could point me to it. 

All the Best
Dave

On 13 Jul 2017, at 18:15, Jens Alfke <jens@...> wrote:


On Jul 13, 2017, at 6:13 AM, Dave <dave@...> wrote:

What is the best way to achieve this? Do I use CALayer? 

Yup, I would recommend using CALayers for the whole UI, pretty much. Back when Core Animation first came out I wrote a framework for building board/card games:
It hasn’t been updated since 2011 so it probably needs some fixes for API changes, but I still think the basic design is pretty well thought out. The goal was that you could implement a simple game UI in <200 lines of code, and there are examples included for checkers, tic-tac-toe, Klondike solitaire, and a few others.

—Jens


 


On Jul 14, 2017, at 5:39 AM, Dave <dave@...> wrote:

I want the View to fly across the screen from the left player area to a position in the board view. In order to do this, do I create a new CALayer or do I use the CALayer of the View I’m moving. 

It’s been years since I did much with CoreAnimation, but IIRC a layer is clipped to its parent layer, so if you want this to happen you need to make the view temporarily be a direct subview of your RootView. I.e. remove it from its superview, add it to the RootView (doing some coordinate transformation so its at the same place on the screen), run the animation, and when the animation finishes do the same in reverse but ending up in the BoardView.

You may want to consider not using a view hierarchy, at least for the views that need to move around a lot.

—Jens