On Sun, Jul 28, 2013 at 6:37 AM, Brandon Jumbeck <[email protected]>wrote:
[...]
My main problem is how to structure the game and if I am understanding
> everything right. In Pyglet I basically went down the normal route of
> creating a main window for the game and then having different states (Menu,
> Playing, Dead, Whatever) to control the flow of the game. But in cocos I am
> struggling to get a hold on the scene/layer things.
>
> From what I understand is a scene represents the current global state of
> the game like Menu, Level 1, Level 2, ect.
>
>From a practical standpoint I think the graph and text in
http://cocos2d.org/doc/programming_guide/scenes.html
gives an intuitive approach as to how to break the game in scenes.
If you want some more formal:
A scene instance represents a specialized view of the app state plus some
behavior appropriate to that view. Classical examples are MainMenuScene,
PlayLevelScene, CreditsScene
At each time there is only one active scene, and the active scene is
responsabile for the full window view and behavior.
> and each scene is made up of layers (Background layer, Game Objects
> layer, HUD layer, ect). I would then add my game objects to their
> respective layers (My subclassed cocos.sprite.Sprite objects in the
> GameObjects layer, my labels in another layer, I might even create a
> different layer for enemies, ect). and then add them layers to their
> respective scenes.
>
Is this how it is usually done? If it isn't please feel free to correct
> anything :).
>
>
That is not a bad organization. Personally I tend to do
scene
world_layer
background or terrain layer
actors (which can be splited in a number of layers for convenience)
controller_layer (receives user input)
HUD
> I'm also having trouble understanding how to control the game objects and
> what does the controlling. For example I thought I would build a simple
> vertical space shooter to get familiar with cocos. For the enemy movement's
> would the scene be in charge of pathing the enemies around and managing
> them all or would that fall to the certain layer, or even the sprite class
> itself?
>
>
In general you want to put the control in the smaller entity than can
handle the job.
Supposing the only actors are spaceships and bullets, and theres no real
coordination between the enemies, the enemies control could go to each ship.
The simpler behavior, used in many arcade games, is to periodically release
enemies, each in a fixed trajectory, maybe firing a bullet at scripted
intervals and checking for collisions of player with bullets and spaceships.
To do this in cocos you can put a method in the world_layer that checks if
it is time to spawn a new enemy, and do it if affirmative. By scheduling
that method, it will be called periodically.
Spawn an enemy should be easy :
enemy = cocos.sprite.Sprite('my_image')
enemy.do( (MyWavyMoveAction(<enemy mov params>) |
BulletTriggerAction(bullet_image, interval, ...) ) +
RemoveFromWorld( ) )
> This all might be because I am still fairly new with game development in
> general so sorry if these seem like stupid questions. It also tends to help
> me if I bounce ideas off others to help get a grounding.
>
>
> Anyways if anyone can maybe explain the structure a bit more or even share
> a project example that would be great. And thank you all in advance for
> taking the time to read this and help me :).
>
>
A minimal game included in the cocos download is balldrive, which can be
found at samples\balldrive_toy_game
Theres also samples\tetrico but this is more heavy to follow.
Others ones of the top of my head are:
http://www.usebox.net/jjm/for-science/
http://www.pyweek.org/e/petraszd-pw-12/
--
You received this message because you are subscribed to the Google Groups
"cocos2d discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/cocos-discuss.
For more options, visit https://groups.google.com/groups/opt_out.