SpriteRendering
From SWWorkshop
Animated images are the most important part of 2D Game. All actor, vehicle and other item's behaviour can easily shown with Sprite. Sprite mechanism is very simple technique.For example: Character running animation compose of 20 frame of images. In a defined folder these images consist. Now we access these folder. Navigate all files in folder. Load TGA files and bind with OpenGL. SWEngine do this operation only one function
spriteID=swGraphicsCreateSprite("XenRunning\\");
ScreenShot
![]()
Api Doc
SwEngine, swGraphics, swRect, swApplication
Source Code
#include "../../include/SWEngine.h" #pragma comment (lib,"../../lib/SWUtil.lib") #pragma comment (lib,"../../lib/SWTypes.lib") #pragma comment (lib,"../../lib/SWCore.lib") #pragma comment (lib,"../../lib/SWEngine.lib") swApplication spriteRenderingApp; int spriteID; //Img1 Setting swRect target1={200,200,125,150}; //------------------------------------------------------------------------------------------- void GameLoop(){ swGraphicsBeginScene(); //Background swGraphicsSetBgColor0(0,0,0.6); //BlendingMode swGraphicsSetBlendingMode(SW_BLENDING_MODE_SOLID); //Draw Image static index=0; index=(index+1)%swGraphicsGetCountOfImgInSprite(spriteID); swGraphicsSetColor0(1,1,1,1); swGraphicsRenderSprite0(spriteID,index,&target1); swGraphicsEndScene(); } //------------------------------------------------------------------------------------------- int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nShowCmd) { //Application Settings spriteRenderingApp.hInstance=hInstance; spriteRenderingApp.fullScreen=false; spriteRenderingApp.cursor=true; spriteRenderingApp.width=800; spriteRenderingApp.height=600; spriteRenderingApp.title="Sprite Rendering"; spriteRenderingApp.path="\\rsc\\SpriteRendering\\"; spriteRenderingApp.appRun=GameLoop; //Application Execution swEngineInit(&spriteRenderingApp); //Init My Application spriteID=swGraphicsCreateSprite("XenRunning\\"); swEngineRun(); swEngineExit(); return 0; }
