-
-
Save G3z/1859159 to your computer and use it in GitHub Desktop.
Cocos2D v0.2 example in CoffeeScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Pull in the modules we're going to use | |
cocos = require 'cocos2d' # Import the cocos2d module | |
nodes = cocos.nodes # Convenient access to 'nodes' | |
events = require 'events' # Import the events module | |
geo = require 'geometry' # Import the geometry module | |
# Convenient access to some constructors | |
Layer = nodes.Layer | |
Scene = nodes.Scene | |
Label = nodes.Label | |
Director = cocos.Director | |
Point = geo.Point | |
class CoffeeTest extends Layer | |
constructor: -> | |
# You must always call the super class constructor | |
super() | |
# Get size of canvas | |
s = Director.sharedDirector.winSize | |
# Create label | |
label = new Label | |
string: 'Coffee Test' | |
fontName: 'Arial' | |
fontSize: 67 | |
# Position the label in the centre of the view | |
label.position = new Point s.width / 2, s.height / 2 | |
# Add label to layer | |
@addChild label | |
# Initialise application | |
exports.main = -> | |
# Get director singleton | |
director = Director.sharedDirector | |
# Wait for the director to finish preloading our assets | |
events.addListener director, 'ready', (director) -> | |
# Create a scene and layer | |
scene = new Scene | |
layer = new CoffeeTest | |
# Add our layer to the scene | |
scene.addChild layer | |
# Run the scene | |
director.replaceScene scene | |
# Preload our assets | |
director.runPreloadScene() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment