本文整理汇总了C++中AnimationFrame::init方法的典型用法代码示例。如果您正苦于以下问题:C++ AnimationFrame::init方法的具体用法?C++ AnimationFrame::init怎么用?C++ AnimationFrame::init使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AnimationFrame
的用法示例。
在下文中一共展示了AnimationFrame::init方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: init
void TreeInspectorPreview::init(spActor item)
{
//_item = item;
STDRenderer r(&_videoCache);
RenderState rs;
rs.renderer = &r;
rs.transform = item->getTransform();
r.begin(0);
//r.setTransform(rs.transform);
item->doRender(rs);
r.end();
r.drawBatch();
setSize(30, 30);
RectF itemRect = _videoCache._bounds;
if (itemRect.isEmpty())
{
itemRect = item->getDestRect();
if (itemRect.isEmpty())
itemRect.setSize(Vector2(10, 4));
}
Vector2 ns = fitSize(Vector2(50.0f, 50.0f), itemRect.size);
float scale = ns.x / itemRect.size.x;
_cacheTransform.identity();
_cacheTransform.scale(Vector2(scale, scale));
_cacheTransform.translate(-itemRect.pos);
AnimationFrame fr = _tree->_resSystem->getResAnim("checker")->getFrame(0, 0);
//Point itemSize(30, 30);// = _getItemRect().size;
RectF srcRect = fr.getSrcRect();
const Diffuse& df = fr.getDiffuse();
srcRect.size.x = ns.x / (float)df.base->getWidth();
srcRect.size.y = ns.y / (float)df.base->getHeight();
RectF destRect = fr.getDestRect();
destRect.size = ns;
AnimationFrame cfr;
cfr.init(0, df, srcRect, destRect, ns);
setAnimFrame(cfr);
/*
spEventHandler bh = new EventHandler();
bh->setCallbackEnter(CLOSURE(this, &TreeInspectorPreview::_onEvent));
bh->setCallbackExit(CLOSURE(this, &TreeInspectorPreview::_onEvent));
bh->setCallbackPressDown(CLOSURE(this, &TreeInspectorPreview::_onEvent));
bh->setCallbackPressUp(CLOSURE(this, &TreeInspectorPreview::_onEvent));
addEventHandler(bh);
*/
}
示例2: initPlayer
void MovieSprite::initPlayer()
{
if (_initialized)
return;
_initialized = true;
_initPlayer();
Point sz = _bufferSize;
//sz = Point(nextPOT(sz.x), nextPOT(sz.y));
Point uvSize = _bufferSize / 2;
//uvSize = Point(nextPOT(uvSize.x), nextPOT(uvSize.y));
//uvSize = sz;
_mtUV.init(uvSize.x, uvSize.y, TF_A8L8);
_mtUV.fill_zero();
_textureUV = IVideoDriver::instance->createTexture();
_textureUV->init(uvSize.x, uvSize.y, _mtUV.getFormat(), false);
_mtYA.init(sz.x, sz.y, _hasAlphaChannel ? TF_A8L8 : TF_L8);
_mtYA.fill_zero();
_textureYA = IVideoDriver::instance->createTexture();
_textureYA->init(sz.x, sz.y, _mtYA.getFormat(), false);
if (_hasAlphaChannel)
setBlendMode(blend_premultiplied_alpha);
else
setBlendMode(blend_disabled);
Diffuse d;
d.base = _textureYA;
d.alpha = _textureUV;
d.premultiplied = true;
AnimationFrame frame;
RectF mr = _movieRect.cast<RectF>();
Vector2 szf = sz.cast<Vector2>();
RectF tcYA = RectF(mr.pos.div(szf), mr.size.div(szf));
frame.init(0, d, tcYA, mr, mr.size);
_yaScale = Vector2(uvSize.x / szf.x, uvSize.y / szf.y);
_yaScale = Vector2(0.5f, 0.5f);
_yaScale = Vector2(1, 1);
Vector2 s = getSize();
setAnimFrame(frame);
setSize(s);
}
示例3: TextureLine
TextureLine(spNativeTexture t)
{
setVerticalMode(Box9Sprite::TILING_FULL);
setHorizontalMode(Box9Sprite::TILING_FULL);
Sprite::setResAnim(DebugActor::resSystem->getResAnim("checker"));
AnimationFrame f;
Vector2 s = fitSize(itemSize, Vector2((float)t->getWidth(), (float)t->getHeight()));
setSize(s);
Diffuse df;
df.base = t;
f.init(0, df, RectF(0, 0, 1.0f, 1.0f), RectF(0, 0, s.x, s.y), s);
spSprite image = initActor(new Sprite,
arg_blend = blend_disabled,
arg_resAnim = f);
addChild(image);
spColorRectSprite rect = initActor(new ColorRectSprite,
arg_color = Color(Color::White, 255),
arg_attachTo = this);
rect->addTween(Sprite::TweenColor(Color(Color::White, 0)), 4000, -1, true);
char path[255];
path::normalize(t->getName().c_str(), path);
char txt[255];
safe_sprintf(txt, "%s\n<div c=\"FF0000\">%s</div>-<div c=\"0000ff\">%dx%d</div>\nid: %d",
path,
textureFormat2String(t->getFormat()),
t->getWidth(), t->getHeight(), t->getObjectID());
spTextField text = initActor(new TextField,
arg_color = Color::Black,
arg_w = (float)itemSize.x,
arg_vAlign = TextStyle::VALIGN_TOP,
arg_hAlign = TextStyle::HALIGN_LEFT,
arg_multiline = true,
arg_attachTo = rect,
arg_htmlText = txt
);
text->setBreakLongWords(true);
rect->setSize(text->getTextRect().size.cast<Vector2>() + Vector2(2, 2));
rect->setY((itemSize.y - rect->getHeight()) / 2.0f);
}
示例4: setResAnim
void Sprite::setResAnim(const ResAnim *resanim)
{
if (resanim)
{
if (resanim->getTotalFrames())
setAnimFrame(resanim);
else
{
AnimationFrame fr;
fr.init(0, Diffuse(), RectF(0,0,0,0), RectF(0,0,0,0), getSize());
setAnimFrame(fr);
}
}
else
setAnimFrame(AnimationFrame());
}
示例5: init
void ResAnim::init(spNativeTexture texture, const Point& originalSize, int columns, int rows, float scaleFactor)
{
_scaleFactor = scaleFactor;
if (!texture)
return;
int frame_width = originalSize.x / columns;
int frame_height = originalSize.y / rows;
animationFrames frames;
int frames_count = rows * columns;
frames.reserve(frames_count);
Vector2 frameSize((float)frame_width, (float)frame_height);
for (int y = 0; y < rows; ++y)
{
for (int x = 0; x < columns; ++x)
{
Rect src;
src.pos = Point(x * frame_width, y * frame_height);
src.size = Point(frame_width, frame_height);
float iw = 1.0f / texture->getWidth();
float ih = 1.0f / texture->getHeight();
RectF srcRect(src.pos.x * iw, src.pos.y * ih, src.size.x * iw, src.size.y * ih);
RectF destRect(Vector2(0, 0), frameSize * scaleFactor);
AnimationFrame frame;
Diffuse df;
df.base = texture;
frame.init(this, df, srcRect, destRect, destRect.size);
frames.push_back(frame);
}
}
init(frames, columns, scaleFactor);
}
示例6: loadAtlas
void ResAtlas::loadAtlas(CreateResourceContext &context)
{
//string path = context.walker.getCurrentFolder();
pugi::xml_node node = context.walker.getNode();
pugi::xml_node meta = context.walker.getMeta();
int w = node.attribute("width").as_int(defaultAtlasWidth);
int h = node.attribute("height").as_int(defaultAtlasHeight);
const char *format = node.attribute("format").as_string("8888");
atlas_data ad;
TextureFormat tf = string2TextureFormat(format);
pugi::xml_node meta_image = meta.child("atlas");
bool compressed = false;
while(meta_image)
{
const char *file = meta_image.attribute("file").value();
int w = meta_image.attribute("w").as_int();
int h = meta_image.attribute("h").as_int();
const char *file_format = meta_image.attribute("format").as_string(0);
TextureFormat ffmt = TF_UNDEFINED;
if (file_format)
{
ffmt = string2TextureFormat(file_format);
compressed = isCompressedFormat(ffmt);
}
std::string alpha_file = meta_image.attribute("alpha").as_string("");
if (!alpha_file.empty())
{
alpha_file = *context.prebuilt_folder + alpha_file;
}
addAtlas(tf, *context.prebuilt_folder + file, alpha_file, w, h);
meta_image = meta_image.next_sibling("atlas");
context.walker.nextMeta();
}
//
std::vector<ResAnim*> anims;
while (true)
{
XmlWalker walker = context.walker.next();
if (walker.empty())
break;
pugi::xml_node child_node = walker.getNode();
pugi::xml_node meta_frames = walker.getMeta();
const char *name = child_node.name();
if (!strcmp(name, "image"))
{
std::string id = child_node.attribute("id").value();
std::string file = child_node.attribute("file").value();
if (file.empty())
{
ResAnim *ra = new ResAnim(this);
ra->init(0, 0, 0, walker.getScaleFactor());
init_resAnim(ra, file, child_node);
ra->setParent(this);
context.resources->add(ra);
continue;
}
if (meta)
{
OX_ASSERT(meta_frames && "Did you recreate atlasses?");
}
MemoryTexture mt;
ImageData im;
int columns = 0;
int rows = 0;
int frame_width = 0;
int frame_height = 0;
float frame_scale = 1.0f;
bool loaded = false;
if (meta_frames || meta)
{
const char *frame_size = meta_frames.attribute("fs").value();
//int w = 0;
//int h = 0;
sscanf(frame_size, "%d,%d,%d,%d,%f", &columns, &rows,
//.........这里部分代码省略.........
示例7: loadAtlas
void ResStarlingAtlas::loadAtlas(CreateResourceContext& context)
{
std::string xml_path = context.walker.getPath("file");
file::buffer fb;
file::read(xml_path, fb);
pugi::xml_document doc;
doc.load_buffer_inplace(&fb.data[0], fb.data.size());
pugi::xml_node starling_xml = doc.first_child();
pugi::xml_node root = doc.root().first_child();
const std::string& img = root.attribute("imagePath").as_string();
char head[255];
char tail[255];
path::split(xml_path.c_str(), head, tail);
_imagePath = std::string(head) + img;
_texture = IVideoDriver::instance->createTexture();
pugi::xml_node meta = context.walker.getMeta();
if (!meta.empty())
{
int textureWidth = meta.attribute("tw").as_int();
int textureHeight = meta.attribute("th").as_int();
_texture->init(0, textureWidth, textureHeight, TF_R8G8B8A8);
}
else
{
unsigned char buff[64];
unsigned int size = 0;
{
file::autoClose ac(file::open(_imagePath, "rb"));
size = file::read(ac.getHandle(), buff, sizeof(buff));
}
int width = 0;
int height = 0;
ImageType type;
if (getImageInfo(buff, size, img.c_str(), type, width, height))
{
_texture->init(0, width, height, TF_R8G8B8A8);
}
else
{
spMemoryTexture mt = new MemoryTexture;
ImageData im;
file::buffer bf;
file::read(_imagePath, bf);
mt->init(bf, true, _texture->getFormat());
im = mt->lock();
_texture->init(mt->lock(), false);
}
}
float iw = 1.0f / _texture->getWidth();
float ih = 1.0f / _texture->getHeight();
ResAnim* resAnim = 0;
pugi::xml_node sub = starling_xml.first_child();
animationFrames frames;
while (sub)
{
const char* name = sub.attribute("name").value();
char id[255];
strcpy(id, name);
//int frame_index = atoi(index);
//todo optimize attributes
int x = sub.attribute("x").as_int();
int y = sub.attribute("y").as_int();
int width = sub.attribute("width").as_int();
int height = sub.attribute("height").as_int();
int frameX = sub.attribute("frameX").as_int();
int frameY = sub.attribute("frameY").as_int();
int frameWidth = sub.attribute("frameWidth").as_int(width);
int frameHeight = sub.attribute("frameHeight").as_int(height);
if (!resAnim || resAnim->getName() != id)
{
if (resAnim)
{
resAnim->init(frames, (int)frames.size());
resAnim->setParent(this);
context.resources->add(resAnim);
frames.clear();
}
//.........这里部分代码省略.........
示例8: loadAtlas
void ResStarlingAtlas::loadAtlas(CreateResourceContext &context)
{
const char *xml_name = context.node.attribute("file").value();
string xml_path = *context.folder + xml_name;
file::buffer fb;
file::read(xml_path.c_str(), fb);
pugi::xml_document doc;
doc.load_buffer_inplace(&fb.data[0], fb.data.size());
pugi::xml_node starling_xml = doc.first_child();
_imagePath = *context.folder + starling_xml.attribute("imagePath").value();
_texture = IVideoDriver::instance->createTexture();
if (context.meta)
{
int textureWidth = context.meta.attribute("tw").as_int();
int textureHeight = context.meta.attribute("th").as_int();
_texture->init(0, textureWidth, textureHeight, TF_R8G8B8A8);
}
else
{
spMemoryTexture mt = new MemoryTexture;
ImageData im;
file::buffer bf;
file::read(_imagePath.c_str(), bf);
mt->init(bf, true, _texture->getFormat());
im = mt->lock();
_texture->init(mt->lock(), false);
}
float iw = 1.0f / _texture->getWidth();
float ih = 1.0f / _texture->getHeight();
ResAnim *resAnim = 0;
pugi::xml_node sub = starling_xml.first_child();
animationFrames frames;
while (sub)
{
const char *name = sub.attribute("name").value();
int index_pos = strlen(name) - 4;
const char *index = name + index_pos;
char id[255];
strcpy(id, name);
id[index_pos] = 0;
int frame_index = atoi(index);
//todo optimize attributes
int x = sub.attribute("x").as_int();
int y = sub.attribute("y").as_int();
int width = sub.attribute("width").as_int();
int height = sub.attribute("height").as_int();
int frameX = sub.attribute("frameX").as_int();
int frameY = sub.attribute("frameY").as_int();
int frameWidth = sub.attribute("frameWidth").as_int(width);
int frameHeight = sub.attribute("frameHeight").as_int(height);
if (!resAnim || resAnim->getName() != id)
{
if (resAnim)
{
resAnim->init(frames, frames.size());
context.resources->add(resAnim);
frames.clear();
}
resAnim = new ResAnim(this);
setNode(resAnim, context.node);
resAnim->setName(id);
}
AnimationFrame frame;
RectF srcRect(x * iw, y * ih, width * iw, height * ih);
RectF destF = Rect(-frameX, -frameY, width, height).cast<RectF>();
Diffuse df;
df.base = _texture;
frame.init(resAnim, df, srcRect, destF, Vector2((float)frameWidth, (float)frameHeight));
frames.push_back(frame);
sub = sub.next_sibling();
}
if (resAnim)
{
resAnim->init(frames, frames.size());
context.resources->add(resAnim);
}
//.........这里部分代码省略.........
示例9: _run
void TransitionQuads::_run(spScene current, spScene next, bool back)
{
Point ds = core::getDisplaySize();
spActor holder = new Actor;
holder->setPosition(getStage()->global2local(Vector2(0, 0)));
//holder->setVisible(false);
holder->setSize(core::getDisplaySize());
holder->attachTo(getStage());
holder->setPriority(1000);
int numX = ds.x / 40;
int numY = ds.y / 40;
//log::messageln("tq1");
Vector2 quad(holder->getWidth() / numX, holder->getHeight() / numY);
spTween slowestTween;
for (int y = 0; y < numY; ++y)
{
for (int x = 0; x < numX; ++x)
{
spSprite sp = new ColorRectSprite;
Vector2 pos(quad.x * x, quad.y * y);
pos += quad / 2;
sp->setPosition(pos);
sp->setAnchor(Vector2(0.5f, 0.5f));
sp->setSize(quad);
sp->attachTo(holder);
sp->setScale(0);
sp->setColor(Color(0xffffffff));
Vector2 d = pos - _center;
float time = d.length() / holder->getSize().length();
/*
if (back)
time = 1.0f - time;
*/
float mp = 4.0f;
//mp = 10;
int tm = int(1 + time * 800 * mp);
spTween nt = sp->addTween(Actor::TweenScale(1.0f), int(100 * mp), 1, false, tm);
if (!slowestTween || (int)slowestTween->getDelay() < tm)
slowestTween = nt;
}
}
//log::messageln("tq2");
#if OXYGINE_RENDERER <= 2
STDRenderer r;
RenderState rs;
rs.renderer = &r;
rs.renderer->initCoordinateSystem(ds.x, ds.y, true);
spNativeTexture mask = IVideoDriver::instance->createTexture();
mask->init(ds.x, ds.y, TF_R5G5B5A1, true);
_mask = mask;
spSprite maskSprite = new Sprite;
{
AnimationFrame fr;
Diffuse df;
df.base = mask;
RectF srcRect(0, 0, (float)ds.x / mask->getWidth(), (float)ds.y / mask->getHeight());
RectF destRect(Vector2(0, 0), ds);
fr.init(0, df, srcRect, destRect, ds);
maskSprite->setAnimFrame(fr);
}
//log::messageln("tq3");
//#define BUG
//STDMaterial
spMaskedSprite bg = new MaskedSprite;
bg->setMask(maskSprite);
bg->attachTo(getStage());
bg->setPriority(100);
bg->addChild(next->getHolder());
bg->setInputEnabled(false);
_bg = bg;
timeMS tm = getTimeMS() + 3000;
holder->setCallbackDoUpdate(CLOSURE(this, &TransitionQuads::update));
//_r = r;
_holder = holder;
waitTween(slowestTween);
#endif
}