Monday, July 23, 2012

How to Use Function or Method in Xcode for noob

So yeah, I spend a well 20 minute just to learn how to use function or method with parameter

step1: build your function
 -(void)playerdonate:(int) x: (int) y
{
}

step2: use your function
[self playerdonate:50 :100];


So there you go, step 1 you build your function with two parameter x and y, void mean return nothing
then on step 2, you use your function with input 50 and 100 as x and y 



Saturday, July 21, 2012

itemFromNormalImage Depreciated

Well, Tons of warning on my Xcode with itemFromNormalImage Depreciated


So here is a quick fix, i open the cocos2d CCMenuItem.h and discover that they already change the method name to "ItemWithNormalImage"

so you just change all your "ItemFromNormalImage" with "ItemWithNormalImage"

Friday, July 20, 2012

Today Progress, the other guy will give money to the main character when he start to sing

So today progress will be that the other guy will run in front of the main character and give money to the main character when he start to sing

problem encounter is if i run my game for more than few minute my computer start to heat up and fans is becoming extremely noisy, i guess i am not doing the right thing, will have to recheck my code


Thursday, July 19, 2012

Today Progress

Well, today i add a few button on a screen to let the player control the character, the player can press left to control the character go left, press right to control the character go right, then press button 1 to make the character sing, press button 2 to let the character dance,


Wednesday, July 18, 2012

How to make screen recording video on MAC for noob

If you are wondering how I make my screen recording video on Mac, here is the step by step

1. First press F4 on your mac to view all application
2. Open the Quick Time Player,
3. Right click Quick Time Player and choose new screen recording
4. Press the record button and it will screen recording everything
5. Press stop recording to stop
6. Right click on your video to upload to youtube


a video of my first iPhone games part 1

here is a video of my first iPhone games part 1

where I have a menu to click around and it will change scene, a background that will move and also a character that will move



then i add in a new character to let it run so you can see now i have 2 character running, but nothing much yet



So today I draw a background using gimp

The background is 1000 x 320 , because I plan to scroll the background while the character move around, do note that to draw using gimp is not simple

1. to draw a line using gimp, you have to press Shift
2. to draw a rectangle using gimp, you need to select the rectangle select tool, then draw a rectangle, edit -> Stroke selection


It took me around a full 20 minute to draw this background, holy cow, yeah, thats how long it take to draw such an ugly background

Tuesday, July 17, 2012

What Have I done Today? Just a Menu, Seriously

What Have I done Today? Just a Menu, Seriously it took almost 2 hour just to finish a menu

of coz most of the time is R&D how to create a menu and switch from scene 1 to scene 2

well ok ladies and gentlemen let me present to you my GAME MENU, BOO YA


Cocos2d Changing Scene for Noob

Ok, So today I learned about how to change scene from one layer to another

so let say you are in scene1, how do you change to scene 2?

First Step: Creating Scene 2
1. Right click your project, add new file
2. select Cocos2d file, the "CCNODES class"
3. subclass of "CCLAYER"
4. give a name, let say "MainMenuLayer"
5. double click your MainMenuLayer.h and add

+(CCScene *) scene;

6.double click your MainMenuLayer.m and add

-(id) init
{
    
    if( (self=[super init] )) {
        
        CCLabelTTF *title = [CCLabelTTF labelWithString:@"Main Menu" fontName:@"Courier" fontSize:64];
        title.positionccp(240, 240);
        [self addChild: title];
        
    }
    return self;
}

- (void) dealloc
{
    
    [super dealloc];
}

// Helper class method that creates a Scene with the HelloWorldLayer as the only child.
+(CCScene *) scene
{
// 'scene' is an autorelease object.
CCScene *scene = [CCScene node];
// 'layer' is an autorelease object.
MainMenuLayer *layer = [MainMenuLayer node];
// add layer as a child to scene
[scene addChild: layer];
// return the scene
return scene;
}

Explanation- Well, you need to first init your scenes with some label "MAIN MENU", you will also need to dealloc your scene if not been used, also finally is the scene function that can be called by the CCDIRECTOR

