source: abuse/trunk/src/imlib/sprite.cpp @ 682

Last change on this file since 682 was 682, checked in by Sam Hocevar, 8 years ago

core: rename vec2i to ivec2 and update matrix.h from Lol Engine.

File size: 1.3 KB
Line 
1/*
2 *  Abuse - dark 2D side-scrolling platform game
3 *  Copyright (c) 1995 Crack dot Com
4 *  Copyright (c) 2005-2011 Sam Hocevar <sam@hocevar.net>
5 *
6 *  This software was released into the Public Domain. As with most public
7 *  domain software, no warranty is made or implied by Crack dot Com, by
8 *  Jonathan Clark, or by Sam Hocevar.
9 */
10
11#if defined HAVE_CONFIG_H
12#   include "config.h"
13#endif
14
15#include <math.h>
16
17#include "common.h"
18
19#include "video.h"
20#include "image.h"
21#include "palette.h"
22#include "linked.h"
23#include "sprite.h"
24
25Sprite::Sprite(image *screen, image *visual, ivec2 pos)
26{
27    CHECK(visual && screen);
28    m_pos = pos;
29    m_visual = visual;
30    m_screen = screen;
31    m_save = new image(visual->Size());
32
33    if (m_pos + visual->Size() >= 0 && m_pos < ivec2(xres, yres))
34        m_save->PutPart(m_screen, ivec2(0,0), m_pos, m_pos + m_save->Size());
35}
36
37Sprite::~Sprite()
38{
39    delete m_save;
40}
41
42void Sprite::SetVisual(image *visual, int delete_old)
43{
44    if (delete_old)
45        delete m_visual;
46    m_visual = visual;
47    if (m_save->Size() != visual->Size())
48    {
49        delete m_save;
50        m_save = new image(visual->Size());
51    }
52
53    if (m_pos + visual->Size() >= 0 && m_pos < ivec2(xres, yres))
54        m_save->PutPart(m_screen, ivec2(0,0), m_pos, m_pos + m_save->Size());
55}
56
Note: See TracBrowser for help on using the repository browser.