Friday, 31 May 2013

How to call a function directly/with scheduler and cancel scheduler: cocos2d

In cocos2d, the function call can be either direct call without any delay, or scheduled call with a delay.

In direct call, the syntax is as follows:

      [self functionName];                                    // to call a function without delay


In scheduled function call, the syntax is:

    [self schedule:@selector(functionName) interval:10];    // to call a function with delay = 10min.s.

Note:   If the function is called with a selector with specified time interval(say 10min, as above), then it will get called in every repeated,specified time intervals(in the above case, it will trigger in every 10 min.s). So, if you need to stop the function getting called repeatedly, you can simply use the following line inside the called function at it's beginning.



       [self unschedule:_cmd];           

       example:                  
              function (normal):

                  -(void)myFunction{
                          .............................
                          .............................
                          .............................
                    }









              scheduled call:

                  [self schedule:@selector(myFunction) interval:2];

              to stop the function from getting called per each 2 mins, 
              rewrite the function as follows:

                     -(void)myFunction{
                          [self unschedule:_cmd];           // this will unschedule the scheduler
                          .............................
                          .............................
                          .............................

                    }








How to change the z order of a sprite during execution: cocos2d

In cocos2d, the z order of any sprite can be changed programmatically during execution.

Syntax:

    CCSprite * Sprite = [CCSprite spriteWithFile:@"spriteFileName.png"];
    Sprite.position = ccp(250,150);
    [self addChild:Sprite z:1];
        ...
        ...
        ...
    [self reorderChild:Sprite z:5];        // reordering position
                                                        // z  from 1 to 5 means bottom to top 

How to reset the image of a sprite: cocos2d

Cocos2d allows the programmer to reset the image of a sprite when needed. This can be done with the help of following code:




Syntax:

    [spriteName setTexture:[[CCTextureCache sharedTextureCache]
                                           addImage:@"newImageName.png"]];

How to call a sprite by tag: cocos2d

In cocos2d, you can call a sprite by it's tag. This can be done as follows:

Syntax:

      CCSprite *tempSprite =  (CCSprite *)[self getChildByTag:tagValue];

Example:

      CCSprite *tempSprite =  (CCSprite *)[self getChildByTag:10];

How to add and position a sprite in a scene: cocos2d

You can add an image/sprite in your cocos2d scene as below:


    // Add the sprite from file
    CCSprite *spriteName = [CCSprite spriteWithFile:@"a.png"]; 

    // placing it in a particular position
    spriteName.position = ccp(100, 100);          
                           
    // giving a tag value to the sprite (optional)
    spriteName.tag = 10;                         

    // adding the sprite as a child of the layer (z indicates the z-index/order of layer)
    // z = -1: bottom layer;  higher z-index = layer on topper position                  
    [self addChild:spriteName z:1];                                               

How to create multi-line label: cocos2d

Creating multi-line labels in cocos2d is very simple as shown below:

CCLabelTTF *multiLineLabel = [CCLabelTTF labelWithString:@"It is possible to have multi-line text in a cocos2d label. Here is the code . "  
                                dimensions:CGSizeMake(300.0, 80.0) 
                                alignment:UITextAlignmentCenter 
                                lineBreakMode:UILineBreakModeTailTruncation 
                                fontName:@"Marker Felt"  fontSize:25];
    multiLineLabel.position = ccp(240, 140);
    multiLineLabel.color=ccc3(255, 0, 0);
    [self addChild:multiLineLabel z:20];

How to create a label and position it properly: cocos2d

Adding and positioning a label (CCLabel ) in cocos2d is very simple. You can do it with only a few lines of code, as below:
    // create and initialize a Label
    CCLabelTTF *labelName = [CCLabelTTF labelWithString:@"Hello World" 
                                               fontName:@"Marker Felt" 
                                               fontSize:64];

    // ask director the the window size
    CGSize size = [[CCDirector sharedDirector] winSize];

    // position the label on the center of the screen
    labelName.position =  ccp( size.width /2 , size.height/2 ); 
    // To add Label Color
    labelName.color = ccc3(255, 0, 0);

    // add the label as a child to this Layer
    [self addChild: labelName];

How to print a line in console: Xcode

To print a line in console, you can use the following syntax:

Syntax:

          NSLog(@"Show this line in console...");

How to comment code: Xcode

Comment lines are used for separating some words or sentences from the executing code. In Xcode and cocos2d objective C platforms, you can comment lines as below:
  •     Insert " // " infront of any line for single line comments 
  •     Use "/* ....... */" for multi-line comments    
Example:
       
       1)   // This line is commented and
                 this second line is not commented.

      2)   /*
                By using this method, both the first line and
                the second line are commented
            */

Thursday, 30 May 2013

How to create a password field: HTML

Creating a password field in a HTML page is as simple as below:

Syntax:

    <input type’”password” name=”password”>

How to create a text field: HTML

