<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.sugarlabs.org/index.php?action=history&amp;feed=atom&amp;title=Activity_Team%2FSugar-sprites</id>
	<title>Activity Team/Sugar-sprites - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.sugarlabs.org/index.php?action=history&amp;feed=atom&amp;title=Activity_Team%2FSugar-sprites"/>
	<link rel="alternate" type="text/html" href="https://wiki.sugarlabs.org/index.php?title=Activity_Team/Sugar-sprites&amp;action=history"/>
	<updated>2026-04-11T17:49:43Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.0</generator>
	<entry>
		<id>https://wiki.sugarlabs.org/index.php?title=Activity_Team/Sugar-sprites&amp;diff=49044&amp;oldid=prev</id>
		<title>Walter: /* The Sprites Class */</title>
		<link rel="alternate" type="text/html" href="https://wiki.sugarlabs.org/index.php?title=Activity_Team/Sugar-sprites&amp;diff=49044&amp;oldid=prev"/>
		<updated>2010-02-27T21:19:10Z</updated>

		<summary type="html">&lt;p&gt;&lt;span class=&quot;autocomment&quot;&gt;The Sprites Class&lt;/span&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 17:19, 27 February 2010&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l59&quot;&gt;Line 59:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 59:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;     def __init__(self, canvas, area=None, gc=None)&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;     def __init__(self, canvas, area=None, gc=None)&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-added&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;         self.canvas&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;         self.canvas&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;         self.area&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;         self.area&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Walter</name></author>
	</entry>
	<entry>
		<id>https://wiki.sugarlabs.org/index.php?title=Activity_Team/Sugar-sprites&amp;diff=49043&amp;oldid=prev</id>
		<title>Walter: /* Sugar sprites library */</title>
		<link rel="alternate" type="text/html" href="https://wiki.sugarlabs.org/index.php?title=Activity_Team/Sugar-sprites&amp;diff=49043&amp;oldid=prev"/>
		<updated>2010-02-27T21:15:09Z</updated>

		<summary type="html">&lt;p&gt;&lt;span class=&quot;autocomment&quot;&gt;Sugar sprites library&lt;/span&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 17:15, 27 February 2010&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l1&quot;&gt;Line 1:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== Sugar sprites library ==&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== Sugar sprites library ==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;While not yet an official part of Sugar, there is a simple sprites library, [http://git.sugarlabs.org/projects/turtleart/repos/refactoring/blobs/master/sprites.py sprites.py], that is used by many activities, including [[Activities/TurtleArt|Turtle Art]], [[Activities/&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;Visualmatch&lt;/del&gt;|Visual Match]], Slideruler, Cardsort, Erikos, etc.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;While not yet an official part of Sugar, there is a simple sprites library, [http://git.sugarlabs.org/projects/turtleart/repos/refactoring/blobs/master/sprites.py sprites.py], that is used by many activities, including [[Activities/TurtleArt|Turtle Art]], [[Activities/&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;VisualMatch&lt;/ins&gt;|Visual Match]], Slideruler, Cardsort, Erikos, etc.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;sprites.py is a simple sprites library for managing graphics objects, &amp;#039;sprites&amp;#039;, on a canvas. It manages multiple sprites with methods such as move, hide, set_layer, etc.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;sprites.py is a simple sprites library for managing graphics objects, &amp;#039;sprites&amp;#039;, on a canvas. It manages multiple sprites with methods such as move, hide, set_layer, etc.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Walter</name></author>
	</entry>
	<entry>
		<id>https://wiki.sugarlabs.org/index.php?title=Activity_Team/Sugar-sprites&amp;diff=49042&amp;oldid=prev</id>
		<title>Walter: Created page with &#039;== Sugar sprites library ==  While not yet an official part of Sugar, there is a simple sprites library, [http://git.sugarlabs.org/projects/turtleart/repos/refactoring/blobs/mast…&#039;</title>
		<link rel="alternate" type="text/html" href="https://wiki.sugarlabs.org/index.php?title=Activity_Team/Sugar-sprites&amp;diff=49042&amp;oldid=prev"/>
		<updated>2010-02-27T21:14:34Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;#039;== Sugar sprites library ==  While not yet an official part of Sugar, there is a simple sprites library, [http://git.sugarlabs.org/projects/turtleart/repos/refactoring/blobs/mast…&amp;#039;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;== Sugar sprites library ==&lt;br /&gt;
&lt;br /&gt;
While not yet an official part of Sugar, there is a simple sprites library, [http://git.sugarlabs.org/projects/turtleart/repos/refactoring/blobs/master/sprites.py sprites.py], that is used by many activities, including [[Activities/TurtleArt|Turtle Art]], [[Activities/Visualmatch|Visual Match]], Slideruler, Cardsort, Erikos, etc.&lt;br /&gt;
&lt;br /&gt;
sprites.py is a simple sprites library for managing graphics objects, &amp;#039;sprites&amp;#039;, on a canvas. It manages multiple sprites with methods such as move, hide, set_layer, etc.&lt;br /&gt;
&lt;br /&gt;
There are two classes:&lt;br /&gt;
&lt;br /&gt;
* class Sprites maintains a collection of sprites.&lt;br /&gt;
* class Sprite manages individual sprites within the collection.&lt;br /&gt;
&lt;br /&gt;
=== Example usage ===&lt;br /&gt;
&lt;br /&gt;
The basic work flow is to first create a Sprites instance to manage the sprite collection. Then create and use individual sprites.&lt;br /&gt;
&lt;br /&gt;
        # Import the classes into your program.&lt;br /&gt;
        from sprites import Sprites, Sprite&lt;br /&gt;
&lt;br /&gt;
        # Create a new sprite collection for a gtk Drawing Area.&lt;br /&gt;
        my_drawing_area = gtk.DrawingArea()&lt;br /&gt;
        self.sprite_list = Sprites(my_drawing_area)&lt;br /&gt;
&lt;br /&gt;
        # Create a &amp;quot;pixbuf&amp;quot; (in this example, from SVG).&lt;br /&gt;
        my_pixbuf = svg_str_to_pixbuf(&amp;quot;&amp;lt;svg&amp;gt;...some svg code...&amp;lt;/svg&amp;gt;&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
        # Create a sprite at position x1, y1.&lt;br /&gt;
        my_sprite = sprites.Sprite(self.sprite_list, x1, y1, my_pixbuf)&lt;br /&gt;
&lt;br /&gt;
        # Move the sprite to a new position.&lt;br /&gt;
        my_sprite.move((x1+dx, y1+dy))&lt;br /&gt;
&lt;br /&gt;
        # Create another &amp;quot;pixbuf&amp;quot;.&lt;br /&gt;
        your_pixbuf = svg_str_to_pixbuf(&amp;quot;&amp;lt;svg&amp;gt;...some svg code...&amp;lt;/svg&amp;gt;&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
        # Create a sprite at position x2, y2.&lt;br /&gt;
        your_sprite = sprites.Sprite(self.sprite_list, x2, y2, my_pixbuf)&lt;br /&gt;
&lt;br /&gt;
        # Assign the sprites to layers.&lt;br /&gt;
        # In this example, your_sprite will be on top of my_sprite.&lt;br /&gt;
        my_sprite.set_layer(100)&lt;br /&gt;
        your_sprite.set_layer(200)&lt;br /&gt;
&lt;br /&gt;
        # Now put my_sprite on top of your_sprite.&lt;br /&gt;
        my_sprite.set_layer(300)&lt;br /&gt;
&lt;br /&gt;
 # method for converting SVG to a gtk pixbuf&lt;br /&gt;
 def svg_str_to_pixbuf(svg_string):&lt;br /&gt;
     pl = gtk.gdk.PixbufLoader(&amp;#039;svg&amp;#039;)&lt;br /&gt;
     pl.write(svg_string)&lt;br /&gt;
     pl.close()&lt;br /&gt;
     pixbuf = pl.get_pixbuf()&lt;br /&gt;
     return pixbuf&lt;br /&gt;
&lt;br /&gt;
=== The Sprites Class ===&lt;br /&gt;
&lt;br /&gt;
class Sprites&lt;br /&gt;
&lt;br /&gt;
methods:&lt;br /&gt;
&lt;br /&gt;
    def __init__(self, canvas, area=None, gc=None)&lt;br /&gt;
&lt;br /&gt;
        self.canvas&lt;br /&gt;
        self.area&lt;br /&gt;
        self.gc&lt;br /&gt;
        self.cm&lt;br /&gt;
        self.list = []&lt;br /&gt;
&lt;br /&gt;
    def get_sprite(self, i)&lt;br /&gt;
&lt;br /&gt;
    def length_of_list(self)&lt;br /&gt;
&lt;br /&gt;
    def append_to_list(self, spr)&lt;br /&gt;
&lt;br /&gt;
    def insert_in_list(self, spr, i)&lt;br /&gt;
&lt;br /&gt;
    def remove_from_list(self, spr):&lt;br /&gt;
&lt;br /&gt;
    def find_sprite(self, pos):&lt;br /&gt;
&lt;br /&gt;
    def redraw_sprites(self):&lt;br /&gt;
&lt;br /&gt;
=== The Sprite Class ===&lt;br /&gt;
&lt;br /&gt;
class Sprite&lt;br /&gt;
&lt;br /&gt;
methods:&lt;br /&gt;
&lt;br /&gt;
    def __init__(self, sprites, x, y, image):&lt;br /&gt;
        self.layer = 100&lt;br /&gt;
        self.labels = []&lt;br /&gt;
        self.images = []&lt;br /&gt;
&lt;br /&gt;
    def set_image(self, image, i=0, dx=0, dy=0):&lt;br /&gt;
&lt;br /&gt;
    def move(self, pos):&lt;br /&gt;
&lt;br /&gt;
    def move_relative(self, pos):&lt;br /&gt;
&lt;br /&gt;
    def get_xy(self):&lt;br /&gt;
&lt;br /&gt;
    def get_dimensions(self):&lt;br /&gt;
&lt;br /&gt;
    def get_layer(self):&lt;br /&gt;
&lt;br /&gt;
    def set_shape(self, image, i=0):&lt;br /&gt;
&lt;br /&gt;
    def set_layer(self, layer):&lt;br /&gt;
&lt;br /&gt;
    def set_label(self, new_label, i=0):&lt;br /&gt;
&lt;br /&gt;
    def set_margins(self, l=0, t=0, r=0, b=0):&lt;br /&gt;
&lt;br /&gt;
    def set_font(self, font):t)&lt;br /&gt;
&lt;br /&gt;
    def set_label_color(self, rgb):&lt;br /&gt;
&lt;br /&gt;
    def set_label_attributes(self, scale, rescale=True, horiz_align=&amp;quot;center&amp;quot;,&lt;br /&gt;
                             vert_align=&amp;quot;middle&amp;quot;, i=0):&lt;br /&gt;
&lt;br /&gt;
    def hide(self):&lt;br /&gt;
&lt;br /&gt;
    def inval(self):&lt;br /&gt;
&lt;br /&gt;
    def draw(self):&lt;br /&gt;
&lt;br /&gt;
    def hit(self, pos):&lt;br /&gt;
&lt;br /&gt;
    def draw_label(self):&lt;br /&gt;
&lt;br /&gt;
    def label_width(self):&lt;br /&gt;
&lt;br /&gt;
    def label_safe_width(self):&lt;br /&gt;
    &lt;br /&gt;
    def label_safe_height(self):&lt;br /&gt;
    &lt;br /&gt;
    def label_left_top(self):&lt;br /&gt;
&lt;br /&gt;
    def get_pixel(self, pos, i=0):&lt;/div&gt;</summary>
		<author><name>Walter</name></author>
	</entry>
</feed>