Exemple #1
0
//------------------------------------------------------------------------------
//## 画像を表示する
TEST_F(Test_Scene_Sprite, Basic)
{
	//* [ ] can be drawn
	//* [ ] setSourceRect
    //* [ ] Sprite はデフォルトで BlendModel=Aplha
	{

        auto light1 = AmbientLight::create();
        auto texture1 = Assets::loadTexture(LN_ASSETFILE("Sprite1.png"));

        auto sprite1 = Sprite::create(3, 3, texture1);
        sprite1->setPosition(-3, 0, 0);

        auto sprite2 = Sprite::create(3, 3, texture1);
        sprite2->setPosition(0, 0, 0);
        sprite2->setSourceRect(Rect(0, 0, 16, 16));

        auto sprite3 = Sprite::create(3, 3, texture1);
        sprite3->setPosition(3, 0, 0);
        sprite3->setSourceRect(16, 16, 16, 16);


        TestEnv::updateFrame();
        ASSERT_SCREEN(LN_ASSETFILE("Result/Test_Scene_Sprite-Basic-1.png"));
        LN_TEST_CLEAN_SCENE;
	}
}
Exemple #2
0
void SpriteFrameSet::init(Texture* texture, int frameWidth, int frameHeight, const Vector2& anchorPoint)
{
	init();

	if (LN_REQUIRE(texture)) return;
	if (LN_REQUIRE(frameWidth > 0)) return;
	if (LN_REQUIRE(frameHeight > 0)) return;
	m_texture = texture;
	m_frames = makeList<Ref<SpriteFrame>>();

	int cols = m_texture->width() / frameWidth;
	int rows = m_texture->height() / frameHeight;

	for (int y = 0; y < rows; y++)
	{
		for (int x = 0; x < cols; x++)
		{
			// TODO: モノによっては大量の小オブジェクトができるので、できればまとめて alloc したりキャッシュしたい
			auto frame = newObject<SpriteFrame>();
			frame->setSourceRect(Rect(x * frameWidth, y * frameHeight, frameWidth, frameHeight));
			frame->setAnchorPoint(anchorPoint);
            m_frames->add(frame);
		}
	}
}
Exemple #3
0
//! Reads attributes of the element
void CGUIImage::deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options=0)
{
	IGUIImage::deserializeAttributes(in,options);

	setImage(in->getAttributeAsTexture("Texture", Texture));
	setUseAlphaChannel(in->getAttributeAsBool("UseAlphaChannel", UseAlphaChannel));
	setColor(in->getAttributeAsColor("Color", Color));
	setScaleImage(in->getAttributeAsBool("ScaleImage", UseAlphaChannel));
	setSourceRect(in->getAttributeAsRect("SourceRect", SourceRect));

	DrawBounds.UpperLeftCorner.X = in->getAttributeAsFloat("DrawBoundsX1", DrawBounds.UpperLeftCorner.X);
	DrawBounds.UpperLeftCorner.Y = in->getAttributeAsFloat("DrawBoundsY1", DrawBounds.UpperLeftCorner.Y);
	DrawBounds.LowerRightCorner.X = in->getAttributeAsFloat("DrawBoundsX2", DrawBounds.LowerRightCorner.X);
	DrawBounds.LowerRightCorner.Y = in->getAttributeAsFloat("DrawBoundsY2", DrawBounds.LowerRightCorner.Y);
	setDrawBounds(DrawBounds);
}