Creating a text field in a HTML page is very simple as shown below:

Syntax:

    <input type=”text” name=”myName” />

Definition list: HTML

To create a definition list in HTML, you can use the following syntax.

Syntax:

 <dl>
    <dt> Bike </dt>
        <dd> Two wheeler </dd>
    <dt> Car </dt>
        <dd> Four wheeler </dd> 
 </dl>
 
Output:
Bike
   Two wheeler
Car
    Four wheeler

Create ordered list: HTML

The syntax to create an ordered list in an HTML page is given below:

Syntax:

<ol>
    <li>Bike</li>
    <li>Bus</li>
    <li>Car</li>
</ol>
 
Output: 
  1. Bike
  2. Bus
  3. Car

Unordered list: HTML

The syntax to create an unordered list in an HTML page is given below:

Syntax:

<ul>
    <li>Bike</li>
    <li>Bus</li>
    <li>Car</li>
</ul>
 
Output:
  • Bike
  • Bus
  • Car

Table cells that span more than one row/column: HTML

Example:

1: Column span


<table border="1">
  <tr>
    <th>Name</th>
    <th colspan="2">Contact No:</th>
  </tr>
  <tr>
    <td>Alen</td>
    <td>111 222 3333</td>
    <td>111 222 4444</td>
  </tr>
</table>
 
Output (Column span):

Name Contact No:
Alen 111 222 3333 111 222 4444

2: Row span


<table border="1">
  <tr>
    <th rowspan="2">Cell 1.1+Cell 2.1</th>
    <td>Cell 1.2</td>
    <td>Cell 1.3</td>
  </tr>
  <tr>
    <td>Cell 2.2</td>
    <td>Cell 2.3</td>
  </tr>
</table>
 
Output (Row span):

Cell 1.1+Cell 2.1 Cell 1.2 Cell 1.3
Cell 2.2 Cell 2.3

How to create a table: HTML

The syntax for a simple HTML table is given below:

<table border="1">
  <tr>
     <td>Data 1.1</td>
     <td>Data 1.2</td>
     <td>Data 1.3</td>
  </tr>
  <tr>
     <td>Data 2.1</td>
     <td>Data 2.2</td>
     <td>Data 2.3</td>
  </tr>
</table>
 
Output
 


Data 1.1 Data 1.2 Data 1.3
Data 2.1 Data 2.2 Data 2.3

How to mark deleted and inserted text: HTML

We can mark/show a text as deleted with a strike across it, and newly inserted text with a selection. It can be done in HTML with the help of following tags.

Sample:

      <p>My favorite color is <del>blue</del> <ins>red.</ins>


Output:

     My favorite color is blue red.

How to create an address with e-mail contact information in a text: HTML

You can create an address info with inserted e-mail address to a word or a sentence in HTML using the following ‘address’ tag.

Syntax:

  <address>
    Author: developerDK<br/>
    developerdk.wordpress.com<br/>
    <a href="mailto:devblogdk@gmail.com">Email author</a>
  </address>

How to display a preformatted text: HTML

Preformatted text tag is used to control the line breaks and spaces in a HTML paragraph.

Syntax:

      <pre> …………………… </pre>

eg:

  <pre>
 This is
 preformatted text.
 The    spaces and line breaks 
 you are using will be preserved 
 here. 
 </pre> 

How to insert line breaks: HTML

Inserting line breaks(go to next line) is very simlpe in an HTML page. The syntax is shown below:

Syntax:  
<br/>

How to insert horizontal lines in an HTML page

Inserting horizontal lines is very simple in HTML. It can be done with a simple tag as below:

Syntax:
    <hr/>

How to comment in a HTML page

The comment line syntax of a HTML page is as follows:

      <!– ………………………………….. –>

eg: : <! This comment will not be displayed in the screen –>

Image tag in HTML

Syntax:

<img src=”http://www.google.co.in/images/srpr/logo1w.png; width=”300″ height=”100″>


Output:


Wednesday, 29 May 2013

How to add links in an HTML page

Syntax:

   <a href=”http://www.google.co.in/”>This indicates a link</a>
Output:

This indicates a link

HTML Text formattings

Heading formatting:
  1. <h1> Largest sized heading <h1>
  2. <h2> Smaller than h1 <h2>
  3. <h3> Smaller than h2 <h3>
  4. <h4> Smaller than h3 <h4>
  5. <h5> Smaller than h4 <h5>
  6. <h6> Smaller than h5, and the smallest heading <h6>
Paragraph formatting:
  1.  <b>         Used for bold text              </b>
  2.  <strong> Used for strong text          </strong>
  3. <big>       Used for big text                </big>
  4. <em>       Used for emphasized text  </em>
  5. <i>           Used for italic text               </i>
  6. <small>    Used for small text               </small>
  7. This is used for <sub>subscript</sub> and this is for <sup>superscript</sup>