EzDevInfo.com

cocos2d-html5

cocos2d for Web Browsers. Built using JavaScript

cc.Class.extend not respecting functions

When ever I run the code below in Cocos 2D HTML or with bindings it seems to not add any of my functions but will add my Variables.

So:

cc.Class.extend({
   init: function(isDancing){
   this.dancing = isDancing;
},
   age : 5,
   dance: function(){
       return this.dancing;
   }
});

becomes :

 function anonymous() {
   this._super=null;this.age=this.age;
 }

Which I will get a undefined error when I try to call, dance().


Source: (StackOverflow)

Remove no longer used sprites from memory in Cocos2d-html5

Because I'm developing on mobile devices, I wanna to remove no longer used objects (sprites) from memory. Should be detachChild be enough to have it out of memory ? What about the src references. How to remove/detach them from the dom ?


Source: (StackOverflow)

Advertisements

Cocos2d-html5-WebGL: Documentation required to learn and develop Cocos2d-html5-WebGL programming

I am trying to use Cocos2d-html5 framework (v 2.1.x) with WebGL programming concepts to develop 3d application. I am able to see documentation only for Cocos2d-html5 programming, and not finding any tutorials, API documentation and samples to do it further on WebGL programming concepts. I am searching it for a week, but still couldn't find anything. I need to start development as soon as possible on cocos2d-webgl, so could someone please guide me to get documentation, sample and API's.

Thank you.


Source: (StackOverflow)

Getting started with Cocos2d-html5

I know this can't be considered as a question. But this is for the developers those want to start development in cocos2d-html5. Is there basic tutorial for this framework with good explanation. And i want to know that can we build facebook games using this framework (cocos2d-html5).?


Source: (StackOverflow)

Can a website be made in cocos2d-html?

I have been working with cocos2d-iPhone, cocos2d-x, and cocos2d-html5 for quite some time. I wanted to ask if it is okay to build a website with cocos2d-html5. I want to do it because I want the website look interactive, animated, and scroll around like a game. We can do this with javascript, but is it possible to write it in cocos3d-html5? What are the drawbacks of doing this? And is there any existing website that is built on cocos2d? Thank you for the help.


Source: (StackOverflow)

Suitable library for combining with D3js , to allowing drawing to webgl (2D)

Here is what i am trying to do : http://mbostock.github.com/d3/talk/20111116/iris-splom.html

But i want to do that in webgl 2d (because SVG performance is very slow, randering 10k SVG only already drops to 12 fps)

On a quick search i found several webgl-2d libs : cocos2d-html5 , pixijs,Three.js and webgl-2d(abandoned?)

They seems to be pretty easy but what i want to do is data visualization.cocos and pixijs are 2d game libraries. I am new to webgl and those libraries so experts at SO can you guys recommend ?

summary of things i need:

Interaction :

  • Rectangular selection inside plots. Click to select on Some elements.
  • Zoom and Pan Support (Semitic Zooming if possible)

Renderer : WebGL2d (according to benchmarks webgl is fastest)


Source: (StackOverflow)

Same code for Cocos2Dx and Cocos2d-html5?

Here I see the following:

.... the team of Cocos2d-x are working on something called "Javascript binding for Cocos2d". What that means is your very same code running on Cocos2d-html5 engine can work flawlessly on Cocos2d-X and Cocos2d-iPhone without or with little modification. And all that translates to "almost native fast on mobile phones".

What I can not understnad is that how the code written in one language can be translated to another one? Do they mean that there is a tool that gets as an input JavaScript code of Cocos2d-html5 game and translate it to C++ Cocos2dx code or backwards?

EIDT: Can I port easily the C++ game written with Cocos2Dx into Cocos2D-html5? What I have to do for that?


Source: (StackOverflow)

Cocos2d-js EditBox zOrder not working

I have an EditBox on my layer.

var ebox = new cc.EditBox(cc.p(200, 30));
ebox.setPosition(size.width / 2 - 50, size.height / 2);
ebox.setPlaceHolder("Password");
ebox.setInputFlag(cc.EDITBOX_INPUT_FLAG_PASSWORD);
ebox.setDelegate(this);
ebox.setFontColor({"r": 0, "g": 0, "b": 0});
ebox.setFontSize(20);
ebox.initWithBackgroundColor(cc.size(200, 30), {"r": 0, "g": 255, "b": 0});
ebox.init();

this.addChild(ebox, 1); //this - is a main layer

then I have to display some kind of overlay over the main layer

this.getParent().addChild(overlayLayer, 100);

overlayLayer - layer filled with color

The thing is that editbox stays always above the overlay. Why isn't zOrder working with EditBox??


Source: (StackOverflow)

object is not a function in menuitem

I'm getting this error message from Chrome Console, when I push a Menu item that tries to change the scene:

Uncaught TypeError: object is not a function CCMenuItem.js:174
cc.MenuItem.cc.Node.extend.activate CCMenuItem.js:174
cc.MenuItemLabel.cc.MenuItem.extend.activate CCMenuItem.js:333
(anonymous function) CCClass.js:138
cc.Menu.cc.Layer.extend.onTouchEnded CCMenu.js:442
cc.TouchDispatcher.cc.Class.extend.touches CCTouchDispatcher.js:376
cc.TouchDispatcher.cc.Class.extend.touchesEnded CCTouchDispatcher.js:508
cc.ProcessMouseupEvent CCTouchDispatcher.js:630
(anonymous function)

this is my code from the menu:

var menuItem1 = new cc.MenuItemFont.create("Play",this,this.onPlay);
var size = cc.Director.getInstance().getWinSize();
menuItem1.setPosition(new cc.Point(size.width/2,size.height/2+50));

var menu = cc.Menu.create(menuItem1);

menu.setPosition(new cc.Point(0,0));

this.addChild(menu);

And the function of menuitem1:

onPlay:function(){
    //cc.log("==onplay clicked");
    //var director = cc.Director.getInstance();
    //director.replaceScene(new MainLayer());
}

Source: (StackOverflow)

cannot get cc.point and delay to work together

OK think Space Invaders and Galaga. I have an enemy squadron at the top of the screen. They move left and right and down the screen as a group. Every now and then an enemy fighter leaves the group and attack's the player's ship. does a few bezier curves, attempts to attack the player's ship. If the enemy fighter misses he (1) fly off the bottom of the screen, hides, moves to the top of the screen, appears and flys back into its position in the squadron. The problem is the enemy fighter flys back into the position where it left the squadron not where its current position should be.

  1. set variable new_pos
  2. call action function with delay to handle the bezier flight paths e.g.

