本文整理汇总了C++中Sprite::GetPosition方法的典型用法代码示例。如果您正苦于以下问题:C++ Sprite::GetPosition方法的具体用法?C++ Sprite::GetPosition怎么用?C++ Sprite::GetPosition使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sprite
的用法示例。
在下文中一共展示了Sprite::GetPosition方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例2: MoveSprites
void Sprites::MoveSprites(float timeStep)
{
Graphics* graphics = GetSubsystem<Graphics>();
float width = (float)graphics->GetWidth();
float height = (float)graphics->GetHeight();
// Go through all sprites
for (unsigned i = 0; i < sprites_.Size(); ++i)
{
Sprite* sprite = sprites_[i];
// Rotate
float newRot = sprite->GetRotation() + timeStep * 30.0f;
sprite->SetRotation(newRot);
// Move, wrap around rendering window edges
Vector2 newPos = sprite->GetPosition() + sprite->GetVar(VAR_VELOCITY).GetVector2() * timeStep;
if (newPos.x_ < 0.0f)
newPos.x_ += width;
if (newPos.x_ >= width)
newPos.x_ -= width;
if (newPos.y_ < 0.0f)
newPos.y_ += height;
if (newPos.y_ >= height)
newPos.y_ -= height;
sprite->SetPosition(newPos);
}
}
示例3: PPCollision
bool PPCollision(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 += 5)
{
for(int x = int(xmin); x < xmax; x += 5)
{
float x1 = x - xmin1, y1 = y - ymin1;
float x2 = x - xmin2, y2 = y - ymin2;
if(x1 > 0 && y1 > 0 && x2 > 0 && y2 > 0
&& x1 < Sprite1.GetSize().x && y1 < Sprite1.GetSize().y
&& x2 < Sprite2.GetSize().x && y2 < Sprite2.GetSize().y)
{
Color color1 = Sprite1.GetPixel(int(x1),int(y1));
Color color2 = Sprite2.GetPixel(int(x2),int(y2));
if (color1.a >= AlphaLimit && color2.a >= AlphaLimit)
{
return true;
}
}
}
}
return false;
}
示例4: 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;
}
示例5: 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;
}
示例6: 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;
}
示例7: lua_Sprite_SetPosition
int lua_Sprite_SetPosition(lua_State* state)
{
Sprite* sprite = (Sprite*)lua_touserdata(state, 1);
if (sprite == NULL)
{
return luaL_typerror(state, 1, "Sprite");
}
if(lua_isnumber(state, 2))
{
double x = (double) luaL_optnumber(state, 2, sprite->GetPosition().x);
double y = (double) luaL_optnumber(state, 3, sprite->GetPosition().y);
sprite->SetPosition(x, y);
}
else
{
Vector* vector = (Vector*)lua_touserdata(state, 2);
if (vector == NULL)
{
return luaL_typerror(state, 2, "Vector");
}
sprite->SetPosition(*vector);
}
return 0;
}
示例8: main
int main()
{
glfwInit(); // Initialisoidaan GLFW
// GLFW perusasetukset
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2); // asetetaan OpenGL-
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1); // versio 2.1
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_ANY_PROFILE); // määritellään OpenGL profiili käytettäväksi
glfwWindowHint(GLFW_RESIZABLE, GL_FALSE); // ikkunan kokoa ei voi muuttaa
// luodaan ikkuna GLFWwindow
GLFWwindow* window = glfwCreateWindow(width, height, "EPELIROOTTORI", nullptr, nullptr);
glfwMakeContextCurrent(window);
glfwSetKeyCallback(window, key_callback);
glewExperimental = GL_TRUE;
glewInit(); // Initialisoidaan GLEW
glViewport(0, 0, width, height);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
Renderer renderer = { glm::vec2(width, height) };
Renderer renderer2 = { glm::vec2(width * 2, height * 2) };
Renderer renderer3 = { glm::vec2(width * 4, height * 4) };
AnimationManager anima;
TextManager tex;
tex.LoadFont("..//data/fonts/arial.ttf");
tex.SetText("0");
tex.SetCharacterSize(30);
tex.SetPosition(glm::vec2(10, 0));
tex.SetColor(glm::vec3(0.0, 0.0, 1.0));
TextManager tex2;
tex2.LoadFont("..//data/fonts/arial.ttf");
tex2.SetText("0");
tex2.SetCharacterSize(30);
tex2.SetPosition(glm::vec2(width - tex2.GetGlobalBounds().x, 0));
tex2.SetColor(glm::vec3(0.0, 1.0, 0.0));
TextManager tex3;
tex3.LoadFont("..//data/fonts/Arctik5.ttf");
tex3.SetText("Pong");
tex3.SetCharacterSize(30);
tex3.SetPosition(glm::vec2(width / 2.5, 0));
tex3.SetColor(glm::vec3(0.0, 0.0, 0.0));
Sprite typhlosion;
typhlosion.SetAnimation("../data/animations/Typhlosion2.png", glm::vec2(234, 250), 0.2);
typhlosion.SetPosition(glm::vec2((width - typhlosion.GetBounds().x) / 2, (height - typhlosion.GetBounds().y) / 2));
typhlosion.SetScale(glm::vec2(0.5, 0.5));
Sprite kisse;
kisse.SetTexture("../data/textures/kisse.png");
kisse.SetColor(glm::vec3(0.0, 0.0, 1.0));
kisse.SetPosition(glm::vec2(0, (height - kisse.GetBounds().y) / 2));
Sprite kisse2;
kisse2.SetTexture("../data/textures/kisse.png");
kisse2.SetColor(glm::vec3(0.0, 1.0, 0.0));
kisse2.SetPosition(glm::vec2(width - kisse.GetBounds().x, (height - kisse.GetBounds().y) / 2));
Sprite animation;
animation.SetAnimation("../data/animations/gems.png", "../data/animations/anim_gems.xml");
animation.SetPosition(glm::vec2((width / 2), 250));
animation.SetScale(glm::vec2(2, 2));
renderer2.camera->SetPosition(glm::vec2(1, 1));
renderer3.camera->SetPosition(glm::vec2(1.5, 1.5));
glm::vec2 dir = { 2.0, 2.0 }, dir2 = { 0.0, 1.0 }, dir3 = { 0.0, -1.0 };
int score1 = 0, score2 = 0;
glm::vec3 color = { 0.01, 0.01, 0.01 };
Polygon polygon(300, 200, 1, 0, 350, 350, 1.0f, 0.4f, 0.3f, "../data/textures/planet.png");
Polygon polygon2(4, 100, 1, 0, 850, 350, 1.0f, 0.4f, 0.3f, "../data/textures/kisse.png");
Timer time;
time.Start();
while (!glfwWindowShouldClose(window))
{
glfwPollEvents();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearColor(0.0f, 0.2f, 0.2f, 1.0f);
// Typhlosion koskettaa vasenta tai oikeaa seinää
if (typhlosion.GetPosition().x > width)
{
typhlosion.SetPosition(glm::vec2((width - typhlosion.GetBounds().x) / 2, (height - typhlosion.GetBounds().y) / 2));
dir.x = -2.0;
score1++;
tex.SetText(std::to_string(score1));
}
//.........这里部分代码省略.........
示例9: GetPosition
Vector2f GetPosition()
{
return oSprite.GetPosition();
}
示例10: 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;
}
示例11: RenderObjectAt
//void RenderManager::RenderObjectAt(Entity* object, const a2de::Vector2D& screen_position) {
// if(object == nullptr) return;
// a2de::Vector2D old_pos(object->GetBody()->GetPosition());
// object->GetBody()->SetPosition(screen_position);
// object->Render(al_get_backbuffer(_display_context));
// object->GetBody()->SetPosition(old_pos);
//}
//
void RenderManager::RenderObjectAt(Sprite& sprite, const a2de::Vector2D& screen_position) {
a2de::Vector2D old_pos(sprite.GetPosition());
sprite.SetPosition(screen_position);
sprite.Draw(al_get_backbuffer(_display_context));
sprite.SetPosition(old_pos);
}
示例12: LowerRight
Vector2f LowerRight(Sprite & sprite)
{
return sprite.GetPosition() + sprite.GetSize() - sprite.GetCenter();
}
示例13: UpperLeft
Vector2f UpperLeft(Sprite & sprite)
{
return sprite.GetPosition() - sprite.GetCenter();
}