Class: Carbuncle::Game

Inherits:
Container show all
Defined in:
gems/carbuncle-core/mrblib/game.rb

Constant Summary

Constants included from Enumerable

Enumerable::NONE

Instance Attribute Summary collapse

Lifecycle methods collapse

Lifecycle events collapse

Instance Method Summary collapse

Methods inherited from Container

#add_child, #add_children, #children, #draw, #each, #initialize, #remove_child, #remove_children, #update

Methods included from Enumerable

__update_hash, #all?, #any?, #chain, #collect, #count, #cycle, #detect, #drop, #drop_while, #each_cons, #each_slice, #each_with_index, #each_with_object, #entries, #filter_map, #find_all, #find_index, #first, #flat_map, #grep, #group_by, #hash, #include?, #inject, #lazy, #max, #max_by, #min, #min_by, #minmax, #minmax_by, #none?, #one?, #partition, #reject, #reverse_each, #sort, #sort_by, #sum, #take, #take_while, #tally, #to_h, #uniq, #zip

Constructor Details

This class inherits a constructor from Carbuncle::Container

Instance Attribute Details

#current_gameCarbuncle::Game (readonly)

The current game, that’s already running.

Returns:



# File 'gems/carbuncle-core/mrblib/game.rb', line 4

Instance Method Details

#after_closenil

This event is called after the game is closed and the screen is destroyed.

Returns:

  • (nil)


66
# File 'gems/carbuncle-core/mrblib/game.rb', line 66

def after_close; end

#after_runnil

This event is called after the game starts, even after load. You can use this event to trigger your start, if you want to keep it separated from load.

Returns:

  • (nil)


58
# File 'gems/carbuncle-core/mrblib/game.rb', line 58

def after_run; end

#before_closenil

This event is called before the game is closed, useful for cleanup.

Returns:

  • (nil)


62
# File 'gems/carbuncle-core/mrblib/game.rb', line 62

def before_close; end

#before_runnil

This event is called before the game starts, even before the screen is initialized. If you require to load your assets, use Carbuncle::Game#load instead.

Returns:

  • (nil)


53
# File 'gems/carbuncle-core/mrblib/game.rb', line 53

def before_run; end

#file_dropped(*files) ⇒ nil

This method is called when a file is dropped.

Returns:

  • (nil)


71
# File 'gems/carbuncle-core/mrblib/game.rb', line 71

def file_dropped(*files); end

#loadnil

This method is called before the graphics context are created. Only really used when working on the web. This will prepare the files on the filesystem so the game can load them properly. Any file preloaded here will be awaited before starting the engine, on the loading screen. Any other initial configuration like screen size would be nice to be added here. If you don’t preload the file here, it will still be loaded, but may hang the website if the file is too big.

Examples:

The game is a web game

class MyGame < Carbuncle::Game
  def load
    Loader.prepare("img/hero.png")
  end

  def start
     @hero = Texture.new("img/hero.png")
     # the rest of your code here...
  end
end

Returns:

  • (nil)


34
# File 'gems/carbuncle-core/mrblib/game.rb', line 34

def load; end

#on_resize(width, height) ⇒ nil

Called on the web when the canvas resizes

Returns:

  • (nil)


77
# File 'gems/carbuncle-core/mrblib/game.rb', line 77

def on_resize(width, height); end

#running?Boolean

Returns true if a game is running

Returns:

  • (Boolean)


# File 'gems/carbuncle-core/mrblib/game.rb', line 4

#startnil

This method is called after the graphics context is created and assets were prepared. This method is the one you run to setup the game.

Examples:

The game starts

class MyGame < Carbuncle::Game
  def start
    # The assets are loaded, so we can load our assets
    SceneManager.set(TitleScene)
  end
end

Returns:

  • (nil)


46
# File 'gems/carbuncle-core/mrblib/game.rb', line 46

def start; end