hge循环播放两张图片

//zxq 加入云层代码
#ifndef CLOUD_H_
#define CLOUD_H_
#pragma once

#include "hge.h"
#include "hgesprite.h"
#include "hgeanim.h"

class Cloud
{
public:
    Cloud();
    ~Cloud();

    bool OnFrame(float delta_time);
    bool OnRender(float offset_x, float offset_y, float hscale, float vscale);
    bool LoadGameResource();
private:
    static const int kCloudFPS = 120; //zxq   修改云层播放帧率  16
    static const int kCloudFrames = 20;  //zxq   修改云层播放帧率  16

private:
    HGE* hge_;
    float _cloud_x1;//给两张云图的x坐标
    float _cloud_x2;
    float _cloud_y;
    hgeAnimation* spr_cloud_1;//2张云图重复播放
    hgeAnimation* spr_cloud_2;
    HTEXTURE tex_cloud_;
    float  since_last_frame_;

};

#endif // WATER_H_



//zxq  加入云层代码

#include "StdAfx.h"
#include "cloud.h"
#include "game_manager.h"

#define start_width 1366 //设置云层宽度

Cloud::Cloud() :_cloud_x1(0),since_last_frame_(-1),_cloud_y(0){
    hge_ = hgeCreate(HGE_VERSION);

}

Cloud::~Cloud() {
    hge_->Release();
}
//zxq 变更云层的X轴坐标
bool Cloud::OnFrame(float delta_time) {
    if (since_last_frame_ == -1.0f) since_last_frame_ = 0.0f;
    else since_last_frame_ += delta_time;
    static const float kSpeed = 1.0f / kCloudFrames;
    float screen_width = static_cast<float>(hge_->System_GetState(HGE_SCREENWIDTH));
    while (since_last_frame_ >= kSpeed)
    {
        since_last_frame_ -= kSpeed;
        _cloud_x1 += screen_width / (kCloudFPS * 6);
        _cloud_x2 += screen_width / (kCloudFPS * 6);
    }
    
    return false;
}
//zxq 绘制云层
bool Cloud::OnRender(float offset_x, float offset_y, float hscale, float vscale) {
    float screen_width = static_cast<float>(hge_->System_GetState(HGE_SCREENWIDTH));
    float screen_height = static_cast<float>(hge_->System_GetState(HGE_SCREENHEIGHT));

     spr_cloud_1->RenderEx(offset_x+_cloud_x1-screen_width,_cloud_y, 0.0f, hscale, vscale);
     spr_cloud_2->RenderEx(offset_x+_cloud_x2-screen_width,_cloud_y, 0.0f, hscale, vscale);
     if (_cloud_x2-screen_width>=screen_width)//当云2 图片已经过场  重新设置云1 和 云2 的X坐标
     {
         //         _cloud_y=rand()%600-300;  设置绘制高度
         _cloud_x1=screen_width;
         _cloud_x2=0;
         since_last_frame_ = -1.0f;
     }
     if (_cloud_x1-screen_width>=screen_width)//当云1 图片已经过场  重新设置云1 和 云2 的X坐标
     {
//         _cloud_y=rand()%600-300;  设置绘制高度
         _cloud_x2=screen_width;
         _cloud_x1=0;
         since_last_frame_ = -1.0f;
     }
    return false;
}
//zxq 加载云层图片
bool Cloud::LoadGameResource() {

    hgeResourceManager* resource_manager = GameManager::GetInstance().GetResourceManager();    
    spr_cloud_1 = resource_manager->GetAnimation("scene_cloud1");
    spr_cloud_2= resource_manager->GetAnimation("scene_cloud2");
    _cloud_x2=-static_cast<float>(hge_->System_GetState(HGE_SCREENWIDTH)) ;//初始化云2的x坐标

    return true;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值