Class GObject

class graphics.GObject(**keywords)

Base graphics object for a GameView class.

You should never make a GObject directly. Instead, you should use one of the subclasses: GRectangle, GEllipse, GLine, GImage, and GLabel.

Constructor: creates a new graphics object.

param keywords:dictionary of keyword arguments

Precondition: See below.

To use the constructor for this class, you should provide it with a list of keyword arguments that initialize various attributes. For example, to initialize the x position and the fill color, use the constructor call

GObject(x=2,fillcolor=colormodel.RED)

You do not need to provide the keywords as a dictionary. The ** in the parameter keywords does that automatically.

Any attribute of this class may be used as a keyword. The argument must satisfy the invariants of that attribute. See the list of attributes of this class for more information.

This class is a subclass of Widget from Kivy, and inherits all of its attributes and methods.

Attributes

linecolor

The object line color.

Used to color the foreground, text, or, in the case of solid shapes, the shape border.

Invariant: Must be an RGB or HSV object from module colormodel.

fillcolor

The object fill color.

Used to color the backgrounds or, in the case of solid shapes, the shape interior.

Invariant: Must be an RGB or HSV object from module colormodel.

center

The center position of this graphics object.

Invariant: A tuple of the attributes (center_x, center_y). Hence changing this attribute will change those attributes. The elements of the tuple must be numbers (int or float).

center_x

The x coordinate of the center of this graphics object.

Invariant: Must be equal to (x + width / 2). Hence changing this attribute will change those attributes. The value must be a number (int or float).

center_y

The y coordinate of the center of this graphics object.

Invariant: Must be equal to (y + height / 2). Hence changing this attribute will change those attributes. The value must be a number (int or float).

height

The height of this graphics object.

Invariant: Must be a non-negative number (int or float). Default value is 100.

pos

The position of this graphics object.

Invariant: A tuple of the attributes (x, y). Hence changing this attribute will change those attributes. The elements of the tuple must be numbers (int or float).

right

The position of the right this graphics object.

Invariant: Must be equal to (x + width). Hence changing this attribute will change those attributes. The value must be a number (int or float).

size

The size of this graphics object.

Invariant: A tuple of the attributes (width, height). Hence changing this attribute will change those attributes. The elements of the tuple must be numbers (int or float).

top

The position of the top of this graphics object.

Invariant: Must be equal to (y + height). Hence changing this attribute will change those attributes. The value must be a number (int or float).

width

The width of this graphics object.

Invariant: Must be a non-negative number (int or float). Default value is 100.

x

The x position of this graphics object (specifically, the lower left corner).

Invariant: Must be a non-negative number (int or float). Default value is 0.

y

The y position of this graphics object (specifically, the lower left corner).

Invariant: Must be a non-negative number (int or float). Default value is 0.

Methods

These methods are all inherited from the base class Widget provided in Kivy. You should use them to determine whether or not two graphics objects have collided.

collide_point(x, y)

Returns True if (x,y) is inside this graphics object; False otherwise.

param x:x position in the GameView.

Precondition: a number (int or float)

param y:y position in the GameView.

Precondition: a number (int or float)

The graphics object is defined by the rectangle whose bottom left corner is at pos, and which has the the same width and height as this object. This method checks if (x,y) is in this region.

collide_widget(wid)

This method does nothing.

It has been disabled so that you implement this functionality in the way specified in the assignment.

Table Of Contents

Previous topic

Graphics Objects

Next topic

Class GLine

This Page