August 12, 2010

using interface in opengles(part2: functions)

In this parti’ll describe how you can run your interface on base of  game objects move.

Every code for running your game main windows,should be added in EAGLVIew class.

in opengles is better that you add more windows to games for performing menus and

games and etc but in this project it isn’t necessary .In project that we build before you

know that  ES1Rendere and ES2Renderer class have code for render engine in

opengles1 and opengles2 .All new Iphone device support opengles2.

Now we want control speed of colored box (see in previous project).we  add two lable

and  button to windows like this image

setspeedwin

Now we define two function increasespeed and decreasespeed and a lable with name label in EAGLView class.in EAGLView.h inside interface we add UILabel *label ;

then add

- (IBAction)increasespeed:(id)sender;
- (IBAction)decreasespeed:(id)sender;

after  interface definition Then linked two button + and – to them..Now we add some code in function .for example for decreasespeed function we add this code(is same for increasespeed )

   - (IBAction)decreasespeed:(id)sender {

label.text=@"increase";
    speed+=0.15f;
     [renderer setspeed:(speed)];
     [renderer render];// is necessary for seeing change

}

setspeed is function that should defined in ES1Renderer and ES2Renderer and

ESRenderer.in ES1Renderer and ES2Renderer after interface defination add

-(void)setspeed:(int)Speed; . do it for ESRenderer after @protocol defination.

Now in ES2Renderer.m and ES1Renderer.m add following code

-(void)setspeed:(int)Speed
{
    speed=Speed;
}

it is all you need. now see your app!

 

setspeedapp

Read more »