[Newbie]How cocos2d-x does work?

Hi everyone!
I know it’s a stupid question but i don’t get it.

I 've learned some cocos2d-x basic, such as Director, Scene, Layer, Sprite classes and AppDelegate, HelloWorld classes.
These classes define their methods that i can understand, but not well.

The major problem:
I have never seen any call of these methods?? In the main entry point of program, it simply declare a AppDelegate object and run a run() function. Did i misunderstand something?

It 's said that a 2D game is simply think as some Sprite and a loop. But i don’t see any instance of Sprites, just define of them. And there is no loop.

Thank you very much.
Sorry for my bad English.

have you created the sample HelloWorld program?

have you run through cpp-tests to see what they are doing?

Hello,

The basis of most if not all game engine is one infinite loop, which calls 2 methods: update (which updates the logic of the game) and draw (which draw the current state of the game on screen).

Cocos2d-x takes care of all the drawing (unless you want to overload it of course, you can), and most of the updates (especially if you uses Actions).

Somewhere you should have something like Director::runWithScene(HelloScene) (or something close, I don’t remember the specifics). That’s the main entry point: from there, Director is going to take care of everything, you just need to construct your hierarchy of Scene, Layer, Sprites and other objects, and let cocos2d-x take care of all the low-level stuff.

If you want to have a custom update or draw, you need to suscribe to those methods. You don’t make the loops yourself.

Do you have more specific questions ?

2 Likes

i have run cpp-tests program.
Do you mean debug it and step over every statement?

Thank a lot for useful information .

I asked because you said you don’t see any instance of a Sprite or a loop. There are Sprites in the HelloWorld and cpp-test apps for sure. The loop is implemented in Director and I’m sure you have seen this.

1 Like

okay @fethut1 not a stupid question at all.
even i would say… it is a very good question and nicely explained by @Fradow

even @Fradow would have asked himself at some point of time that really how stuffs work
and this info is worth useful.

so thanks for asking the questions it help others also it shows your curosity in cocos2d-x and a possible sign for a good developer.
appreciate that. :smile:

Happy Coding

yes i would request you to make a document somewhat rough or clean
to deliver some ideas about cocos2d-x which are not known to the newbie

and they couldn’t find it anywhere… more like courses :smile:

i would appreciate if you could do that for us by sparing some of your time for the fellow developers. :smile:

you could pm me or just post here…
as you may like… :smile:

@pabitrapadhy Do you have a specific idea of where I should post that ? I don’t have a website nor plan opening and maintaining one.

I may find some time to do that, but currently I’m a bit busy open-sourcing my framework (cf Open-sourcing my framework : any interest?)

Thank you all !!!
it was mistaken as i said didn’t see any instance of Sprite. I mean a Sprite object can’t call its methods itself.

In console app, i have to call object’s method myself in main().

Thank to @Fradow, i studied there is a update() method that handle touch events, and cocos2d-x calls it for us. And the loop is executed by Scheduler.

yes @Fradow i can tell that.

well if you could help with the document then make it simple and descriptive
something like you’ve described about the update and draw in this post.
stuffs like that, which a developer should know but they are not aware of.

If you could make a draft, you could post it here as tutorials on the forums
also, if you want to spread it to all the video lovers, we could talk with Sonar Systems
they make video tutorials on YouTube
also you could send me the draft, i am also planning to make some video tutorials related to cocos2d-x
about common error faced by developers when they get into the framework
so, i could make a video tutorial based on the draft :smile:

I believe in spreading knowledge and helping other.
so, if you could spare some time on the draft it would be great for all.

What do you say… !! :slight_smile: