| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- #pragma once
- #include "test.h"
- extern Resources resources;
- class PerfTest: public Test
- {
- public:
- spButton button;
- int count;
- bool _tweenAnim;
- bool _tweenRot;
- bool _tweenScale;
- PerfTest()
- {
- _tweenAnim = false;
- _tweenRot = false;
- _tweenScale = false;
- count = 0;
- addButton("add", "add 500");
- addButton("animate", "animate");
- addButton("scale0.01", "scale=0.01");
- addButton("scale0.2", "scale=0.2");
- addButton("scale0.5", "scale=0.5");
- toggle dr[] = {toggle("driver=null", 0, new VideoDriverNull), toggle("driver=default", 0, 0)};
- addToggle("driver", dr, 2);
- content->setTouchEnabled(false);
- content->setTouchChildrenEnabled(false);
- }
- void toggleClicked(string id, const toggle* data)
- {
- if (id == "driver")
- content->driver = (IVideoDriver*)(data->data);
- }
- void clicked(string id)
- {
- if (id == "add")
- {
- int a = 500;
- count += a;
- for (int i = 0; i < a; ++i)
- {
- spSprite sprite = new Sprite;
- sprite->setResAnim(resources.getResAnim("anim"));
- sprite->setAnchor(Vector2(0.5f, 0.5f));
- sprite->setScale(0.05f);
- sprite->setPosition(scalar::randFloat(0, (float)getWidth()), scalar::randFloat(0, (float)getHeight()));
- content->addChild(sprite);
- }
- char str[255];
- safe_sprintf(str, "add 500 (%d)", count);
- updateText(id, str);
- }
- if (id == "scale0.01")
- {
- spActor child = content->getFirstChild();
- while (child)
- {
- child->setScale(Vector2(1, 1) * 0.01f);
- child = child->getNextSibling();
- }
- }
- if (id == "scale0.2")
- {
- spActor child = content->getFirstChild();
- while (child)
- {
- child->setScale(Vector2(1, 1) * 0.2f);
- child = child->getNextSibling();
- }
- }
- if (id == "scale0.5")
- {
- spActor child = content->getFirstChild();
- while (child)
- {
- child->setScale(Vector2(1, 1) * 0.5f);
- child = child->getNextSibling();
- }
- }
- if (id == "animate")
- {
- spActor child = content->getFirstChild();
- while (child)
- {
- spTween t = 0;
- if (!_tweenAnim)
- t = createTween(TweenAnim(resources.getResAnim("anim")), 500, -1);
- else if (!_tweenRot)
- t = createTween(Actor::TweenRotation((float)MATH_PI * 2.0f), 3000, -1);
- else if (!_tweenScale)
- t = createTween(Actor::TweenScale(Vector2(0.2f, 0.2f)), 3000, -1, true);
- if (t)
- child->addTween(t);
- child = child->getNextSibling();
- }
- if (!_tweenAnim)
- _tweenAnim = true;
- else
- {
- if (!_tweenRot)
- _tweenRot = true;
- else if (!_tweenScale)
- {
- updateText(id, "");
- _tweenScale = true;
- }
- }
- }
- }
- };
|