CocosNode: the basic element of cocos2d
Bases: object
Cocosnode is the main element. Anything thats gets drawn or contains things that get drawn is a cocosnode. The most popular cocosnodes are scenes, layers and sprites.
Some cocosnodes provide extra functionality for them or their children.
Adds a child and if it becomes part of the active scene calls its on_enter method
Parameters: |
|
---|---|
Return type: | CocosNode instance |
Returns: | self |
Determine whether any actions are running.
Executes an action. When the action finished, it will be removed from the node’s actions container.
Parameters: |
|
---|---|
Return type: | Action instance |
Returns: | A clone of action |
to remove an action you must use the .do return value to call .remove_action
This is the function you will have to override if you want your subclassed to draw something on screen.
You must respect the position, scale, rotation and anchor attributes. If you want OpenGL to do the scaling for you, you can:
def draw(self):
glPushMatrix()
self.transform()
# ... draw ..
glPopMatrix()
Gets a child given its name
Parameters: |
|
---|---|
Return type: | CocosNode |
Returns: | the child named ‘name’. Will raise Exception if not present |
Warning: if a node is added with name, then removed not by name, the name cannot be recycled: attempting to add other node with this name will produce an Exception.
Walks the nodes tree upwards until it finds a node of the class klass or returns None
Return type: | CocosNode or None |
---|
Return a list with the node’s childs, order is back to front
Return type: | list of CocosNode |
---|---|
Returns: | childs of this node, ordered back to front |
returns an euclid.Matrix3 with the local inverse transformation matrix
Return type: | euclid.Matrix3 |
---|
returns an euclid.Matrix3 with the local transformation matrix
Return type: | euclid.Matrix3 |
---|
returns an euclid.Matrix3 with the world inverse transformation matrix
Return type: | euclid.Matrix3 |
---|
returns an euclid.Matrix3 with the world transformation matrix
Return type: | euclid.Matrix3 |
---|
Remove this object from its parent, and thus most likely from everything.
Called every time just before the node enters the stage.
scheduled calls and worker actions begins or continues to perform
Good point to do .push_handlers if you have custom ones Rule: a handler pushed there is near certain to require a .pop_handlers in the .on_exit method (else it will be called even after removed from the active scene, or, if going on stage again will be called multiple times for each event ocurrence)
Called every time just before the node leaves the stage
scheduled calls and worker actions are suspended, that is, will not be called until an on_enter event happens.
Most of the time you will want to .pop_handlers for all explicit .push_handlers found in on_enter
Consider to release here openGL resources created by this node, like compiled vertex lists
Suspends the execution of actions.
Time will stop passing for this node: scheduled callbacks will not be called, worker actions will not be called
returns an euclid.Vector2 converted to local space
Return type: | euclid.Vector2 |
---|
returns an euclid.Vector2 converted to world space
Return type: | euclid.Vector2 |
---|
Removes a child given its name or object
If the node was added with name, it is better to remove by name, else the name will be unavailable for further adds ( and will raise Exception if add with this same name is attempted)
If the node was part of the active scene, its on_exit method will be called.
Parameters: |
|
---|
Removes an action from the node actions container, potentially calling action.stop()
If action was running, action.stop is called Mandatory interfase to remove actions in the node actions container. When skipping this there is the posibility to double call the action.stop
Parameters: |
|
---|
Resumes the execution of actions.
Time will continue/start passing for this node and callbacks will be called, worker actions will be called
Schedule a function to be called every frame.
The function should have a prototype that includes dt as the first argument, which gives the elapsed time, in seconds, since the last clock tick. Any additional arguments given to this function are passed on to the callback:
def callback(dt, *args, **kwargs):
pass
Parameters: |
|
---|
This function is a wrapper to pyglet.clock.schedule. It has the additional benefit that all calllbacks are paused and resumed when the node leaves or enters a scene.
You should not have to schedule things using pyglet by yourself.
Schedule a function to be called every interval seconds.
Specifying an interval of 0 prevents the function from being called again (see schedule to call a function as often as possible).
The callback function prototype is the same as for schedule.
Parameters: |
|
---|
This function is a wrapper to pyglet.clock.schedule_interval. It has the additional benefit that all calllbacks are paused and resumed when the node leaves or enters a scene.
You should not have to schedule things using pyglet by yourself.
Removes all actions from the running action list
For each action running the stop method will be called, and the action will be retired from the actions container.
Apply ModelView transformations
you will most likely want to wrap calls to this function with glPushMatrix/glPopMatrix
Remove a function from the schedule.
If the function appears in the schedule more than once, all occurances are removed. If the function was not scheduled, no error is raised.
Parameters: |
|
---|
This function is a wrapper to pyglet.clock.unschedule. It has the additional benefit that all calllbacks are paused and resumed when the node leaves or enters a scene.
You should not unschedule things using pyglet that where scheduled by node.schedule/node.schedule_interface.
This function visits it’s children in a recursive way.
It will first visit the children that that have a z-order value less than 0.
Then it will call the draw method to draw itself.
And finally it will visit the rest of the children (the ones with a z-value bigger or equal than 0)
Before visiting any children it will call the transform method to apply any possible transformation.
Executes callback on all the subtree starting at self. returns a list of all return values that are not none
Parameters: |
|
---|---|
Return type: | list |
Returns: | the list of not-none return values |
list of Action objects that are running
Anchor point of the object. Children will be added at this point and transformations like scaling and rotation will use this point as the center
Anchor x value for transformations and adding children
Anchor y value for transformations and adding children
eye, center and up vector for the Camera. gluLookAt() is used with these values. Default: FOV 60, center of the screen. IMPORTANT: The camera can perform exactly the same transformation as scale, rotation and the x, y attributes (with the exception that the camera can modify also the z-coordinate) In fact, they all transform the same matrix, so use either the camera or the other attributes, but not both since the camera will be overridden by the transformations done by the other attributes. You can change the camera manually or by using the Camera3DAction action.
list of (int, child-reference) where int is the z-order, sorted by ascending z (back to front order)
dictionary that maps children names with children references
the grid object for the grid actions. This can be a Grid3D or a TiledGrid3D object depending on the action.
whether of not the object is running
The parent of this object.
Type: | object |
---|
The (x, y) coordinates of the object.
Type: | (int, int) |
---|
list of scheduled callbacks
list of scheduled interval callbacks
whether or not the next frame will be skipped
list of Action objects to be removed
Transformation anchor point. Transformations like scaling and rotation will use this point as it’s center
offset from (x,0) from where rotation and scale will be applied. Default: 0
offset from (0,y) from where rotation and scale will be applied. Default: 0
whether of not the object and his childrens are visible. Default: True
The x coordinate of the object
The y coordinate of the object