objective c - Cocos2d Spritebuilder moving sprite and firing ammo -


i going through sprite builder tutorial , trying change things see how works , got myself stuck , in need of help. here's code problems marked //<----

  1. i trying little character move right , left on screen based on how long press button. best find through searching below not smooth holding button down , moving character around.

  2. all actions appear take place on touches ending well, not when touched (began), how can modify that?

    static const cgfloat scrollspeed = 150.f; @implementation mainscene{ ccnode *hero; ccphysicsnode *physicsnode; }  - (void)didloadfromccb { self.userinteractionenabled = true; }  - (void)update:(cctime)delta { hero.position = ccp(hero.position.x + delta * scrollspeed, hero.position.y); physicsnode.position = ccp(physicsnode.position.x - (scrollspeed *delta), physicsnode.position.y); }  - (void)jump {//make hero jump (still deciding on 400 or 600) [hero.physicsbody applyimpulse:ccp(0, 400.f)]; }  - (void)fire {   ccnode* ammo = [ccbreader load:@"ammo"]; ammo.position = ccpadd(hero.position, ccp(10, 20)); // add ammo physicsnode of scene (because has physics enabled) [physicsnode addchild:ammo];  // manually create & apply force launch knife cgpoint launchdirection = ccp(1, 0); cgpoint force = ccpmult(launchdirection, 8000); [ammo.physicsbody applyforce:force]; }  - (void)left { <---- how can make hero move based on how long button pressed? cgpoint movedirection = ccp(-1, 0); cgpoint force = ccpmult(movedirection, 8000); [hero.physicsbody applyforce:force]; }  - (void)right { <---- how can make hero move based on how long button     pressed? cgpoint movedirection = ccp(1, 0); cgpoint force = ccpmult(movedirection, 8000); [hero.physicsbody applyforce:force]; }  - (void)retry { // reload level [[ccdirector shareddirector] replacescene: [ccbreader loadasscene:@"mainscene"]]; } - (void)exit { ccscene *menuscene = [ccbreader loadasscene:@"menuscene"]; [[ccdirector shareddirector] replacescene:menuscene]; }  @end 


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -