How To Make a Cross-Platform Game with Cocos2D Javascript Tutorial: Getting Started

Discussion of the official tutorials published on raywenderlich.com. Please only discuss the official tutorials here - for general questions, use the General Discussion forum instead.

How To Make a Cross-Platform Game with Cocos2D Javascript Tutorial: Getting Started

Postby rwenderlich » Mon Feb 25, 2013 11:00 am

This is the official thread to discuss the following blog post: How To Make a Cross-Platform Game with Cocos2D Javascript Tutorial: Getting Started
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
Ray Wenderlich
Blog: http://www.raywenderlich.com
Twitter: http://twitter.com/rwenderlich
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
User avatar
rwenderlich
Team Member
Site Admin
 
Posts: 2155
Joined: Thu Dec 23, 2010 4:14 pm
Has thanked: 28 times
Been thanked: 343 times

Re: How To Make a Cross-Platform Game with Cocos2D Javascrip

Postby grillaface » Mon Feb 25, 2013 9:06 pm

God bless you Ray ;)

So excited to try this out! I'm doing a gameJam this weekend and my go ahead and test the JS waters with this as a guide.

I'd love to see a subsequent tutorial give an example of creating additional classes to use and how to instantiate them, but I might be able to figure that out from this.

Thank you again you're amazing.
User avatar
grillaface
Subscriber since Mar 31, 2014
Uber Haxx0r
 
Posts: 110
Joined: Tue Aug 02, 2011 1:59 pm
Location: Richmond, VA
Has thanked: 11 times
Been thanked: 11 times

Re: How To Make a Cross-Platform Game with Cocos2D Javascrip

Postby icanzilb » Wed Feb 27, 2013 11:50 am

The tutorial looks amazingly great :]

One thing I don't really understand though - in applicationDidFinishLaunching: you fetch two times the director :

var director = cc.Director.getInstance();

and then again:
director = cc.Director.getInstance();

is the second one referring to the global "director" var, and if so would it not be better to have different names for those?
But the directory is supposed to be a singleton right, so you don't need a local and a global variable ... I'm a bit confused about this one :)
User avatar
icanzilb
Team Member
iOS Tutorial Team Member
 
Posts: 372
Joined: Tue Jan 11, 2011 10:33 am
Has thanked: 12 times
Been thanked: 17 times

Re: How To Make a Cross-Platform Game with Cocos2D Javascrip

Postby dericeira » Wed Feb 27, 2013 12:37 pm

I have this error:


Code: Select all
var navex;
var MainLayer = cc.LayerColor.extend({
    _balas:[],
     ctor:function() {
        this._super();
         cc.associateWithNative( this, cc.LayerColor );
    },
    onEnter:function () {
        this._super();
    this.setMouseEnabled(true);
         var nave = cc.Sprite.create(s_nave);
         nave.setPosition(winSize.width/2, nave.getContentSize().height);   
         this.addChild(nave);
this.schedule(this.balago, 1);
    },

balago:function() {
console.log("bala");

var bala = cc.Sprite.create(s_bala);
bala.setPosition(navex, 30);
this.addChild(bala);

bala.runAction(cc.Sequence.create( // 2
        cc.MoveTo.create(1, cc.p(navex,500)),
        cc.CallFunc.create(function(node) {
            cc.ArrayRemoveObject(this._balas, node);
            node.removeFromParent();
        }, this)
    ));

bala.setTag(1);
this._balas.push(bala);
},

onMouseUp:function (event) {
    var location = event.getLocation();
    this.locationTapped(location);
},
 
onTouchesEnded:function (touches, event) {
    if (touches.length <= 0)
        return;
    var touch = touches[0];
    var location = touch.getLocation();
    this.locationTapped(location);
},

[b]locationTapped:function(location) {
nave.setPosition(0,0);
}[/b]






});


MainLayer.create = function () {
    var sg = new MainLayer();
    if (sg && sg.init(cc.c4b(255, 255, 255, 255))) {
        return sg;
    }
    return null;
};
 

MainLayer.scene = function () {
    var scene = cc.Scene.create();
    var layer = MainLayer.create();
    scene.addChild(layer);
    return scene;
};


How can I change the object "nave" position in the function locationTapped ?
dericeira
n00b
 
Posts: 1
Joined: Wed Feb 27, 2013 12:35 pm
Has thanked: 0 time
Been thanked: 0 time

Re: How To Make a Cross-Platform Game with Cocos2D Javascrip

Postby fabiobh » Wed Feb 27, 2013 4:47 pm

I download the project and try to run in Google Chrome, but the game was not running smooth, it has some lag.
fabiobh
Baby Hacker
 
Posts: 8
Joined: Fri Jul 13, 2012 5:26 pm
Has thanked: 0 time
Been thanked: 0 time

Re: How To Make a Cross-Platform Game with Cocos2D Javascrip

Postby NamSin » Thu Feb 28, 2013 4:34 am

You must be psychic. Started looking at js game engines / cross platform with cocos-2dx this week then found this. great tutorial. looking forward to part 2.
NamSin
n00b
 
Posts: 1
Joined: Thu Feb 28, 2013 4:28 am
Has thanked: 0 time
Been thanked: 0 time

Re: How To Make a Cross-Platform Game with Cocos2D Javascrip

Postby samuel » Thu Feb 28, 2013 9:19 am

This seems to be awesome !! Actually, I was looking for a cross-platform technology for my future game in a way to code once and distribute anywhere (including web) and cocos2d-javascript seems to fill the gap. Could you compare cocos2d-javascript with Corona?
Thanks a lot!
Sam
samuel
Baby Hacker
 
Posts: 9
Joined: Wed Jun 20, 2012 3:04 pm
Has thanked: 0 time
Been thanked: 0 time

Re: How To Make a Cross-Platform Game with Cocos2D Javascrip

Postby fabiobh » Mon Mar 04, 2013 6:15 pm

Hi Ray,
this tutorial is incredible, I can develop a web game now using my games develop with cocos2d.
Could you please extend this tutorial and cover the part about add different type of monsters?
This will help since it can introduce new concepts of cocos2d-html5
fabiobh
Baby Hacker
 
Posts: 8
Joined: Fri Jul 13, 2012 5:26 pm
Has thanked: 0 time
Been thanked: 0 time

Re: How To Make a Cross-Platform Game with Cocos2D Javascrip

Postby hamdanhashmi » Mon Mar 04, 2013 8:50 pm

great tutorial .... can u help me? some time enemy not detect in device (iphone) if delete game again load then work but work perfect in chrome
hamdanhashmi
n00b
 
Posts: 1
Joined: Mon Mar 04, 2013 8:46 pm
Has thanked: 0 time
Been thanked: 0 time

Re: How To Make a Cross-Platform Game with Cocos2D Javascrip

Postby macgeo » Thu Mar 14, 2013 3:38 am

Man, this is a timely tutorial!

Could use a little advice here on my own workflow. I've been using cocos2d-iphone for a while, love it, and now making jump to [fill in the blank] to go cross-platform. Just trying out some stuff this week, and have been working on a flow like described here: http://www.raywenderlich.com/23996/intr ... cosbuilder

In a nutshell here's what I'm doing-
1. Start in cocosbulider 3.0 as a javascript project. Rough in all the scenes.
2. Move over to xcode, create a cocos2d-x-javascript project from template. (v2.1rcA0) Add all the cocosbuilder stuff to the project.
3. Write classes and game logic there in xcode.
4. Wire back up with cocosbuilder
5. Test running in simulator and cocosplayer (which is really cool!)

So, a couple questions here because I'm not sure I'm in new territory here, and like you said, the documentation is a little scant and a lot of underlying things are changing rapidly:

1. Is it "better" to start in cocosbuilder or xcode, or does it matter?
2. Getting a ton of warnings in xcode on the javascript project, even on base template project. Assuming this is spidermonkey related but maybe not?
3. Interested if anyone is folding in levelhelper (also checking out codehelper) into this kind of workflow, and what I should look out for if I'm trying to do that.

Totally bonus question: I'm a novice at Git, but what I dream about sometimes is the ability to write a script that will run inside the IDE that goes out and pulls down most recent stable release of all these frameworks I'm now using and adds them to the project. Oh, and pulls in new art from dropbox :)
macgeo
n00b
 
Posts: 3
Joined: Thu Sep 01, 2011 1:24 pm
Has thanked: 1 time
Been thanked: 0 time

Next

Return to Official Tutorials

Who is online

Users browsing this forum: No registered users and 12 guests