本文整理汇总了C++中Sprite::GetSize方法的典型用法代码示例。如果您正苦于以下问题:C++ Sprite::GetSize方法的具体用法?C++ Sprite::GetSize怎么用?C++ Sprite::GetSize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sprite
的用法示例。
在下文中一共展示了Sprite::GetSize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Generate
void Scene::Generate() {
vector<SceneElement*>::iterator i;
float ratio = 0.f, width = -1024.f;
vector<SceneElement*>_backgroundSeed;
// Creating Background;
for(i = _dynamic.begin(); i != _dynamic.end(); ++i)
if ( (*i)->_cat == Scene::Background ) { _backgroundSeed.push_back(*i); ratio += (*i)->_ratio; }
while( width < _width ) {
float r = (rand()%static_cast<int>(ratio*100));
r /= 100.0;
float finder = 0.0f;
for(i = _backgroundSeed.begin(); i != _backgroundSeed.end(); ++i) {
finder += (*i)->_ratio;
if ( r < finder ) {
Sprite * tmp = new Sprite( *(*i)->_image );
tmp->SetX( width );
tmp->SetY( 600 - tmp->GetSize().y );
width += tmp->GetSize().x + ( rand()%200 - 100);
_background.push_back(tmp);
break;
}
}
}
}
示例2: click
bool click(int x1, int y1, bool leftclicked)
{
if(leftclicked && x1>x-sprite.GetSize().x/2 && x1<x+sprite.GetSize().x/2
&& y1>y-sprite.GetSize().y/2 && y1<y+sprite.GetSize().y/2)return true;
return false;
}
示例3: SetCursorImage
void SetCursorImage(string FileName, Vector2f Center = Vector2f(-500, -500))
{
OwnCursor = true;
CursorSprite = LoadSprite(CursorImage, FileName);
if(Center == Vector2f(-500, -500))
CursorSprite.SetCenter(CursorSprite.GetSize().x/2, CursorSprite.GetSize().y/2);
else
CursorSprite.SetCenter(Center);
}
示例4: SimpleCollision
bool SimpleCollision(Sprite s1, Sprite s2)
{
if(s1.GetPosition().x - s1.GetCenter().x < s2.GetPosition().x + s2.GetSize().x - s2.GetCenter().x
&& s1.GetPosition().x + s1.GetSize().x - s1.GetCenter().x > s2.GetPosition().x - s2.GetCenter().x
&& s1.GetPosition().y - s1.GetCenter().y < s2.GetPosition().y + s2.GetSize().y - s2.GetCenter().y
&& s1.GetPosition().y + s1.GetSize().y - s1.GetCenter().y > s2.GetPosition().y - s2.GetCenter().y)
return true;
else
return false;
}
示例5: ownCollision
bool ownCollision(Sprite& s1, Sprite& s2, int n)
{
if(s1.GetPosition().x < s2.GetPosition().x+s2.GetSize().x
&& s1.GetPosition().x+s1.GetSize().x > s2.GetPosition().x
&& s1.GetPosition().y < s2.GetPosition().y+s2.GetSize().y
&& s1.GetPosition().y+s1.GetSize().y+n > s2.GetPosition().y)
return true;
else
return false;
}
示例6: PPCollision
bool PPCollision(Vector2f point, Sprite & s, float AlphaLimit = 20.f)
{
point -= s.GetPosition() - s.GetCenter();
if(point.x >= 0 && point.x < s.GetSize().x
&& point.y >= 0 && point.y < s.GetSize().y
&& s.GetPixel((int)point.x, (int)point.y).a > AlphaLimit)
return true;
else
return false;
}
示例7: BackgroundObject
BackgroundObject(string fileName, float distance, Vector2f position, Vector2f speed = Vector2f(0.f, 0.f))
{
bSprite = LoadSprite(bImage, fileName);
Distance = distance;
Origin = position;
MinCorner = Vector2f(-1000.f, -1000.f);
MaxCorner = Vector2f(1000.f, 1000.f);
Speed = speed;
bSprite.SetCenter(bSprite.GetSize().x/2, bSprite.GetSize().y/2);
bSprite.SetPosition(Origin + Position);
}
示例8: SetGrass
void Scene::SetGrass(Image * img) {
int nbimg = _width/img->GetWidth();
nbimg += 2;
// TODO: Clear old scene (if any?)
for(int i = 0; i < nbimg; ++i) {
Sprite * tmp = new Sprite( *img);
tmp->SetX((i-1) * tmp->GetSize().x );
tmp->SetY(600 - img->GetHeight());
_grass.push_back(tmp);
}
}
示例9: SetSky
void Scene::SetSky(Image *img) {
int nbimg = _width/img->GetWidth();
nbimg += 2;
// TODO: Clear old scene (if any?)
for(int i = 0; i < nbimg; ++i) {
Sprite * tmp = new Sprite( *img);
tmp->SetX((i-1) * tmp->GetSize().x );
tmp->SetCenter(0, tmp->GetSize().y );
tmp->SetY(600);
tmp->SetScaleY(2.0);
_sky.push_back(tmp);
}
}
示例10: PPCollisionWR
bool PPCollisionWR(Sprite Sprite1,Sprite Sprite2,float AlphaLimit = 50.f)
{
float xmin1 = Sprite1.GetPosition().x - Sprite1.GetCenter().x;
float ymin1 = Sprite1.GetPosition().y - Sprite1.GetCenter().y;
float xmin2 = Sprite2.GetPosition().x - Sprite2.GetCenter().x;
float ymin2 = Sprite2.GetPosition().y - Sprite2.GetCenter().y;
float xmax1 = xmin1 + Sprite1.GetSize().x;
float ymax1 = ymin1 + Sprite1.GetSize().y;
float xmax2 = xmin2 + Sprite2.GetSize().x;
float ymax2 = ymin2 + Sprite2.GetSize().y;
float xmin = max(xmin1, xmin2);
float ymin = max(ymin1, ymin2);
float xmax = min(xmax1, xmax2);
float ymax = min(ymax1, ymax2);
//if(xmax <= xmin || ymax <= ymin) { return false; }
for(int y = int(ymin); y < ymax; ++y)
{
for(int x = int(xmin); x < xmax; ++x)
{
float x1 = x - xmin1, y1 = y - ymin1;
float x2 = x - xmin2, y2 = y - ymin2;
Vector2f Point1 =
RotatePoint(Vector2f(x1,y1),
Sprite1.GetCenter(),
-Sprite1.GetRotation());
Vector2f Point2 =
RotatePoint(Vector2f(x2,y2),
Sprite2.GetCenter(),
-Sprite2.GetRotation());
if(Point1.x > 0 && Point1.y > 0 && Point2.x > 0 && Point2.y > 0
&& Point1.x < Sprite1.GetSize().x && Point1.y < Sprite1.GetSize().y
&& Point2.x < Sprite2.GetSize().x && Point2.y < Sprite2.GetSize().y)
{
Color color1 = Sprite1.GetPixel(int(Point1.x),int(Point1.y));
Color color2 = Sprite2.GetPixel(int(Point2.x),int(Point2.y));
if (color1.a >= AlphaLimit && color2.a >= AlphaLimit)
{
return true;
}
}
}
}
return false;
}
示例11: hoversprite
bool EngineInput::hoversprite( Sprite &s )
{
F32 x, y, w, h;
x = s.GetPosition().x;
y = s.GetPosition().y;
w = x + s.GetSize().x;
h = y + s.GetSize().y;
if( x <= mouse.x && mouse.x <= w ) {
if( y < mouse.y && mouse.y <= h ) {
return true;
}
}
return false;
}
示例12: colisionSimple
bool Colision::colisionSimple(Sprite s1, Sprite s2) {
///Obtengo el tamaño y la posicion de los sprites a comparar
Vector2f tam_s1 = s1.GetSize();
Vector2f tam_s2 = s2.GetSize();
Vector2f pos_s1 = s1.GetPosition();
Vector2f pos_s2 = s2.GetPosition();
///Comparo si la esquina superior izquierda se S1 estra dentro del area ocupada por s2
if( ((pos_s1.x >= pos_s2.x) and (pos_s1.x <= pos_s2.x + tam_s2.x))
and ((pos_s1.y >= pos_s2.y) and (pos_s1.y <= pos_s2.y + tam_s2.y))
) {
return true;
}
///Comparo si la esquina superior dercha de S1 esta dentro del area ocupada por S2
if( ((pos_s1.x + tam_s1.x >= pos_s2.x) and (pos_s1.x + tam_s1.x <= pos_s2.x + tam_s2.x))
and ((pos_s1.y >= pos_s2.y) and (pos_s1.y <= pos_s2.y + tam_s2.y))
) {
return true;
}
///Comparo si la esquina inferior derecha de S1 esta dentro del area ocupada por S2
if( ((pos_s1.x + tam_s1.x >= pos_s2.x) and (pos_s1.x + tam_s1.x <= pos_s2.x + tam_s2.x))
and ((pos_s1.y + tam_s2.y>= pos_s2.y) and (pos_s1.y + tam_s2.y <= pos_s2.y + tam_s2.y))
) {
return true;
}
///Comparo si la esquina inferior izquierda de S1 esta dentro del area ocupada por S2
if( ((pos_s1.x >= pos_s2.x) and (pos_s1.x <= pos_s2.x + tam_s2.x))
and ((pos_s1.y + tam_s2.y>= pos_s2.y) and (pos_s1.y + tam_s2.y <= pos_s2.y + tam_s2.y))
) {
return true;
}
///s2 con s1
///Comparo si la esquina superior izquierda se S1 estra dentro del area ocupada por s2
if( ((pos_s2.x >= pos_s1.x) and (pos_s2.x <= pos_s1.x + tam_s1.x))
and ((pos_s2.y >= pos_s1.y) and (pos_s2.y <= pos_s1.y + tam_s1.y))
) {
return true;
}
///Comparo si la esquina superior dercha de S1 esta dentro del area ocupada por S2
if( ((pos_s2.x + tam_s2.x >= pos_s1.x) and (pos_s2.x + tam_s2.x <= pos_s1.x + tam_s1.x))
and ((pos_s2.y >= pos_s1.y) and (pos_s2.y <= pos_s1.y + tam_s1.y))
) {
return true;
}
///Comparo si la esquina inferior derecha de S1 esta dentro del area ocupada por S2
if( ((pos_s2.x + tam_s2.x >= pos_s1.x) and (pos_s2.x + tam_s2.x <= pos_s1.x + tam_s1.x))
and ((pos_s2.y + tam_s1.y>= pos_s1.y) and (pos_s2.y + tam_s1.y <= pos_s1.y + tam_s1.y))
) {
return true;
}
///Comparo si la esquina inferior izquierda de S1 esta dentro del area ocupada por S2
if( ((pos_s2.x >= pos_s1.x) and (pos_s2.x <= pos_s1.x + tam_s1.x))
and ((pos_s2.y + tam_s1.y>= pos_s1.y) and (pos_s2.y + tam_s1.y <= pos_s1.y + tam_s1.y))
) {
return true;
}
return false;
}
示例13: SetCenterInCenter
void SetCenterInCenter(Sprite & s)
{
s.SetCenter(s.GetSize().x/2.f, s.GetSize().y/2.f);
}
示例14: Obstacle
Obstacle(string fileName, Vector2f pos)
{
oSprite = LoadSprite(oImage, fileName);
oSprite.SetCenter(oSprite.GetSize().x/2.f, oSprite.GetSize().y/2.f);
Position = pos;
}
示例15: GetSize
Vector2f GetSize()
{
return oSprite.GetSize();
}