存档

2011年10月 的存档

Should I use cocos2D or andengine?

2011年10月31日 没有评论

What is the project the more active/Stable?
Can you say me the deep diference between cocos2D and andengine?

I’m using AndEngine for one of my projects, and I must say, it’s rather nice. A little comparision between LibGDX and AndEngine:

1) AndEngine

  • Only for Android.
  • High level, you propably won’t need any direct calls for GL functions.
  • Quite easy to learn, and to code with.
  • There are versions (source) for OpenGL ES 1.0 / 1.1 / 2.0 (with support for shaders)

2) LibGDX

The question is, do you need the LibGDX platform freedom, or maybe you are making project only for Android?

Also, look at that nice list of Android engines here.

I would definitly choose Andengine. Cocos2D for Android is yet too buggy.

AndEngine was specifically designed for coding-efficiency, libGDX gives you a little more freedom but requires a little more work. So LibGDX allows you to the low-level stuff easier, which is a little harder to do in AndEngine.

I think cocos2d-android is not an active project like cocos2d-iphone and cocos2d-x .
It haven’t been updated for quite a long time.

分类: cocos2d, stackoverflow精选 标签:

Frameworks/Libraries & Game engines — What's the difference

2011年10月20日 没有评论

I’ve seen plenty of game programming frameworks, libraries, and engines but there seems to be a difference I can’t put a finger on. It seems like frameworks are harder to work with than engines.

From what I understand (or think I understand) Frameworks are built using programming libraries, and game engines can be built using frameworks. I’m confused on the whole deal to be honest.

Is there some sort of heirarchy involved with these? There’s a game engine I seen in Java called LibGDX, which is built on top of the LWJGL and JOGL, and can be used to make android games because It uses Google’s Android framework as well, how is that possible?

I’ve also used the C# XNA framework, which can be used to make full blown games, and there are engines built on top of that, why would you need an engine on top of the XNA framework when you can build the game from the framework itself?

Also, I dont know much about Unity but it seems to be able to use three different languages as a game engine.

Library is just part that you use to build the final product. It usually is responsible for one particular thing like Math, Physics, Rendering, etc.

Framework is a bit bigger or can be just a synonym of Library. Framework can be all fundamentals necessary to build a game like Math, Physics, Rendering all together. For example XNA has fundamentals for Audio, Math, Graphics, Input, etc. With framework you have the basics but on low level usually you need to write a lot of code to make a game with a framework. In many cases you want to write a whole layer on top of the framework (it can be a whole Engine) in order to make a game with it.

Engine is much higher layer. With many of the game engines you don’t have to write a single line of code to make a game (it may not be very innovative game but it will be a game). Engines usually come with game editor and other tools that are not part of your final game and often are data driven. You can just run the game editor and make a level or modify the winning logic and therefore make a whole new game.

Going to start from the most basic based on what I understand.

A library is something extended into a program, a really common example would be a .dll file (Dynamic-link library) which extends functionality into the application it is being included in. I tend to think of libraries as being similar in many ways to classes because they are extending existing functionality into something that does not natively have that functionality (I am kind of inexperienced with libraries so please correct me if I am wrong). There is more to libraries then just this though so I will point you to wikipedia:

http://en.wikipedia.org/wiki/Programming_library

A framework is pretty simple to explain, it is basically a collection of libraries. When you are referencing an object in XNA (say you want to make a StringBuilder), then the framework you are using references System.Text (EDIT: Which is part of the mscorelib) to access the class StringBuilder. So in this example (as Aleks pointed out) it goes StringBuilder (class) Text (namespace) System (another namespace) which is part of mscorelib (or the .NET library according to MSDN).

Game Engines are sort of similar to frameworks but they are a little more focused and refined. In general I think a game engine includes things like resources, editors, built in functionality, and ect that you would not necessarily find in just XNA. I think one of the biggest draws (from my understanding) to using a game engine is the resources included. You don’t need to create your own textures, they may have some models, sounds, animations. It is a more complete set of tools for creating a video game as opposed to having to create all that stuff from scratch. Again I will point you to wikipedia for more:

