本文整理汇总了C++中SpriteBatch类的典型用法代码示例。如果您正苦于以下问题:C++ SpriteBatch类的具体用法?C++ SpriteBatch怎么用?C++ SpriteBatch使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SpriteBatch类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: w_SpriteBatch_setTexture
int w_SpriteBatch_setTexture(lua_State *L)
{
SpriteBatch *t = luax_checkspritebatch(L, 1);
Texture *tex = luax_checktexture(L, 2);
t->setTexture(tex);
return 0;
}
示例2: GP_ASSERT
TileSet* TileSet::create(const char* imagePath,
float tileWidth, float tileHeight,
unsigned int rowCount, unsigned int columnCount)
{
GP_ASSERT(imagePath);
GP_ASSERT(tileWidth > 0 && tileHeight > 0);
GP_ASSERT(rowCount > 0 && columnCount > 0);
SpriteBatch* batch = SpriteBatch::create(imagePath);
batch->getSampler()->setWrapMode(Texture::CLAMP, Texture::CLAMP);
batch->getSampler()->setFilterMode(Texture::Filter::NEAREST, Texture::Filter::NEAREST);
batch->getStateBlock()->setDepthWrite(false);
batch->getStateBlock()->setDepthTest(true);
TileSet* tileset = new TileSet();
tileset->_batch = batch;
tileset->_tiles = new Vector2[rowCount * columnCount];
memset(tileset->_tiles, -1, sizeof(float) * rowCount * columnCount * 2);
tileset->_tileWidth = tileWidth;
tileset->_tileHeight = tileHeight;
tileset->_rowCount = rowCount;
tileset->_columnCount = columnCount;
tileset->_width = tileWidth * columnCount;
tileset->_height = tileHeight * rowCount;
return tileset;
}
示例3: pos
unsigned int CheckBox::drawImages(Form* form, const Rectangle& clip)
{
if (!_image)
return 0;
// Left, v-center.
// TODO: Set an alignment for icons.
const Rectangle& region = _image->getRegion();
const Theme::UVs& uvs = _image->getUVs();
Vector4 color = _image->getColor();
color.w *= _opacity;
Vector2 size;
if (_imageSize.isZero())
{
size.set(region.width, region.height);
}
else
{
size.set(_imageSize);
}
Vector2 pos(_viewportBounds.x, _viewportBounds.y + _viewportBounds.height * 0.5f - size.y * 0.5f);
SpriteBatch* batch = _style->getTheme()->getSpriteBatch();
startBatch(form, batch);
batch->draw(pos.x, pos.y, size.x, size.y, uvs.u1, uvs.v1, uvs.u2, uvs.v2, color, _viewportClipBounds);
finishBatch(form, batch);
return 1;
}
示例4: w_SpriteBatch_setg
int w_SpriteBatch_setg(lua_State *L)
{
SpriteBatch *t = luax_checkspritebatch(L, 1);
int index = luaL_checkinteger(L, 2);
Geometry *g = luax_checktype<Geometry>(L, 3, "Geometry", GRAPHICS_GEOMETRY_T);
float x = (float)luaL_optnumber(L, 4, 0.0f);
float y = (float)luaL_optnumber(L, 5, 0.0f);
float angle = (float)luaL_optnumber(L, 6, 0.0f);
float sx = (float)luaL_optnumber(L, 7, 1.0f);
float sy = (float)luaL_optnumber(L, 8, sx);
float ox = (float)luaL_optnumber(L, 9, 0);
float oy = (float)luaL_optnumber(L, 10, 0);
float kx = (float)luaL_optnumber(L, 11, 0);
float ky = (float)luaL_optnumber(L, 12, 0);
try
{
t->addg(g, x, y, angle, sx, sy, ox, oy, kx, ky, index);
}
catch (love::Exception &e)
{
return luaL_error(L, "%s", e.what());
}
return 0;
}
示例5: getState
unsigned int TextBox::drawImages(Form* form, const Rectangle& clip)
{
Control::State state = getState();
if (_caretImage && (state == ACTIVE || hasFocus()))
{
// Draw the cursor at its current location.
const Rectangle& region = _caretImage->getRegion();
if (!region.isEmpty())
{
const Theme::UVs& uvs = _caretImage->getUVs();
Vector4 color = _caretImage->getColor();
color.w *= _opacity;
float caretWidth = region.width * _fontSize / region.height;
Font* font = getFont(state);
unsigned int fontSize = getFontSize(state);
Vector2 point;
font->getLocationAtIndex(getDisplayedText().c_str(), _textBounds, fontSize, &point, _caretLocation,
getTextAlignment(state), true, getTextRightToLeft(state));
SpriteBatch* batch = _style->getTheme()->getSpriteBatch();
startBatch(form, batch);
batch->draw(point.x - caretWidth * 0.5f, point.y, caretWidth, fontSize, uvs.u1, uvs.v1, uvs.u2, uvs.v2, color, _viewportClipBounds);
finishBatch(form, batch);
return 1;
}
}
return 0;
}
示例6: w_SpriteBatch_setImage
int w_SpriteBatch_setImage(lua_State *L)
{
SpriteBatch *t = luax_checkspritebatch(L, 1);
Image *image = luax_checktype<Image>(L, 2, "Image", GRAPHICS_IMAGE_T);
t->setImage(image);
return 0;
}
示例7: w_SpriteBatch_setBufferSize
int w_SpriteBatch_setBufferSize(lua_State *L)
{
SpriteBatch *t = luax_checkspritebatch(L, 1);
int size = (int) luaL_checknumber(L, 2);
luax_catchexcept(L, [&]() {t->setBufferSize(size); });
return 0;
}
示例8: drawParticles
//=====-----=======---------=========---------==========---------=========----------=============
void ParticleSet::drawParticles( SpriteBatch& sb, const TexturePtr texture, const Color& color, const int layer, const float sizeFactor, bool doFade )
{
for(int i = 0; i <= mHighestLiveIndex; ++i)
{
if(!mParticles[i].mAlive)
{
continue;
}
if (mParticles[i].mLifetime == -1.0f)
{
Color finalColor( color );
finalColor *= mParticles[i].mAlphaMultiplier;
sb.drawQuad(layer, texture, mParticles[i].mPosition + VectorTools::rotateVector(mParticles[i].mOffset, Walaber::degToRad(mParticles[i].mAngleDeg)), Walaber::degToRad(mParticles[i].mAngleDeg), mParticles[i].mSize * sizeFactor, finalColor);
}
else
{
Color finalCol = color;
if (doFade)
finalCol = _getParticleColor(&mParticles[i], color); // color * lerp(0.0f, 1.0f, mParticles[i].mLifetime / mParticles[i].mFadeLength);
sb.drawQuad(layer, texture, mParticles[i].mPosition + VectorTools::rotateVector(mParticles[i].mOffset, Walaber::degToRad(mParticles[i].mAngleDeg)), Walaber::degToRad(mParticles[i].mAngleDeg), getParticleSize(i) * sizeFactor, finalCol);
}
}
}
示例9: w_SpriteBatch_setColor
int w_SpriteBatch_setColor(lua_State *L)
{
SpriteBatch *t = luax_checkspritebatch(L, 1);
Color c;
if (lua_gettop(L) <= 1)
{
t->setColor();
return 0;
}
else if (lua_istable(L, 2))
{
for (int i = 1; i <= 4; i++)
lua_rawgeti(L, 2, i);
c.r = (unsigned char) luaL_checkint(L, -4);
c.g = (unsigned char) luaL_checkint(L, -3);
c.b = (unsigned char) luaL_checkint(L, -2);
c.a = (unsigned char) luaL_optint(L, -1, 255);
lua_pop(L, 4);
}
else
{
c.r = (unsigned char)luaL_checkint(L, 2);
c.g = (unsigned char)luaL_checkint(L, 3);
c.b = (unsigned char)luaL_checkint(L, 4);
c.a = (unsigned char)luaL_optint(L, 5, 255);
}
t->setColor(c);
return 0;
}
示例10: draw
void ParticleEmitter::draw (SpriteBatch& spriteBatch,float delta) {
accumulator += std::min(delta * 1000, 250.f);
if (accumulator < 1) {
draw(spriteBatch);
return;
}
int deltaMillis = (int)accumulator;
accumulator -= deltaMillis;
if (additive) spriteBatch.setBlendFunction(gdx_cpp::graphics::GL10::GL_SRC_ALPHA, gdx_cpp::graphics::GL10::GL_ONE);
for (unsigned int index = 0; index < active.size(); index++) {
if (active[index])
{
if (updateParticle(index, delta, deltaMillis))
{
particles[index]->draw(spriteBatch);
}
else
{
active[index] = false;
activeCount--;
}
}
}
if (additive) spriteBatch.setBlendFunction(gdx_cpp::graphics::GL10::GL_SRC_ALPHA, gdx_cpp::graphics::GL10::GL_ONE_MINUS_SRC_ALPHA);
if (delayTimer < delay) {
delayTimer += deltaMillis;
return;
}
if (firstUpdate) {
firstUpdate = false;
addParticle();
}
if (durationTimer < duration)
durationTimer += deltaMillis;
else {
if (!continuous || allowCompletionVar) return;
restart();
}
emissionDelta += deltaMillis;
float emissionTime = emission + emissionDiff * emissionValue.getScale(durationTimer / (float)duration);
if (emissionTime > 0) {
emissionTime = 1000 / emissionTime;
if (emissionDelta >= emissionTime) {
int emitCount = (int)(emissionDelta / emissionTime);
emitCount = std::min(emitCount, maxParticleCount - activeCount);
emissionDelta -= emitCount * emissionTime;
emissionDelta = std::fmod((float)emissionDelta, emissionTime);
addParticles(emitCount);
}
}
if (activeCount < minParticleCount) addParticles(minParticleCount - activeCount);
}
示例11: w_SpriteBatch_getImage
int w_SpriteBatch_getImage(lua_State *L)
{
SpriteBatch *t = luax_checkspritebatch(L, 1);
Image *image = t->getImage();
image->retain();
luax_newtype(L, "Image", GRAPHICS_IMAGE_T, (void *)image);
return 1;
}
示例12: draw
void Level::draw(SpriteBatch& spriteBatch)
{
for (auto& block : m_levelData)
{
spriteBatch.draw(glm::vec4(block.pos.x, block.pos.y, block.size.x, block.size.y), glm::vec4(0,0,1,1), m_texture.id, 0, m_color);
}
spriteBatch.draw(glm::vec4(m_finishPoint.pos.x-2.f, m_finishPoint.pos.y-2.f, m_finishPoint.size.x, m_finishPoint.size.y), glm::vec4(0,0,1,1), m_texture.id, 0, ColorRGBA8(20,20,220,255));
}
示例13: w_SpriteBatch_attachAttribute
int w_SpriteBatch_attachAttribute(lua_State *L)
{
SpriteBatch *t = luax_checkspritebatch(L, 1);
const char *name = luaL_checkstring(L, 2);
Mesh *m = luax_checktype<Mesh>(L, 3, GRAPHICS_MESH_ID);
luax_catchexcept(L, [&](){ t->attachAttribute(name, m); });
return 0;
}
示例14: clear
void MeshGame::drawSplash(void* param)
{
clear(CLEAR_COLOR_DEPTH, Vector4(0, 0, 0, 1), 1.0f, 0);
SpriteBatch* batch = SpriteBatch::create("res/logo_powered_white.png");
batch->start();
batch->draw(this->getWidth() * 0.5f, this->getHeight() * 0.5f, 0.0f, 512.0f, 512.0f, 0.0f, 1.0f, 1.0f, 0.0f, Vector4::one(), true);
batch->finish();
SAFE_DELETE(batch);
}
示例15: clear
void SpaceshipGame::drawSplash(void* coookie)
{
clear(CLEAR_COLOR_DEPTH, Vector4(0, 0, 0, 1), 1.0f, 0);
SpriteBatch* batch = SpriteBatch::create("res/splash.png");
batch->begin();
batch->draw(Rectangle(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT), Rectangle(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT), Vector4::one());
batch->end();
SAFE_DELETE(batch);
}