void example_init() { animals.loadXML("animals.xml"); spSprite dog = new Sprite; dog->setResAnim(animals.getResAnim("dog")); dog->setPosition(200, 300); dog->attachTo(getStage()); spSprite cat = new Sprite; cat->setResAnim(animals.getResAnim("cat")); cat->setPosition(600, 300); cat->attachTo(getStage()); }
void runSprite() { spSprite sprite = new Sprite(); addChild(sprite); int duration = 500;//500 ms int loops = -1;//infinity loops //animation has 7 columns, check 'res.xml' ResAnim *animation = gameResources.getResAnim("anim"); //add animation tween to sprite //TweenAnim would change animation frames sprite->addTween(TweenAnim(animation), duration, loops); Vector2 destPos = getStage()->getSize() - sprite->getSize(); Vector2 srcPos = Vector2(0, destPos.y); //set sprite initial position sprite->setPosition(srcPos); //add another tween: TweenQueue //TweenQueue is a collection of tweens spTweenQueue tweenQueue = new TweenQueue(); tweenQueue->setDelay(1500); //first, move sprite to dest position tweenQueue->add(Sprite::TweenPosition(destPos), 1500, 1); //then fade it out smoothly tweenQueue->add(Sprite::TweenAlpha(0), 500, 1); sprite->addTween(tweenQueue); //and remove sprite from tree when tweenQueue is empty //if you don't hold any references to sprite it would be deleted automatically tweenQueue->setDetachActor(true); }
MainActor() { //create simple Sprite spSprite button = new Sprite(); //setup it: //set button.png image. Resource 'button' defined in 'res.xml' button->setResAnim(gameResources.getResAnim("button")); //centered button at screen Vector2 pos = getStage()->getSize() / 2 - button->getSize() / 2; button->setPosition(pos); //handle click to button EventCallback cb = CLOSURE(this, &MainActor::buttonClicked); button->addEventListener(TouchEvent::CLICK, cb); #ifdef CLOSURE_FUNCTION //if your compiler supports lambda button->addEventListener(TouchEvent::CLICK, [](Event * e)->void { log::messageln("button clicked"); }); #endif //attach button as child to current actor addChild(button); _button = button; //second part //create TextField Actor spTextField text = new TextField(); //attach it as child to button text->addTo(button); //centered in button text->setPosition(button->getSize() / 2); //initialize text style TextStyle style; style.font = gameResources.getResFont("main")->getFont(); style.color = Color::White; style.vAlign = TextStyle::VALIGN_MIDDLE; style.hAlign = TextStyle::HALIGN_CENTER; text->setStyle(style); text->setText("Click\nMe!"); _text = text; }
Rocket::Rocket(Resources &resources) : fuel(100), accelerationEffeciency(1), fuelUsage(0.1) { spSprite sprite = new Sprite(); sprite->setResAnim(resources.getResAnim("rocket")); sprite->setAnchor(0.5, 0.5); anchorAcceleration = new Anchor(resources); anchorAcceleration->setColor(Color::YellowGreen); anchorVelocity = new Anchor(resources); anchorVelocity->setColor(Color::IndianRed); addChild(anchorAcceleration); addChild(anchorVelocity); addChild(sprite); }
void example_init() { file::setExtendedFolder("ext"); //load xml file with resources definition resources.loadXML("xmls/res.xml"); resourcesUI.loadXML("xmls/res_ui.xml"); resourcesUI.loadXML("xmls/fonts.xml"); spSprite sp = initActor(new Sprite, arg_resAnim = resources.getResAnim("logo2"), arg_attachTo = getRoot(), arg_priority = 10, arg_alpha = 128 ); sp->setX(getRoot()->getWidth() - sp->getWidth()); sp->setY(getRoot()->getHeight() - sp->getHeight()); _tests = new TestActor; RootActor::instance->addChild(_tests); }
void example_init() { //load xml file with resources definition gameResources.loadXML("res.xml"); Resources::registerResourceType(ResKeyframeAnimation::create, "keyframe_anim"); animResources.loadXML("godscores_res.xml"); // temporary solution // here we are connecting string resources names to real ResAnims int res_count = animResources.getCount(); for (int ind = 0; ind < res_count; ++ind) { Resource * res = animResources.get(ind); ResKeyframeAnimation * res_ka = dynamic_cast<ResKeyframeAnimation *>(res); if (res_ka) res_ka->linkWithResAnims(&animResources); } spAnimatedActor anim = new AnimatedActor(); anim->setName("anim"); anim->setPosition(250, 80); anim->setResAnim(animResources.getT<ResKeyframeAnimation>("godscores")); anim->play(); RootActor::instance->addChild(anim); //create Play/Stop button spButton button = new Button(); button->setName("btn"); button->setResAnim(gameResources.getResAnim("button")); button->setPosition(50, VirtualHeight - 10); button->setAnchor(Vector2(0.0, 1.0)); button->setInputChildrenEnabled(false); EventCallback cb = CLOSURE(&a, &ab::clicked); button->addEventListener(TouchEvent::CLICK, cb); RootActor::instance->addChild(button); //create Actor with Text and it to button as child spTextActor caption = new TextActor(); caption->setName("caption"); TextStyle style; style.font = gameResources.getResFont("main")->getFont(); style.color = Color(255, 255, 139, 255); style.vAlign = TextStyle::VALIGN_MIDDLE; style.hAlign = TextStyle::HALIGN_CENTER; caption->setStyle(style); caption->setSize(button->getSize()); caption->setText(L"Pause"); button->setScale(0.8f); button->addChild(caption); // create frame counter spTextActor frame_text = new TextActor(); frame_text->setName("frame"); TextStyle style2; style2.font = gameResources.getResFont("main")->getFont(); style2.color = Color(255, 255, 139, 255); style2.vAlign = TextStyle::VALIGN_TOP; frame_text->setStyle(style2); frame_text->setPosition(10, 10); frame_text->setScale(0.6f); frame_text->setSize(200, 30); RootActor::instance->addChild(frame_text); }