http://en.wikipedia.org/wiki/Game_engine

分类: stackoverflow精选, unity3d 标签:

The method setPosition(CGPoint) in the type CCSprite is not applicable for the arguments (float, int)

2011年10月10日 没有评论

I am developing a basic game.And when i was developing a scence, i got this error message(The method setPosition(CGPoint) in the type CCSprite is not applicable for the arguments (float, int)).how can i fix this problem?

it is from the cocos2d, isn’t it? then you should modify this:

target.setPosition(CGPoint.ccp(winSize.width + (target.getContentSize().width / 2.0f) , actualY/ 1.0f));

i am using the setPosition(CGPoint) like this way you should try it..

deleteMenu.setPosition(CGPoint.ccp((hintSprite.getContentSize().width - 10), hintSprite.getContentSize().height + 10));
分类: cocos2d, stackoverflow精选 标签:

GLSL PointSprite for particle system

2011年10月10日 没有评论

I’m using an ParticleSystem with PointSprites (inspired by the Cocos2D Source). But I wonder how to rebuild the functionality for OpenGL ES 2.0

glEnable(GL_POINT_SPRITE_OES);
glEnableClientState(GL_POINT_SIZE_ARRAY_OES);
glPointSizePointerOES(GL_FLOAT,sizeof(PointSprite),(GLvoid*) (sizeof(GL_FLOAT)*2));
glDisableClientState(GL_POINT_SIZE_ARRAY_OES);
glDisable(GL_POINT_SPRITE_OES);

these generate BAD_ACCESS when using an OpenGL ES 2.0 context.
Should I simply go with 2 TRIANGLES per PointSprite? But thats probably not very efficent (overhead for extra vertexes).

EDIT:
So, my new problem with the suggested solution from:
http://gamedev.stackexchange.com/questions/11095/opengl-es-2-0-point-sprites-size/15528#15528

is a possibility to pass many different sizes in an batch call. I thought of using an Attribute instead of an Uniform, but then I would need to pass always an PointSize to my shaders – even if I’m not drawing GL_POINTS. So, maybe a second shader (a shader only for GL_POINTS)?! I’m not aware of the overhead for switching shaders every frame in the draw routine (because if the particle system is used, I want naturally also render regular GL_TRIANGLES without an pointSize)… Any ideas on this?

So doing the thing here as I already commented here is what you need: http://gamedev.stackexchange.com/questions/11095/opengl-es-2-0-point-sprites-size/15528#15528

And for which approach to go, I can either tell you to use different shaders for different types of drawables in your application or just another boolean uniform in your shader and enable and disable changing the gl_PointSize through your shader code. It’s usually up to you. What you need to keep in mind is changing the shader program is one of the most time costly operations so doing the drawing of same type of objects in a batch will be better in that case. I’m not really sure if using an if statement in your shader code will give a huge performance impact.

分类: stackoverflow精选, unity3d 标签:

Scrolling a Tiled Map in Cocos2D

2011年10月9日 没有评论

I’ve got an issue that I simply can’t figure out; probably because I don’t have the correct knowledge.

I have a TMX map made in Tiled. The Map is bigger than the screen size (tiles are 32x32pixels and there are 100×100 tiles).
What I want to do is to be able to move the map by swiping the screen.

I’ve looked at various tutorials online and examined the paddle.m example but still can’t get it to work.
All the tutorials I’ve come across all focus on moving a clamped centered sprite around a map…
Again, what I want to do is to be able to move the map by swiping/sliding the screen; much like when scrolling through your iPod or moving a picture around.

Can anyone help?

Here is my ccTouchMoved code