action ((bezier), (delay 5 seconds), (hide enemy fighter), (delay 1 second), (move enemy fighter to top of screen), (display enemy fighter), (callfunc to get the enemy fighter's new position in the squadron), (bezier back to new position)

CallFunc seems to get called as soon as the parent function is called. Not after the delay. Is what I am expecting possible?

var epos = 0;

if (enemy_fly_out_from == 0)
    this.runAction(cc.Sequence.create(cc.DelayTime.create(enemy_fly_out_duration), cc.CallFunc.create(this.reduce_flied_out, this), cc.MoveTo.create(1, cc.p(ship_pos.x-25, -25)), cc.Hide.create(), cc.MoveTo.create(0, cc.p(ship_pos.x-25, 610)), cc.Show.create(), cc.CallFunc.create(this.get_enemy_pos(which_enemy), this), cc.BezierTo.create(5, [cc.p(ship_pos.x-25, 600), cc.p(pos.x, 600), cc.p(epos.x,epos.y)]), cc.CallFunc.create(this.end_fly_out(which_enemy), this)));   

else
    this.runAction(cc.Sequence.create(cc.DelayTime.create(enemy_fly_out_duration), cc.CallFunc.create(this.reduce_flied_out, this), cc.MoveTo.create(1, cc.p(ship_pos.x+25, -25)), cc.Hide.create(), cc.MoveTo.create(0, cc.p(ship_pos.x+25, 610)), cc.Show.create(), cc.CallFunc.create(this.get_enemy_pos(which_enemy), this), cc.BezierTo.create(5, [cc.p(ship_pos.x+25, 600), cc.p(pos.x-100, 600), cc.p(epos.x, epos.y)]), cc.CallFunc.create(this.end_fly_out(which_enemy), this)));
},
end_fly_out:function(which_enemy)
{
     enemies_array[which_enemy].flied_out = 0;
},
    get_enemy_pos:function(which_enemy)
{
    epos = enemies_array[which_enemy].getPosition();
},
reduce_flied_out:function()
{
    enemies_flied_out = 0;
}

Source: (StackOverflow)

html5 game engine, cocos2d vs construct2

Just a beginners question, I am looking into html5 game engine for mobile devices, possible integration with Phonegap. mainly targeting iphone5 and iOS 7, I see that cocos2d is 2d only, but the question is construct2 vs cocos2d-html. if only consider 2d which is better, performances, learning curves etc.


Source: (StackOverflow)

Cocos2d-html5 - Restarting/quitting engine possible?

With Cocos2d-html5, is there any way to “quit” the engine and re-initialize its state so you can later restart the engine. We are using a Cocos2d game in a single page web app. If the user navigates to another page, we want to programmatically remove the canvas div and attempt to exit the Cocos2d engine. Unfortunately, it seems there’s no good way to do this and attempting to load a new game causes errors.

How can you cleanly unload a scene and quit the engine?

We are using V3.1 and tried several approaches, none of them seem to work. For example:

  1. Trying to reset many variables that are held in the cc object (detailed below). This approach forces you to reset variables that look private as they start with _ and are not in the documentation.
  2. picking, choosing and rewriting some of CCBoot.js but this appeared complicated and not sustainable for engine updates as so much of it is depended upon throughout the library.

Other approaches I thought of but all sound like a hack:
3. Null the whole cc object and somehow run the script again but that might mean stripping out a script tag or module and adding and running it again.
4. Wrap the cc object in another object so it is easier to reset. CCBoot.js looks like it might attach some things to the window object.

I have got furthest with the first approach but am stuck with context issues. When leaving the canvas, before I remove it from the DOM I call these:

// Remove anything that might possibly keep a reference to the old context
cc.textureCache.removeAllTextures();
cc._drawingUtil = null;
cc.stencilBits = null;

// Purge the cc.director, schedules, event listeners, running scene, animations, cached data.
cc.director.purgeDirector();

// Remove references to the context
cc._renderContext = null;
cc.webglContext = null;
window.gl = null;
cc._mainRenderContextBackup = null;

// Remove reference to DOM elements
cc._canvas = null;
cc.container = null;
cc._gameDiv = null;

// Reset CCBoot variables that might stop us from re-initialising
cc._rendererInitialized = false;
cc._setupCalled = false;
cc._renderType = -1;

Then when we restart on the second or subsequent time call

// Reset all system and flag variables
cc._initSys(cc.game.config, cc.game.CONFIG_KEY);

cc.game.run();

And here are the kind of errors I get. It looks like it's not properly resetting the context:

WebGL: INVALID_OPERATION: bindTexture: object not from this context
WebGL: INVALID_OPERATION: texImage2D: no texture
WebGL: INVALID_OPERATION: uniformMatrix4fv: location is not from current program
WebGL: INVALID_OPERATION: vertexAttribPointer: no bound ARRAY_BUFFER

Source: (StackOverflow)

Cocos2d-x HTML5 with Angular JS in Single page application

I've got a Cocos2d-x html5 game developed, and it works fine.

However I'm in the process of porting my front-end to SPA using angularjs. Therefore, there are no redirects, as pages are loaded dynamically.

There is a problem with loading engine sources, as once it is loaded, and user goes to game for the second time, it cannot be launched again.

It results in error: Cannot redefine property: POINT_ZERO

To avoid this, when loading game second time I ommit engine sources and load only game related resources.

But this line, initializing game: cc.setup(this.config['tag']);

results in error: WebGL: INVALID_OPERATION: uniformMatrix4fv: location is not from current program

Can I somehow remove all cocos scripts to be able to load it again?

Or perform a silent reload without redirection, so that the whole page is not refreshed?


Source: (StackOverflow)

Open a website in new window and detect that redirect to another url

In iOS, android I can show a webview and when it redirect to an url, I can detect it.

(like login via facebook, google ..vv..)

I want to do the same thing with cocos2d-html5 or cocos2d-js. (for web-browser)

I just try below code but nothing happened

window.open('http://webdesign.about.com/',
            'open_window',
            'menubar, toolbar, location, directories, status, scrollbars, resizable, dependent, width=640, height=480, left=0, top=0');

How can I tell web-browser open new tab for me?

====== UPDATE ======

My browser stopped all popups. my bad.

But I don't how to observe a Window object in javascript to know when it goes to new url.

I saw all thing about window at http://www.w3schools.com/jsref/obj_window.asp but I don't see something like that :(


Source: (StackOverflow)

Does Cocos2d-js use a webview?

I need to know if the cocos2d-js (cocos2d javascript) could build a real native application and not just use a webview to display the content.

what i exactly need to know, if the animations and all parts of the game logic will be transformed to some native code using JSB.

i searched online, and wasn't able to find any clear answer, and the official cocos2D-js documentation is really poor and don't give much details.

Sorry, it is my first question here, hope that i followed the rules, and sorry for my English.


Source: (StackOverflow)