diff options
| author | Tom Black <[email protected]> | 2018-01-30 00:23:34 -0800 |
|---|---|---|
| committer | Tom Black <[email protected]> | 2018-05-06 15:41:06 -0700 |
| commit | 7d3cff5e5d6d53d7f4def94a9dc831e099e03e67 (patch) | |
| tree | c3fc81f0ee676208dee1530ff5935f1b88692677 /ext | |
| parent | 2e07255723428d09eab38ad1a5fde11fc9a287d8 (diff) | |
| download | ruby2d-7d3cff5e5d6d53d7f4def94a9dc831e099e03e67.tar.gz ruby2d-7d3cff5e5d6d53d7f4def94a9dc831e099e03e67.zip | |
Sprite class redesign
See #33 for discussion
Diffstat (limited to 'ext')
| -rw-r--r-- | ext/ruby2d/ruby2d.c | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/ext/ruby2d/ruby2d.c b/ext/ruby2d/ruby2d.c index 0b9e338..2daa7ed 100644 --- a/ext/ruby2d/ruby2d.c +++ b/ext/ruby2d/ruby2d.c @@ -379,6 +379,14 @@ static R_VAL ruby2d_sprite_ext_init(R_VAL self, R_VAL path) { #endif S2D_Log(S2D_INFO, "Init sprite: %s", RSTRING_PTR(path)); S2D_Sprite *spr = S2D_CreateSprite(RSTRING_PTR(path)); + + // Get width and height from Ruby class. If set, use it, else choose the + // native dimensions of the sprite image. + R_VAL w = r_iv_get(self, "@width"); + R_VAL h = r_iv_get(self, "@height"); + r_iv_set(self, "@width" , r_test(w) ? w : INT2NUM(spr->width)); + r_iv_set(self, "@height", r_test(h) ? h : INT2NUM(spr->height)); + r_iv_set(self, "@data", r_data_wrap_struct(sprite, spr)); return R_NIL; } @@ -392,6 +400,8 @@ static R_VAL ruby2d_sprite_ext_render(mrb_state* mrb, R_VAL self) { #else static R_VAL ruby2d_sprite_ext_render(R_VAL self) { #endif + r_funcall(self, "update", 0); + S2D_Sprite *spr; r_data_get_struct(self, "@data", &sprite_data_type, S2D_Sprite, spr); @@ -402,8 +412,8 @@ static R_VAL ruby2d_sprite_ext_render(R_VAL self) { spr, NUM2INT(r_iv_get(self, "@clip_x")), NUM2INT(r_iv_get(self, "@clip_y")), - NUM2INT(r_iv_get(self, "@clip_w")), - NUM2INT(r_iv_get(self, "@clip_h")) + NUM2INT(r_iv_get(self, "@clip_width")), + NUM2INT(r_iv_get(self, "@clip_height")) ); S2D_DrawSprite(spr); |
