I want to follow the Hero with endless. I have using the following code with limit. It is limited area to follow the Hero.
Here is the coding:
CCSize size = CCDirector::sharedDirector()->getWinSize();
CCRect rect = CCRectMake(0, 0, size.width, size.height);
this->runAction(CCFollow::create(playerSprite, rect));
My game logic - Hero is moving continuously with no boundary.
How can hero follow the object with endless?
Any idea should help me a lot. Thanks in advance.
Try this..
this->runAction(CCFollow::create(playerSprite));
Related
How can one limit the CCScrolLayer/CCLayer to a rect smaller than the screen size ? means:
CCLayer *page1;
When putting many pages in scroller, need all the items in the page to "disappear" when they reached some rect ( the scroller is above a "note page" boundaries hence cant get "out" of it)
Using the CCScrollLayer class extention
scroller = [[CCScrollLayer alloc] initWithLayers:[NSArray arrayWithObjects:pagesArray[0],pagesArray[1],pagesArray[2], nil] widthOffset:240];
scroller.showPagesIndicator=0;
scroller.pagesIndicatorNormalColor=ccc4(0, 0, 0, 20);
scroller.pagesIndicatorPosition=ccp(winSize.width/2,winSize.height*0.17);
scroller.pagesIndicatorSelectedColor=ccc4(239, 58, 104, 255);
[scroller setDelegate:self];
Thank you very much .
What you need is a clipping node. Please have a look at this tutorial.
I've got a question: My games hero can jump (CCJumpTo) and move to forward and backward direction (CCMoveTo).
I faced with problem: if game recived a command from user to move the hero, but in this time hero is jumping (CCJumpTo), how can I do this command after the end of jumping. (can I use some stack of actions for one sparite in cocos2d)
I can't use immediately [self.sprite stopAllActions]; to begin CCMoveTo because the hero have to finish the jump action and if I use CCMoveTo the action CCJumpTo will not finish. Hero can't jump and start to move to forward and backward at height.
sorry for my English
For example, you can store your stack of actions in array, then run action like this
- (void) runNextAction
{
id actionFromStack = [stack objectAtIndex: 0];
[stack removeObjectAtIndex: 0];
id callback = [CCCallFunc actionWithTarget: self selector: #selector(runNextAction)];
id sequence = [CCSequence actionOne: actionFromStack two: callback];
[self runAction: sequence];
}
Is it possible? I guess it is, but I can't figure it out.
So, the code for the movie thus far:
shrigString = [[NSBundle mainBundle] pathForResource:#"shrig_h264_720p" ofType:#"mov"];
shrigURL = [NSURL fileURLWithPath:shrigString];
//shrigMovie = [QTMovie movieWithFile:#"shrig_h264_720p.mov" error:nil];
shrigMovie = [QTMovie movieWithURL:shrigURL error:nil];
shrigMovieView = [QTMovieLayer layerWithMovie:shrigMovie];
[[[[CCDirectorMac sharedDirector] openGLView] window] addChildWindow:shrigWindow ordered:NSWindowAbove];
[shrigWindow setContentView:shrigNSView];
[shrigNSView setLayer:shrigMovieView];
shrigMovieView.frame = CGRectMake(size.width /2, size.height /2, 1024, 576);
[shrigMovie autoplay];
[shrigMovie play];
NSLog(#"shrigMovie: %#", shrigMovie);
NSLog(#"shrigMovie is: %#", QTStringFromTime([shrigMovie currentTime]));
However, I can't figure out how to ad that to my scene. This is Cocos2D for Mac btw.
In the console:
shrigMovie is: 0:00:00:00.00/2500 So I guess it's loading ok, but simply not displaying?
Any ideas would be hugely appreciated.
Thanks.
I ran into the same problem and spent quite a while trying to figure out how to solve it using QTMovie in combination with cocos2D. Eventually I gave up and started looking if there was a good existing solution to this. And voilĂ , I found VideoPlayer. Very easy to use and very lightweight, you can find it on https://github.com/psineur/CCVideoPlayer. Just be sure to copy only the necessary VideoPlayer-folder from the zip-file and don't forget the CustomVideoView.nib in the Resources folder. Add those to some lib-folder within your project, then you can start playing Video-files using those two lines:
[VideoPlayer setDelegate:self];
[VideoPlayer playMovieWithFile:#"intro.mov"];
You can then add the following delegate methods to your class
- (void) moviePlaybackFinished
{
}
- (void) movieStartsPlaying
{
}
Got it working in less than 10 minutes :)
Cheers
I integrated Adwhirl into my app and activated iAd only. My app is in landscapeleft mode and I want to have all Ads in 320x50(48) mode. I managed to rotate the banner view and the iAd looks right.I did this in the following way:
AdWhirl *adView = [AdWhirlView requestAdWhirlViewWithDelegate:self];
[[[Director sharedDirector] openGLView] addSubview:adView];
CGAffineTransform transform = CGAffineTransformMakeTranslation(0, 150);
transform = CGAffineTransformTranslate(transform, 10, 10);
transform = CGAffineTransformRotate(transform, CC_DEGREES_TO_RADIANS(90));
[adView setTransform:transform];
It works fine in iOS4.2.
However,on device with iOS4.1,only left side of the banner view is clickable.I'm really confused about this behavior.Is there anyone having the same problem?
Any hint would be highly appreciated!
P.S.I tried to set frame,bounds,and center,but that does not solve the problem.
I need to move a sprite from one CGPoint to another using Cocos2d for the Iphone. The problem is that the animation should be along a bezier.
Basically I would use this :
id move = [CCMoveTo actionWithDuration:.5f position:ccp(100,200)];
[sprite runAction:move];
Now how can I do this in a non linear path ?
Try this
ccBezierConfig bezier;
bezier.controlPoint_1 = ccp(0, s.height/2);
bezier.controlPoint_2 = ccp(300, -s.height/2);
bezier.endPosition = ccp(300,100);
id bezierForward = [CCBezierBy actionWithDuration:3 bezier:bezier];
Well, actually I was once again too fast seeking for help.
Found the solution, there is a method : CCBezierTo