Below is the code for adding a sprite. Each sprite is a frame in a sprite sheet and is looped based on the speed the user wants.
#include "precomp.hpp"
#include "Engine.hpp"
#include "Animation.hpp"
#include <stdlib.h>
int main(int aargc, const char* argv[])
{
// Setup the window
Engine* engine = new Engine("Game Engine Sprite Test", 800,600);
// Load a texture
int t0 = engine->addTexture("link.png");
// Create collision area
std::vector<ge::fVertex> square;
square.push_back(ge::fVertex(0.0f,0.0f));
square.push_back(ge::fVertex(64.0f,0.0f));
square.push_back(ge::fVertex(64.0f,64.0f));
square.push_back(ge::fVertex(0.0f,64.0f));
// Create a collider sprite
Animation* link = new Animation();
link->setScale(.5f,.5f);
link->setTexture(t0);
link->setSpeed(200);
link->setLoop(true);
// StartX, StartY, Width, Height
link->addFrame(0,0,120,130);
link->addFrame(0,520,120,130);
link->addFrame(120,520,120,130);
link->addFrame(240,520,120,130);
link->addFrame(360,520,120,130);
link->addFrame(480,520,120,130);
link->addFrame(600,520,120,130);
link->addFrame(720,520,120,130);
link->addFrame(840,520,120,130);
link->addFrame(960,520,120,130);
link->addFrame(1080,520,120,130);
link->play();
// Set link as a collider
//link->setCollision(&square, ge::Collision_SOLID);
// Add our link as a sprite
engine->addSprite(link);
//std::vector<Entity*>::iterator it;
while(engine->isRunning())
{
engine->run();
}
delete engine;
engine = NULL;
}
I will have another post explaining the entity class in detail and it's components.
No comments:
Post a Comment