Drag, drop, and scale
During each turn, each player will select a card and use it to attack its adversary. In this section, we're going to implement how to drag and drop a sprite and how to scale its size.
First of all, you need to enable touch management, so in GameScene.m
, add these lines at the end of the init
method, before return self;
:
// Enabling user interaction self.userInteractionEnabled = TRUE;
We need to declare two variables to manage which card has been selected and its initial position. Add the following lines after CCLabelBMFont *_label;
:
// Declare card selected Card *_selectedCard; // Declare initial card position CGPoint _initialCardPosition;
We will use _selectedCard
to know which card is being dragged, and _initialCardPosition
will store its initial position so we can recover it if the player doesn't want to play this card.
Now implement the touchBegan
method:
-(void)touchBegan:(UITouch *)touch withEvent:(UIEvent *)event { // Check what card...