Change scene after few seconds in Cocos2d-x - cocos2d-x

I'm a newbie. At this time, I want to change scene after a few seconds (about 3-5 seconds). But I don't know how to do. I know schedule but I don't want it loops. I mean it just works only once.
Thanks!

For example, running a main menu scene after a 2.0s delay from the splash screen.
// In the init()
this->schedule(schedule_selector(CSplashLayer::RunMainMenu), 2.0f);
// function in the splash layer class
void CSplashLayer::RunMainMenu(float dt) {
// tell CCDirector to run main menu
}

You can do like this
CCScene *pScene = GameLayer::scene();
CCTransitionPageTurn *crosssfade = CCTransitionPageTurn::create(3,pScene, true);
CCDirector::sharedDirector()->replaceScene(crosssfade);
You can use any Transition effect to change the scene with any time to take this transition to complete

You can use this this->scheduleOnce(<#SEL_SCHEDULE selector#>, <#float delay#>). This way you can acheive what you want.

Related

Flash actionscript 3.0 help (Buttons)

I'm a flash beginner, and I would like to create a button that will play a few frames following the frame it's on (a fade out), and then travel to a different part of the timeline. Is there an easy way to accomplish this? Or would it be easier to program a fade with actionscript instead of with an alpha effect?
Thanks in advance to anyone who can help.
It sounds like you have a frame with a few buttons on it and you want to have each button click through to playing a different frame but for all of those buttons to first perform some kind of fade out animation.
You can achieve this by storing a reference to the frame you want to go to after the fade out is complete. Something like:
var destinationFrame:int = 0;
And then when you click a button:
button1.addEventListener(MouseEvent.CLICK, clickButton);
function clickButton(event:MouseEvent):void {
destinationFrame = 40;
gotoAndPlay(<frame for fade out transition>);
}
Finally, at the end of the fade out transition:
gotoAndPlay(destinationFrame);
Simply allocate the relevant destinationFrame based on the button you click.

Cocos2d-x v3 Change Sprite texture with animation slide in/out

I have a Sprite init with file name "blue.png", this is just create a simple rect with blue color.
mySpriteOne = Sprite::create("blue.png");
mySpriteOne->setPosition(Vec2(0,0));
mySpriteOne->setAnchorPoint(Vec2(0,0));
this->addChild(mySpriteOne,-1);
I will change Sprite image with this code
mySpriteOne->setTexture("red.png")
Now i want when change image it also has a transition slide to right or slide to left.
I just learning cocos3d for a few days, so this problem seems too hard for me.
Thank for any answers!
The best way to do what you want to do would be to run a moveTo or moveBy action, then to do a callback to change your texture, and run a moveTo action back to your original Position.
float slideTime = 2.0f; // Time taken for slideIn/Out animation
auto originalPosition = mySpriteOne->getPosition();
auto slideOutChangeSequence = Sequence::create(
MoveTo::create(slideTime, vec2(-100, 100)),
callfunc_selector(MainScene::swapTextureCallback),
MoveTo::create(slideTime, originalPosition,
NULL);
mySpriteOne->runAction(slideOutChangeSequence);
It's bit late, but you have no answer yet, I hope this helps.

How to let an object appear in actionscript

I have an animation that may stop at 2 points depending on what the user fills in, if the animation stops at one of the two frames an objects has to apear and have to disappear if the user continues with playing the animation again. Can someone tell me how I can let object appear if the animation stops at a certain frame?
Do I need something like this? I have very little experience so please help!
star_mc._alpha = 0; star_mc.onEnterFrame = function(){ if(this._alpha < 100){ this._alpha = this._alpha + 5; }}
The code looks ok.... try it... just put it in the right place!
It's hard to tell where because I don't know how your animation built!!

How to make animation from many images(Actionscript)

How much images I need to make a good animated person or someone like stickman?
I have created a class Person for example and added an event listener onEnterFrame there, so every stickman have its own animation
private function onEnterFrame(e:Event):void{
addChild(image[i])
i++;
//thus every times increasing the i++, and add a new image
}
for example if I have a speed of 24 fps, the images are changing to fast and the animation isn't good enough, can you give me an advice on how to do that right?
ps: how to add and remove the child to delete the unnecesary previous image? in the onEnterFrame event?
Use graphics of the container Sprite/MovieClip. Ref: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/Graphics.html
Assuming image[i] is Bitmap
graphics.clear();
var bitmapData:BitmapData = image[i].bitmapData;
graphics.beginBitmapFill(bitmapData, new Matrix());
graphics.endFill();

AS3 Tween class and pan effects

I'm trying to make a "pan" effect (I'm not sure if this is pan) in flash (as3) where you have an image bigger than the mask where it is displayed (just horizontally). It´s a very simple effect, but I'm having trouble with the tweens.
First, I tried with the tween class. But it ended up a mess with the speed of the tween (the parameter where you set the frames or seconds of the tween). The "begin" parameter is easy, is the x value of the object, no matters where is it. The "end" parameter is easy too, is 0 or the end of the image, depending if you are on the left or right button (the tween begins when you are over those buttons and end with a stopTween when you are out of them or when the tween is over). The problem I'm facing it's the "duration" parameter: I want the same speed in all the tweens, no matters where it begins. Obviously, if I put a static value, if I'm in the middle of the image, the speed reduces to half.
So I'm trying to figure out how to create an algorithm to do this. I first tried something like calculating which percent of the image is the current "x" value:
If I am at 50%, make the tween in 50 frames.
If I am at 90%, make the tween in 10 frames.
If I am at 20%, make the tween in 80 frames.
But I think there should be a way to make it easier. Maybe I'm getting it wrong, and the tween class is not what I need... I'm just trying to make an displacement effect, always at the same speed (although an ease in and out until the speed is reached would be greater).
Any idea or useful link about this? I saw a lot of tutorials but with different behaviour, mostly related with mouse position.
thanks in advance!
You want:
duration = (end - begin) / pixels_per_ms
Why not use the ease property of a tween class? Take a look at http://www.greensock.com
There is a useful example widget you can experiment with on the TweenMax page.
The betterway to Achieve this effect is to measure speed/over/distance this formula will be easier and a lot less code.Doing it this way you wouldnt need any tween library's.
var MaskCenter=100;
var speed=1/10;
var distance=boxdummy.mouseX-MaskCenter;
if(mouseX<250){
box.x-=(distance*speed);
}
if (mouseX>250)
{
box.x -= speed + accel;
}
Something like that!
If you cant work it, let me know i will make up a (fla) file for you