-(void) ccTouchMoved:(UITouch *)touch withEvent:(UIEvent *)event
{
    CGPoint touchPointMap = [touch locationInView: [touch view]];
    touchPointMap = [[CCDirector sharedDirector] convertToGL: touchPointMap];
    touchPointMap = [self convertToNodeSpace: touchPointMap];
    CCLOG(@"Touch Point Map %lf, %lf", touchPointMap.x, touchPointMap.y);

    self.position = CGPointMake(touchPointMap.x, touchPointMap.y);
}

To illustrate the problem I’m seeing on screen when I swipe the screen using the code above:
It seems that if I touch the center of the screen, the bottom left corner of the map will jump to that touched coordinate and will move with my touch until my touch is lifted.
The Map’s bottom left corner will always move to where I begin my touch.
Also while the map is being moved, it flashes like crazy and if moved excessively, disappears entirely.

Thanks again All, much appreciated.
Best and Kind Regards,
hiro

I found the solution to the problem.
There’s a very bright person in the Cocos2D community who has written a controller to not only pan around organically, but zoom in and out.

Link to Controller, example and preview movie

You wont need to write your touchBegan, Moved and End methods; this Controller does it all for you.

My init

self.theMap = [CCTMXTiledMap tiledMapWithTMXFile: @"city_map.tmx"];
        self.bgLayer = [theMap layerNamed:@"bg"];

        // boundingRect is the area you wish to pan around
        CGRect boundingRect = CGRectMake(0, 0, 32*50, 16*50);

        theMap.anchorPoint = ccp(0,0);
        [self addChild: theMap z: -1];

        // _controller is declared in the @interface as an object of CCPanZoomController
        _controller = [[CCPanZoomController controllerWithNode:self] retain];
        _controller.boundingRect = boundingRect;
        _controller.zoomOutLimit = _controller.optimalZoomOutLimit;
        _controller.zoomInLimit = 2.0f;

        [_controller enableWithTouchPriority:0 swallowsTouches:YES];
分类: stackoverflow精选, unity3d 标签:

Scrolling a Tiled Map in Cocos2D

2011年10月9日 没有评论

I’ve got an issue that I simply can’t figure out; probably because I don’t have the correct knowledge.

I have a TMX map made in Tiled. The Map is bigger than the screen size (tiles are 32x32pixels and there are 100×100 tiles).
What I want to do is to be able to move the map by swiping the screen.

I’ve looked at various tutorials online and examined the paddle.m example but still can’t get it to work.
All the tutorials I’ve come across all focus on moving a clamped centered sprite around a map…
Again, what I want to do is to be able to move the map by swiping/sliding the screen; much like when scrolling through your iPod or moving a picture around.

Can anyone help?

Here is my ccTouchMoved code

-(void) ccTouchMoved:(UITouch *)touch withEvent:(UIEvent *)event
{
    CGPoint touchPointMap = [touch locationInView: [touch view]];
    touchPointMap = [[CCDirector sharedDirector] convertToGL: touchPointMap];
    touchPointMap = [self convertToNodeSpace: touchPointMap];
    CCLOG(@"Touch Point Map %lf, %lf", touchPointMap.x, touchPointMap.y);

    self.position = CGPointMake(touchPointMap.x, touchPointMap.y);
}

To illustrate the problem I’m seeing on screen when I swipe the screen using the code above:
It seems that if I touch the center of the screen, the bottom left corner of the map will jump to that touched coordinate and will move with my touch until my touch is lifted.
The Map’s bottom left corner will always move to where I begin my touch.
Also while the map is being moved, it flashes like crazy and if moved excessively, disappears entirely.

Thanks again All, much appreciated.
Best and Kind Regards,
hiro

I found the solution to the problem.
There’s a very bright person in the Cocos2D community who has written a controller to not only pan around organically, but zoom in and out.

Link to Controller, example and preview movie

You wont need to write your touchBegan, Moved and End methods; this Controller does it all for you.

My init

