cocos.scene module

Scene class.

class Scene(*children)

Bases: cocos.cocosnode.CocosNode

Creates a Scene with layers and / or scenes.

Responsibilities:

Control the dispatching of events to its layers; and background music playback.

Parameters

children (union[Layer or Scene]) – Layers or Scenes that will be part of the scene. They are automatically assigned a z-level from 0 to num_children.

end(value=None)

Ends the current scene.

This is accomplished by calling Director.pop(). Also sets director.return_value to value.

Parameters

value (anything) – The return value. It can be anything. A type or an instance.

load_music(filename)

This prepares a streamed music file to be played in this scene.

Music will be stopped after calling this (even if it was playing before).

Parameters

filename (str) – Filename of music to load. Depending on installed libraries, supported formats may be WAV, MP3, OGG, MOD. You can also use None to unset music.

on_enter()

Called every time the Scene enters the stage.

on_exit()

Called every time the Scene exits the stage.

play_music()

Enable music playback for this scene. Nothing happens if music was already playing.

Note that if you call this method on an inactive scene, the music will start playing back only if/when the scene gets activated.

stop_music()

Stops music playback for this scene.