📄 gameobjectanim.cpp
字号:
// ***************************************************************
// GameObjectAnim version: 1.0
// -------------------------------------------------------------
// File Name: GameObjectAnim.cpp
// Created: 2007/07/18
// Modified: 2007/07/18 15:44
// Author: ben
// Msn:
// Email:
// Description:
//
// Purpose:
// -------------------------------------------------------------
// license:
//
// The contents of this file are subject to the Mozilla Public
// License Version 1.1 (the "License"); you may not use this file
// except in compliance with the License. You may obtain a copy
// of the License at http://www.mozilla.org/MPL/ Software dis-
// tributed under the License is distributed on an "AS IS"
// basis, WITHOUT WARRANTY OF ANY KIND, either express or im-
// plied. See the License for the specific language governing
// rights and limitations under the License.
//
// The Initial Developer of the Original Code is Ben .
// Copyright (C) 2007 - All Rights Reserved.
// ***************************************************************
#include "StdAfx.h"
#include ".\gameobjectanim.h"
CGameObjectAnim::CGameObjectAnim(void)
{
m_hgeAnim = NULL;
m_dwFrames = 1;
m_dwCols = 1;
m_dwRows = 1;
m_fSpeed = 12;
m_wCurrentRow = 0;
}
CGameObjectAnim::~CGameObjectAnim(void)
{
}
/* 函数:创建动画
* write by Ben at 2007.7.6
*
* 参数: lpName 对象名字 , rcSize 纹理大小 , pResource 纹理句柄 , nframes 动画总帧数 , fps 动画播放速度
* nCols 列数 , nRows 行数
* 返回: bool 成功与否
*
* 备注: 该函数继承于CGameObject类中的Create
*/
bool CGameObjectAnim::Create(LPCTSTR lpName,_SIZE rcSize,CResource* pResource,DWORD dwFrames,float FPS,DWORD dwCols,DWORD dwRows){
__super::Create(lpName,rcSize,Type_Animation);
//_SIZE rcFrameSize; //动画一帧的区域
_SIZE siTextureSize = pResource->GetSize();;
float width = siTextureSize.cx/dwCols; //纹理宽
float height = siTextureSize.cy/dwRows; //纹理高
//rcFrameSize.cx = width;
//rcFrameSize.cy = height;
m_dwCols = dwCols;
m_dwRows = dwRows;
m_dwFrames = dwFrames;
//__super::SetSize(rcFrameSize);
m_hgeAnim = new hgeAnimation(pResource->GetTexture(),dwFrames,FPS,0,0,width,height);
if(m_hgeAnim == NULL)
return false;
else{
//Play();
return true;
}
}
/* 函数:渲染函数
* write by Ben at 2007.7.6
*
* 参数: 无
*
* 返回: 无返回值
*
* 备注: 该函数继承于CGameObject类中的Render
*/
void CGameObjectAnim::Render(WPARAM wParam){
if(m_hgeAnim){
m_hgeAnim->Update( *(float*)(wParam) );
m_hgeAnim->RenderEx(m_BasalInfo.ScreenPos.x,m_BasalInfo.ScreenPos.y ,m_GameBasalInfo.Angle,
m_GameBasalInfo.Scaling.cx,m_GameBasalInfo.Scaling.cy);
//m_hgeAnim->Render(m_BasalInfo.ScreenPos .x ,m_BasalInfo.ScreenPos.y);
}
return;
}
/* 函数:设置纹理
* write by Ben at 2007.7.6
*
* 参数:hTex 纹理句柄
*
* 返回: 无返回
*
* 备注: 设置动画的纹理
*/
void CGameObjectAnim::SetTexture(HTEXTURE hTexture){
m_hgeAnim->SetTexture(hTexture);
return;
}
/* 函数:返回纹理
* write by Ben at 2007.7.6
*
* 参数:无
*
* 返回: 纹理
*
* 备注: 返回纹理
*/
HTEXTURE CGameObjectAnim::GetTexture(){
return m_hgeAnim->GetTexture();
}
//返回当前播放的行
WORD CGameObjectAnim::GetRow(){
return m_wCurrentRow;
}
//设置播放的行
void CGameObjectAnim::SetRow(WORD wRow){
if(wRow<m_dwRows){
m_wCurrentRow = wRow;
m_hgeAnim->SetTextureRect(0, m_wCurrentRow*m_BasalInfo.Size.cy, m_BasalInfo.Size.cx, m_BasalInfo.Size.cy);
}
}
/* 函数:设置从第n帧播放
* write by Ben at 2007.7.6
*
* 参数: DWORD n 第n帧
*
* 返回: 无
*
* 备注: 控制动画从第n帧开始播放
*/
void CGameObjectAnim::SetFrame(DWORD n){
m_hgeAnim->SetFrame(n);
return;
}
/* 函数:返回正在播放第n帧
* write by Ben at 2007.7.6
*
* 参数:无
*
* 返回: DWORD
*
* 备注: 返回第n帧
*/
DWORD CGameObjectAnim::GetFrame(){
return (DWORD)m_hgeAnim->GetFrame() ;
}
/* 函数:设置动画总帧数
* write by Ben at 2007.7.6
*
* 参数:无
*
* 返回: 无
*
* 备注: 设置总帧数
*/
void CGameObjectAnim::SetFrames(DWORD nframes){
m_hgeAnim->SetFrames(nframes);
return;
}
/* 函数:返回动画总帧数
* write by Ben at 2007.7.6
*
* 参数:无
*
* 返回:DWORD 总帧数
*
* 备注:返回总帧数
*/
DWORD CGameObjectAnim::GetFrames(){
return m_hgeAnim->GetFrames();
}
/* 函数:设置播放模式
* write by Ben at 2007.7.6
*
* 参数:DWORD type 播放模式
*
* 返回:无
*
* 备注:设置播放模式 HGEANIM_FWD|HGEANIM_REV|HGEANIM_PINGPONG|HGEANIM_NOPINGPONG|HGEANIM_LOOP|HGEANIM_NOLOOP
*/
void CGameObjectAnim::SetMode(DWORD type){
m_hgeAnim->SetMode(type);
return;
}
/* 函数:返回播放模式
* write by Ben at 2007.7.6
*
* 参数:无
*
* 返回:DWORD 播放模式
*
* 备注:返回播放模式
*/
DWORD CGameObjectAnim::GetMode(){
return m_hgeAnim->GetMode() ;
}
/* 函数:设置播放速度
* write by Ben at 2007.7.6
*
* 参数:float fps 播放速度
*
* 返回:无
*
* 备注:设置速度
*/
void CGameObjectAnim::SetSpeed(float fps){
m_hgeAnim->SetSpeed(fps);
return;
}
/* 函数:返回播放速度
* write by Ben at 2007.7.6
*
* 参数:无
*
* 返回:float 播放速度
*
* 备注:返回播放速度
*/
float CGameObjectAnim::GetSpeed(){
return m_hgeAnim->GetSpeed() ;
}
/* 函数:判断断是否播放
* write by Ben at 2007.7.6
*
* 参数:无
*
* 返回:bool 播放标志
*
* 备注:判断是否在播放
*/
bool CGameObjectAnim::IsPlaying(){
return m_hgeAnim->IsPlaying() ;
}
/* 函数:改变动画纹理
* write by Ben at 2007.7.6
*
* 参数:无
*
* 返回:无
*
* 备注:改变动画纹理
*/
void CGameObjectAnim::SetType(DWORD dwType,DWORD dwFrames,float fFps,bool bIsRow){
float fWidth = m_BasalInfo.Size.cx;
float fHeight = m_BasalInfo.Size.cy;
if(bIsRow){
if(dwType>m_dwRows) return;
m_hgeAnim->SetTextureRect(0.0f,(float)(dwType*fHeight),fWidth,fHeight);
m_hgeAnim->SetFrames(dwFrames);
m_hgeAnim->SetSpeed(fFps);
}else{
if(dwType>m_dwCols) return;
m_hgeAnim->SetTextureRect((float)(dwType*fWidth),0.0f,fWidth,fHeight);
m_hgeAnim->SetFrames(dwFrames);
m_hgeAnim->SetSpeed(fFps);
}
//m_hgeAnim->Play();
return ;
}
/* 函数:播放
* write by Ben at 2007.7.6
*
* 参数:无
*
* 返回:无
*
* 备注:播放动画
*/
void CGameObjectAnim::Play(){
m_hgeAnim->Play();
return;
}
//转至下一帧
void CGameObjectAnim::NextFrame(){
DWORD dwCurrFrame = GetFrame();
if(dwCurrFrame+1<m_dwFrames)
SetFrame(dwCurrFrame+1);
else
SetFrame(0);
}
/* 函数:停止
* write by Ben at 2007.7.6
*
* 参数:无
*
* 返回:无
*
* 备注:停止播放
*/
void CGameObjectAnim::Stop(){
m_hgeAnim->Stop();
return;
}
/* 函数:查询接口
* write by Ben at 2007.7.6
*
* 参数:无
*
* 返回:bool 播放标志
*
* 备注:判断是否在播放
*/
void* CGameObjectAnim::QueryInterface(const IID &Guid,DWORD dwQueryVer){
QUERYINTERFACE(IGameObjectAnim,Guid,dwQueryVer);
QUERYINTERFACE(IGameObject,Guid,dwQueryVer);
QUERYINTERFACE(IBaseObject,Guid,dwQueryVer);
QUERYINTERFACE_IUNKNOWNEX(IGameObjectAnim,Guid,dwQueryVer)
return NULL;
}
//************************************
// <p>Description: =操作重载</p>
// <p>Parameters: </p>
// <p> const CGameObjectAnim & GameObject</p>
//
// <p>Returns: CGameObjectAnim&</p>
//************************************
CGameObjectAnim& CGameObjectAnim::operator=(CGameObjectAnim& GameObject){
CGameObject* pOtherBaseClass = static_cast<CGameObject *>(&GameObject);
CGameObject* pMySelfBaseClass = static_cast<CGameObject *>(this);
*pMySelfBaseClass = *pOtherBaseClass;
m_hgeAnim = new hgeAnimation(*GameObject.m_hgeAnim);;
m_dwFrames = GameObject.m_dwFrames;
m_dwCols = GameObject.m_dwCols;
m_dwRows = GameObject.m_dwRows;
m_fSpeed = GameObject.m_fSpeed;
return *this;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -