Time for action – adding a text field to the dialog
To draw text on the screen, we need to follow these steps:
As shown in the following line of code, add a property called
content
, which is a pointer toSPTextField
, inside theDialog.h
file:@property SPTextField *content;
In the
Dialog
initializer, create the following content instance and position it between the title box and the buttons:_content = [SPTextField textFieldWithWidth:background.width - 48.0f height:background.height - 150.0f text:@"Dialog default text"]; _content.x = 24.0f; _content.y = 50.0f;
Add the
content
property to the display tree, as shown in the following code:[self addChild:background]; [self addChild:buttonYes]; [self addChild:buttonNo]; [self addChild:_content];
Switch to the
Battlefield.m
file.Add a custom message for the abort dialog, as shown in the following code:
_dialogAbort = [[Dialog alloc] init]; _dialogAbort.content.text = @"Would you like to abort the current fight?"; _dialogAbort.x = (Sparrow.stage.width...