now you have successfully created a scene 2 you can proceed to next step



Second Step: Calling Scene 2 from Scene 1
1. Open your scene1.m, paste the header of your scene2

#import "MainMenuLayer.h"

2. Under any function that you want to switch scene to scene 2, paste this code

[[CCDirector sharedDirector] replaceScene:[MainMenuLayer scene]];

Done, thats it
Let say you put the code under ccTouchEnded
Then the moment you tab your app it will go the scene2, and you can do the same to go back to scene1


Additional info:(just in case you have not configured ccTouchEnded, this is how you do it)
1. on your scene.m , paste this on top
#import "CCTouchDispatcher.h"
2. on your scene.m under init function
self.isTouchEnabled = YES;
3. Paste this 3 function on your scene.m
-(void) registerWithTouchDispatcher
{
[[CCTouchDispatcher sharedDispatcher] addTargetedDelegate:self priority:0 swallowsTouches:YES];
}

- (BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event {
    return YES;
}

- (void)ccTouchEnded:(UITouch *)touch withEvent:(UIEvent *)event {
CGPoint location = [self convertTouchToNodeSpace: touch];
    
    
    
}


That it, now you can paste any code under ccTouchEnded and once you touch your app it will react, Example you put this under the ccTouchEnded

[[CCDirector sharedDirectorreplaceScene:[YOUSCENE scene]];










Saturday, July 14, 2012

Game Idea.....what should I build?

Well, I am not sure what should i do , probably I create a beggar game? where you control a beggar to beg money from people, and try to beg as much money as possible within let say 1 minutes?

will that be fun? I really dun know, but I should start by thinking what is the logic for the game from start to finish

First, we need a background, probably somewhere in a city, you never see a beggar in the jungle right? then probably we need a lot of ppl walking around behind the background, that is super tough

so the thing need is
1. background (easy just simply draw any junk will do)
2. walking people on the background(so we need to start doing the animation for the people walking in the background

okokokokokokokk, first study how to animate the people to walk in the background

Cocos2d is easy and fun

okay, so i was trying to start a game from scratch with cocos2d, it is awesome

so the first step is to draw an image on gimp, just a quick draw

then i export the drawing as beg1.png then i drag the drawing into my Xcode project

then after that, i put this line of code in my helloworld.m

under the import


CCSprite *begger1;

under the init

begger1 = [CCSprite spriteWithFile: @"beg1.png"];
        begger1.position = ccp( 50, 100 );
        [self addChild:begger1];



and TADAA!!!!!!!!!, my image appear inside the iPhone, how cool is that, so freaking awesome




Okay, now the next step surely is to control my character to walk around right? So if i press on the right hand side i want to see my character walk to the right hand side and when i press on the left hand side i want to see my character walk to the left hand side

Under the init, i schedule myTimer function to run


  [self schedule:@selector(myTimer:)];

My Timer function to move the character from left to right 

begger1.position = ccp( begger1.position.x + 100*dt, begger1.position.y );
        if (begger1.position.x > 480+32) {
            begger1.position = ccp( -32, begger1.position.y );
        }

Then Finally I need to click somewhere on the screen and I want my picture to go to the area i click, so 

on top of the import
#import "CCTouchDispatcher.h"

on the Init 
 self.isTouchEnabled = YES;

3 New function
-(void) registerWithTouchDispatcher
{
[[CCTouchDispatcher sharedDispatcher] addTargetedDelegate:self priority:0 swallowsTouches:YES];
}

- (BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event {
    return YES;
}

- (void)ccTouchEnded:(UITouch *)touch withEvent:(UIEvent *)event {
CGPoint location = [self convertTouchToNodeSpace: touch];
    
    clickornot=2;
    
[begger1 stopAllActions];
[begger1 runAction: [CCMoveTo actionWithDuration:1 position:location]];    
}

Now when i click on any spot, my picture will fly to that area, freaking cool

Now what is the next step what is the next step



Mac Don't have Ms Paint? well, guess i go and download GIMP

I am surprised mac did not come with its own paint program

so I guess I go and download GIMP instead

I have used GIMP before, you can do a lot of fancy stuff with it, such as making transparent, make it blur, make it sharp, make it show diff texture and stuff

and the best thing is , it is free,

so go ahead and install it

Saturday, July 7, 2012

it is sunday I have no work today, But I am lazy

Yeah, i know i should spend all the free time on this but when it is saturday and sunday, i feel very lazy and just wanna relax, watch tv, watch youtube, play games, going out with friends , do some sport and stuff

Well, i guess at least i will do some quick tutorial for today, since I am not going to do anything big anytime soon so I will just follow a simple tutorial today

http://www.raywenderlich.com/1797/how-to-create-a-simple-iphone-app-tutorial-part-1

will be following this guide, hopefully can at least finish one

when i first create a new empty Master-detail project, i noticed something strange

in my noob eye, i first see the AppDelegate.h and AppDelegate.m, in both of this two we see nothing and no code referencing to the MasterviewController and also the DetailViewController

however, there is a strange thing called the MainStoryBoard.storyboard, if you click that, it show you 3 screen
1. navigation controller scene
2. master view controller - master scene
3. Detail view controller - detail scene

there is also 4 strange file under the "supporting files"
1. scarybug-info.plist
2. infoplist.strings
3.main.m
4. scarybug-prefix.pch


i am just guessing the main.m is the master of all main

as with java there always is a super main stuff such as

public static void main( String arg{})

this one start with


int main(int argc, char *argv[])
{
    @autoreleasepool {
        return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
    }
}

Weird stuff

following the tutorial asking me to create a new file under the class of NSObject, in my noob eye, what the hell is NSObject? weird stuff

anyway, back to the tutorial, it ask me to modify the master view via the storyboard

it look like this


as you can see, everything can be clicked 

then in the masterviewcontroller.m we must do some major changes on the method

- (UITableViewCell *)tableView:(UITableView *)tableView
         cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView
                             dequeueReusableCellWithIdentifier:@"MyBasicCell"];
    ScaryBugDoc *bug = [self.bugs objectAtIndex:indexPath.row];
    cell.textLabel.text = bug.data.title;
    cell.imageView.image = bug.thumbImage;
    return cell;
}

Wow, how a noob supposed to know all of this? it is so freaky

this kinda code can produce something like this
Man, this is awesome and scary at the same time

because i cannot understand anything

anyway, will get back to figure out this soon



Wednesday, July 4, 2012

What I learned Today? So complicated view

Well, at first i thought the view is you code from scratch

but after playing a while i can see that it is not, in fact, a lot of time you can drag the stuff here and there without writing any code and it display the stuff you drag

this is a shocking to me because when you first start a new project you are given choice to choose so many kind of app , some app include a view and some app did not, so if you want to build an app with custom view you have far more to learn

actually i only have some kind of idea but i am now still very confused, hopefully i can sort it out as soon as possible

Monday, July 2, 2012

How to understand Xcode from beginning for View Base Application for newbie?

Since I am a noob, after spending many hours looking at the code, finally i have some simple idea how it all started

when you first create a project, you will notice there are 4 file

AppDelegate.h
AppDelegate.m
ViewController.h
ViewController.m

let me explain using noob way, the whole process start from AppDelegate.m


- (void) applicationDidFinishLaunching:(UIApplication*)application
{

This method mean: WHEN YOUR APP FINISH LAUNCHING, WHAT SHOULD YOU DO NEXT

normally we will put your viewController here to tell the app to launch it with your view

// make the OpenGLView a child of the view controller
[viewController setView:glView];
// make the View Controller a child of the main window
[window addSubview: viewController.view];

Then you will be asking, what the hell is the "viewController" and "window"?

well actually both is an object that you declared on the AppDelegate.h

UIWindow *window;
RootViewController *viewController;

Then you will ask what is the UIWindow???

-The window is the root view in the view hierarchy

-It is the window to show to view

Then what is the ViewController???

-It is the area where you control everything, all the timer and action and graphics and stuff

I guess I can only help so much since I am a noob myself, but keep learning, one day you will become god of programming