未命名.gif


1、创建精灵

Sprite *bg1;
Sprite *bg2;
bg1 = new Sprite(glm::vec2(0.0f, 0.0f), glm::vec2(R(600.0f),R(450.0F)),ResourceManager::GetTexture2D("bg"),glm::vec4(1.0f), glm::vec2(-200.0f,0.0f));
bg2 = new Sprite(glm::vec2(R(-600.0f), 0.0f), glm::vec2(R(600.0f),R(450.0F)),ResourceManager::GetTexture2D("bg"),glm::vec4(1.0f), glm::vec2(-200.0f,0.0f));

2、更新精灵位置数据(Update)

if(bg1->Position.x < bg2->Position.x){
    bg1->Position = bg1->Position + m_deltaTime * bg1->Velocity;
    bg2->Position.x = bg1->Position.x + bg1->Size.x;
}else{
    bg2->Position = bg2->Position + m_deltaTime * bg2->Velocity;
    bg1->Position.x = bg2->Position.x + bg2->Size.x;
}
if(bg1->Position.x + bg1->Size.x < 0.0f){
    bg1->Position.x = bg2->Position.x + bg2->Size.x;
}
if(bg2->Position.x + bg2->Size.x < 0.0f){
    bg2->Position.x = bg1->Position.x + bg1->Size.x;
}

3、渲染精灵(Render)

bg1->Draw(*Renderer);
bg2->Draw(*Renderer);