self.theMap = [CCTMXTiledMap tiledMapWithTMXFile: @"city_map.tmx"];
        self.bgLayer = [theMap layerNamed:@"bg"];

        // boundingRect is the area you wish to pan around
        CGRect boundingRect = CGRectMake(0, 0, 32*50, 16*50);

        theMap.anchorPoint = ccp(0,0);
        [self addChild: theMap z: -1];

        // _controller is declared in the @interface as an object of CCPanZoomController
        _controller = [[CCPanZoomController controllerWithNode:self] retain];
        _controller.boundingRect = boundingRect;
        _controller.zoomOutLimit = _controller.optimalZoomOutLimit;
        _controller.zoomInLimit = 2.0f;

        [_controller enableWithTouchPriority:0 swallowsTouches:YES];
分类: stackoverflow精选, unity3d 标签:

How to start Unity application from android activity?

2011年10月7日 没有评论

I’m new in Unity and really don’t understand how to start unity application from android activity.
I need a widget that sometimes changes (for example, when sms received) and on click start unity application.There is no problem with widget and unity project separately. But I don’t know how to start unity from android project.

You can extend the main activity UnityPlayerActivity (controll the main loop for the Unity Player on Android)

public class MainActivity extends UnityPlayerActivity implements MyFunction {

    @Override
    protected void onCreate(Bundle savedInstanceState) {

    }

    @Override
    protected void onPause() {
        super.onPause();
    }

    @Override
    protected void onStop() {
        super.onStop();
    }

    @Override
    protected void onResume() {
        super.onResume();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }


}

Here is the document

分类: stackoverflow精选, unity3d 标签:

For collision detection only, is Chipmunk or Box2d the better tool?

2011年10月6日 没有评论

For a Cocos2d based project, I’d like to use a physics toolkit for collision detection only. What are the pros/cons of using Chipmunk or Box2d?

What kind of collisions are we talking about?

If all you need are these:

  • rect intersects rect -> CGRectIntersectsRect(..)
  • point in rect -> CGRectContainsPoint(..)
  • radius intersect (ie distance of two points) -> ccpDistance(..)

Then you don’t need a physics engine at all, and you don’t have to write your own collision detection algorithms either.

Chipmunk and Box2D handle collisions equally well. I’m of the opinion that if one is asking “which is better” it’s not going to matter for you. Instead, ask yourself whether you’re more comfortable working with C (Chipmunk) or C++ (Box2D).

Similarly, do you prefer working with an object-oriented, verbose API (Box2D) or a functional, highly abbreviated API (Chipmunk)?

Base your decision on what makes it easier for you to work with rather than some arbitrary, undefined, and highly subjective idea of whether one physics engine might be better than the other, because the technical differences are marginal and you can only assess their influence on your game’s design if you both know your own game design and the physics engines internal algorithms really well.

According to this answer Chipmunk does not support Continuous Collision Detection, but Box2D does. This is important to prevent “tunneling” (objects passing slightly through eachother when moving at high speeds)

This is clarified by Steffen Itterheim’s comment on his Box2D vs Chipmunk FAQ: If you are going to have very fast moving physics objects, eg “Bullets”, consider using Box2D as it can do swept collisions aka continuous collision integration to prevent fast-moving objects from deeply penetrating or even tunneling through other objects.

The Chipmunk Collision Detection docs talk about a separate() callback. Two shapes have just stopped touching for the first time this step. but it was unclear to me if this has any implications of their ability to detect collisions at speed.

There is also a very negative opinion on using Box2D for a breakout game My current game is using Box2D, and I wish I used Chipmunk with it… Mostly because Box2D has two serious issues, that are exacerbated on my game: First, it has a REALLY OLD bug where objects “snag” on corners, my game is a breakout game, so when the ball is “rolling” along a wall, sometimes it snag and is flung away from the wall, lots of people asked why my game physics looks “random”.

Conclusion: I’m confused too.

分类: stackoverflow精选, unity3d 标签: