Neo  0.5.0
Developer Documentation
Neo2D::Sprite Class Reference

The Sprite class displays a texture on the screen. More...

#include <Sprite.h>

+ Inheritance diagram for Neo2D::Sprite:

Public Member Functions

 Sprite (unsigned int x, unsigned int y, unsigned int width, unsigned int height, const char *texture, const char *label)
 Creates a new Sprite with the given options. More...
 
void draw (Vector2 offset)
 Draws the widget to the canvas it belongs to. More...
 
void update ()
 Updates the widget and calls the callback if necessary. More...
 
Vector2 getSize ()
 Returns the textures dimensions that are used. More...
 
- Public Member Functions inherited from Neo2D::Widget
 Widget (unsigned int x, unsigned int y, unsigned int width, unsigned int height, const char *label)
 
 Widget ()
 
void setParent (Widget *w)
 
WidgetgetParent ()
 
float getFontSize ()
 
void setFontSize (float s)
 
void setOffset (Vector2 offset)
 
Vector2 getOffset ()
 
void setSize (unsigned int w, unsigned int h)
 
Vector2 getSize ()
 
virtual void draw ()
 Draws the widget to the canvas it belongs to. More...
 
void setCallback (NEO_CALLBACK_FUNCTION func)
 Sets the callback. More...
 
void setScriptCallback (const char *name)
 
void setCallback (NEO_CALLBACK_FUNCTION func, long int data)
 Sets the callback and appends user data to it. More...
 
long int getUserData ()
 Retrieves the user data that will be given to every callback call. More...
 
void setUserData (long int data)
 Changes the user data that will be given to every callback call. More...
 
const char * getLabel ()
 Gets the currently displayed label a C string. More...
 
void setLabel (const char *l)
 Changes the current label of the widget. More...
 
void setPosition (Vector2 pos)
 Changes the widget position. More...
 
Vector2 getPosition ()
 Retrieves the current position. More...
 
void setRotation (float rot)
 Changes the widget rotation. More...
 
float getRotation ()
 Retrieves the current rotation. More...
 
void translate (Vector2 vec)
 Translates the object. More...
 
void rotate (float value)
 Rotates the object. More...
 
void doCallback ()
 Calls the callback with the user data as an argument. More...
 
bool isVisible ()
 Returns if the widget is turned visible. More...
 
void setVisible (bool v)
 Sets the visibility status. More...
 
void setScale (Vector2 scale)
 setScale Scale this Widget More...
 
Vector2 getScale ()
 
void setFlip (Vector2 flip)
 setFlip Flip this Widget More...
 
Vector2 getFlip ()
 
const char * getStaticName ()
 
virtual bool isMouseOver ()
 

Protected Member Functions

void loadTexture ()
 Loads the texture into memory and registers it with OpenGL. More...
 

Protected Attributes

OTextm_labelText
 
int m_image
 
Vector2 m_imageSize
 
std::string m_imagePath
 
- Protected Attributes inherited from Neo2D::Widget
float m_x
 The 2D coordinates of the widget. More...
 
float m_y
 
float m_rotation
 The rotation of the widget. More...
 
unsigned int m_width
 The width and height of the widget. More...
 
unsigned int m_height
 
std::string m_label
 The label of the widget. More...
 
Vector2 m_offset
 The offset that was used for rendering in the last frame. More...
 
NEO_CALLBACK_FUNCTION m_callback
 The callback that should be called. More...
 
String m_callbackScript
 
long int m_userData
 Some userdata that is given to the callback. More...
 
bool m_visible
 Is the widget visible? More...
 
Vector2 m_scale
 The scale vector. More...
 
Vector2 m_flip
 The flip vector. More...
 
float m_fontSize
 
Widgetm_parent
 

Detailed Description

The Sprite class displays a texture on the screen.

Warning
This way of using Sprites is very slow since the GUI system is not designed for displaying 2D graphics but displaying reusable GUI data! Use a SpriteBatch to display large numbers of Sprite's or Tile's instead!
Creating a new Sprite in C++
Neo2DEngine* engine = Neo2DEngine::getInstance();
// Fetch main canvas
Canvas* mainCanvas = engine->getCanvas(0);
// Calling Sprite(x, y, w, h, file, label) with w = 0 and h = 0
// so the resolution of the texture is used
Sprite* sprite = new Sprite(100, 100, 0, 0, "assets/tex.png", "label");
// Register with the system
int handle = engine->addWidget(sprite);
// Add to canvas
mainCanvas->addWidget(handle);
Creating a new Sprite in Lua
require("NeoLua")
local engine = NeoLua.Neo2DEngine.getInstance()
-- Fetch main canvas
local mainCanvas = engine:getCanvas(0);
-- Calling Sprite(x, y, w, h, file, label) with w = 0 and h = 0
-- so the resolution of the texture is used
local sprite = NeoLua.Sprite(100, 100, 0, 0, "assets/tex.png", "label");
-- Register with the system
local handle = engine:addWidget(sprite);
-- Add to canvas
mainCanvas:addWidget(handle);
Author
Yannick Pflanzer

Constructor & Destructor Documentation

Neo2D::Sprite::Sprite ( unsigned int  x,
unsigned int  y,
unsigned int  width,
unsigned int  height,
const char *  texture,
const char *  label 
)

Creates a new Sprite with the given options.

Parameters
xThe X position.
yThe Y position.
widthThe width. If this value is 0 it will take the width of the texture
heightThe height. If this value is 0 it will take the height of the texture.
textureThe path of the texture to use and display.
labelThe label to display.

Member Function Documentation

void Neo2D::Sprite::draw ( Vector2  offset)
virtual

Draws the widget to the canvas it belongs to.

Parameters
offsetThe offset to apply to the position. Used for emulating a camera.
See also
Canvas

Reimplemented from Neo2D::Widget.

Vector2 Neo2D::Sprite::getSize ( )
inline

Returns the textures dimensions that are used.

Returns
The dimensions of the texture in pixels.
void Neo2D::Sprite::loadTexture ( )
protected

Loads the texture into memory and registers it with OpenGL.

void Neo2D::Sprite::update ( )
virtual

Updates the widget and calls the callback if necessary.

Implements Neo2D::Widget.

Member Data Documentation

int Neo2D::Sprite::m_image
protected
std::string Neo2D::Sprite::m_imagePath
protected
Vector2 Neo2D::Sprite::m_imageSize
protected
OText* Neo2D::Sprite::m_labelText
protected

The documentation for this class was generated from the following file: