| Class | Joyau::Sprite |
| In: |
Drawable.cpp
|
| Parent: | Joyau::Drawable |
This drawable represents an image. You can do lots of manipulations, like showing an animated sprite.
| LEFT | = | INT2FIX(Sprite::LEFT) |
| RIGHT | = | INT2FIX(Sprite::RIGHT) |
| UP | = | INT2FIX(Sprite::UP) |
| DOWN | = | INT2FIX(Sprite::DOWN) |
| UP_LEFT | = | INT2FIX(Sprite::UP_LEFT) |
| UP_RIGHT | = | INT2FIX(Sprite::UP_RIGHT) |
| DOWN_LEFT | = | INT2FIX(Sprite::DOWN_LEFT) |
| DOWN_RIGHT | = | INT2FIX(Sprite::DOWN_RIGHT) |
Creates a Sprite.
/*
call-seq: new()
new(filename)
new(buffer)
Creates a Sprite.
*/
VALUE wrap<Sprite>(int argc, VALUE *argv, VALUE info)
{
Sprite *ptr = NULL;
VALUE tdata;
if (argc >= 1) {
if (rb_obj_is_kind_of(argv[0], getClass("Buffer"))) {
ptr = new Sprite(getRef<Buffer>(argv[0]));
}
else {
argv[0] = rb_obj_as_string(argv[0]);
try {
ptr = new Sprite;
ptr->setPicture(StringValuePtr(argv[0]));
}
catch (const RubyException &e) {
e.rbRaise();
}
}
}
tdata = Data_Wrap_Struct(info, 0, wrapped_free<Sprite>, ptr);
return tdata;
}
Sets the autoDir value. When true, the sprite’s direction changes according to its moves.
/*
Sets the autoDir value. When true, the sprite's direction changes
according to its moves.
*/
VALUE Sprite_setAutoDir(VALUE self, VALUE val)
{
Sprite &ref = getRef<Sprite>(self);
ref.setAutoDir(val == Qtrue);
return val;
}
Changes the sprite’s buffer directly.
/* call-seq: buffer=(buf) Changes the sprite's buffer directly. */ VALUE Sprite_setBuffer(VALUE self, VALUE buf)
Returns the sprite’s transparency.
/*
Returns the sprite's transparency.
*/
VALUE Sprite_getAlpha(VALUE self)
{
Sprite &item = getRef<Sprite>(self);
return INT2FIX(item.getAlpha());
}
Returns the sprite’s angle.
/*
Returns the sprite's angle.
*/
VALUE Sprite_getAngle(VALUE self)
{
Sprite &item = getRef<Sprite>(self);
return INT2FIX(item.getAngle());
}
Returns the sprite’s direction.
/*
Returns the sprite's direction.
*/
VALUE Sprite_getDirection(VALUE self)
{
Sprite &item = getRef<Sprite>(self);
return INT2FIX(item.getDirection());
}
Returns the sprite’s zoom.
/*
Returns the sprite's zoom.
*/
VALUE Sprite_getZoom(VALUE self)
{
Sprite &item = getRef<Sprite>(self);
return INT2FIX(item.getZoom());
}
Returns the sprite’s picture name.
/*
Returns the sprite's picture name.
*/
VALUE Sprite_picture(VALUE self)
{
Sprite &ref = getRef<Sprite>(self);
return rb_str_new2(ref.getPicName().c_str());
}
Sets the sprite’s ressource name. This might be useful when used along with Buffers.
/* call-seq: res_name=(val) Sets the sprite's ressource name. This might be useful when used along with Buffers. */ VALUE Sprite_setResName(VALUE self, VALUE pic)
Saves the sprite in a file.
/*
call-seq: saveFile(filename)
Saves the sprite in a file.
*/
VALUE Sprite_saveFile(VALUE self, VALUE pic)
{
Sprite &item = getRef<Sprite>(self);
const char *file = StringValuePtr(pic);
item.saveImage(file);
return Qnil;
}
Sets the sprite’s transparency.
/*
call-seq: setAlpga(val)
Sets the sprite's transparency.
*/
VALUE Sprite_setAlpha(VALUE self, VALUE alpha)
{
Sprite &item = getRef<Sprite>(self);
item.setAlpha(FIX2INT(alpha));
return alpha;
}
Sets the sprite’s angle.
/*
call-seq: setAngle(val)
Sets the sprite's angle.
*/
VALUE Sprite_setAngle(VALUE self, VALUE angle)
{
Sprite &item = getRef<Sprite>(self);
item.setAngle(FIX2INT(angle));
return angle;
}
Sets how many animation steps there are in the sprite. This considers that each step has the same size.
/*
call-seq: setAnimation(x, y)
Sets how many animation steps there are in the sprite.
This considers that each step has the same size.
*/
VALUE Sprite_setAnimation(VALUE self, VALUE nbrX, VALUE nbrY)
{
Sprite &item = getRef<Sprite>(self);
item.setAnimation(FIX2INT(nbrX), FIX2INT(nbrY));
return Qnil;
}
Sets how many frame the sprite should stay on the same animation.
/*
call-seq: setAnimTime(frames)
Sets how many frame the sprite should stay on the same animation.
*/
VALUE Sprite_setAnimationTime(VALUE self, VALUE t)
{
Sprite &item = getRef<Sprite>(self);
item.setAnimationTime(FIX2INT(t));
return t;
}
Sets the sprite’s direction.
/*
call-seq: setDirection(dir)
Sets the sprite's direction.
*/
VALUE Sprite_setDirection(VALUE self, VALUE dir)
{
Sprite &item = getRef<Sprite>(self);
item.setDirection(FIX2INT(dir));
return dir;
}
Sets the sprite’s file. Notice that the same picture won’t be loaded twice: all the sprites will share that ressource.
/*
call-seq: setPicture(pic)
Sets the sprite's file. Notice that the same picture won't be loaded
twice: all the sprites will share that ressource.
*/
VALUE Sprite_setPicture(VALUE self, VALUE pic)
{
Sprite &item = getRef<Sprite>(self);
try {
item.setPicture(StringValuePtr(pic));
}
catch(const RubyException &e) {
e.rbRaise();
}
return pic;
}
Sets the rect which is shown.
/*
call-seq: setTile(x, y, w, h)
Sets the rect which is shown.
*/
VALUE Sprite_setTile(VALUE self, VALUE x, VALUE y, VALUE w, VALUE h)
{
Sprite &item = getRef<Sprite>(self);
item.setTile(FIX2INT(x), FIX2INT(y), FIX2INT(w), FIX2INT(h));
return Qnil;
}
Converts the sprite in a buffer.
/* Converts the sprite in a buffer. */ VALUE Sprite_to_buf(VALUE self)
This function has got a bang in its name, because it is a very dangerous variant of to_buf: It returns the buffer used by the Sprite. Which means you might be modifying a ressource which is used at multiple places in your program. Use it with care.
/* This function has got a bang in its name, because it is a very dangerous variant of to_buf: It returns the buffer used by the Sprite. Which means you might be modifying a ressource which is used at multiple places in your program. Use it with care. */ VALUE Sprite_to_buf2(VALUE self)