Hot answers tagged

6

Do it via events. Spell begin is an event. Start playing the sound for that event. Enemy getting hit by spell is also an event. If the enemy is further away and you Throw a dart, for example, you only play the second sound (dart hitting) once the dart reaches the target (if you consider Throw as a spell). If you need to tie it to a frame (so for example,...


6

You don't speed up the engine, you speed up your units and their actions. For example, when you update an enemy, you usually do something like enemyDirection * enemySpeed * timePassed to get their new position. Now, if you want to double or halve the speed of gameplay, you just add this in as a factor: enemyDirection * enemySpeed * timePassed * ...


4

It's quite simple actually: cocos2d javascript is the join up of cocos2d-x's JSB and cocos2d html5. It's just a name given to that mix up. JSB is a set of Javascript native function overwrites that, when interpreted by the necessary scripts, are converted to their native correspondents. And these native functions are interpreted by the compiler, resulting ...


4

There are a number of things to ask, but if you understand the basics you should be able to not just determine the speed your sprite is moving but dictate it. Unless you are overtaxing the processor, or you schedule a routine to "update" less often, the game "loop" is going to execute 60 times per second. Assuming the routine that moves your sprite is ...


3

I agree with Engineer's answer, where the main point is "don't fight the framework". Games are different However, another point I want to add is that when it comes to software, games are different. Even though the article is a bit outdated by now, I want to quote a part from Joel's five worlds of software programming: Here’s an important thing to know. ...


3

No, if you are referring to writing Objective-C using the Cocos2D framework to do animations, your animator will not be able to do so without xCode. He could write the code in a text file and pass that to you, but will not be able to compile them to check that they do work (which really defeats the purpose I suppose.) However, if you only need sprite ...


3

Number 3 is easiest if you have an image that is tileable, meaning that if you put them next to each other you wouldn't be able to pick out the seam. Then you can draw the same image twice once on x,y and once on x+image.width,y. each frame you decrement x until x < -image.width where you add image.width to it. Adding details is easy by drawing some ...


3

I'm not finding any way to do this within the cocos2d framework, so if someone can do that it would probably be a better answer. However, cc.Texture2D does have a getHtmlElementObj() function. Now, this function can return either an image element or a canvas element. If it returns an image, you need to make a canvas from it as shown in this answer: var ...


3

Use this code (cocos2dx v3.x): node->runAction( Sequence::create( Spawn::create(A, B, nullptr), C, nullptr)); This is what happen: A and B start simultaneously After the longer one finished, C start. Important: Remember that you should use finite action when using Sequence. for ...


2

To do this, all that you need to write is something like this, a simple swap function: class Point { private int x, y; procedure swapPositions(Point a) { Point temp = a; a.x = x; x = temp.x; a.y = y; y = temp.y; } } Note: this is pseudo-code and it will not work if you try to use it. You must write your own, with this concept, and fit ...


2

It renders using bump- / specular maps. Refer to this video. The ground geometry is never modified. Bumpmaps are just heightmaps used for realistic lighting. To clarify definitions, bumpmapping is a rendering technique, typically written as a shader, which creates the illusion of surface detail on what is in fact a flat piece of geometry... in this case, ...


2

I would recommend you to have just one, unshaded grass texture and create the bright and dark stripes procedurally by making the texture brighter or darker.


2

I ended up altering the contentSize of the CCTableView. So, someTableView.contentSize = CGSizeMake(200, 300); ...and then I placed a CCSprite over it with a hole in the middle that had transparency. This way, the table view was clipped how I wanted it clipped. I added the tableView to my scene with a lower z-order than that of the sprite. Did not need ...


2

It's not the label that understand the text direction, but the OS. as you guessed Android check the first letter to guess how it should format the text, whether it's RTL or LTR. Label::createWithSystemFont basically asks the OS to render the text for you. It's completely out of cocos2dx's control how the text is rendered, And thus it's completely OS ...


2

Regarding the info found here, currently there is no official way to achieve this but they are working on it. Meanwhile you can download the "standalone template" found in the same link.


2

There is noise introduced in your texture due to compression which causes some of the pixels to not be perfectly black. You need to add an error threshold to your comparison, fastest way is to use a distance comparison by considering the RGB color as a 3D vector and use a dot-product to calculate the squared length. This reduces the multiple comparisons ...


1

Yes, cocos2d-x has a built in way to do this. If you want to pause everything the character is doing you can simply use: _character->pause(); _character->resume(); _scheduler->pauseTarget(_character); _scheduler->resumeTarget(_character); NOTE: this also pauses any actions being performed on the character. If you want to continue ...


1

You could try this: [yourSprite pauseSchedulerAndActions] and to resume [yourSprite resumeSchedulerAndActions] Source: SO thread If that shouldn't work, another option might be: //pause [sprite.actionManager pauseTarget:sprite]; //resume [sprite.actionManager resumeTarget:sprite];


1

The way i do it is make custom event listeners for my animation class and have them control my sound. so if my animation has started callback.start(); and start my sound in that method. if my animation was paused do callback.pause(); and pause the sound. when the animation has ended you callback.end(); and have the sound end as well. but for perfect ...


1

You can use SpriteKit or Kobold Kit and then use Apportable to convert it to Android. http://www.apportable.com/ But if you want truly cross compatible you could use Unity3d free version and build out to the specific platform you want since iOS and Android are given. (They now have 2D Sprite abilities) It costs a pretty penny if you want the Pro features ...


1

You have to do two things here: Create a repeating sprite Mask it with the shape For the repeating sprite you will need a texture that has POT (Power Of Two) sides, e.g. 256x256. When you load your tiled texture you need to set its parameters to repeat: CCSprite* sprite = [CCSprite spriteWithFile:@"tiled_tex.png"]; ccTexParams params; params.minFilter = ...


1

Well, one way is to load the textures and keep a reference to them ourself. You could reimplement your code to something like: @interface TextureHelper : NSObject - (void) preloadTextures; - (CCTexture2D *) textureForImageNamed:(NSString *) imageName; @end @implementation TextureHelper { NSArray * loadedTextures; } - (CCTexture *) textureForImageNamed:...


1

That error occurs on this line: CCTexture *texture = [CCTexture textureWithFile:image]; And this is the right way to do this: CCTexture *texture = [[CCTexture alloc] initWithCGImage:image.CGImage contentScale:image.scale];


1

As far as I know, whenever you make a sprite using any spritesheet, that spritesheet will be loaded automatically. So you don't have to load anything.


1

One solution would be to get the normal vector between the objects and look at its x and z components. Diagonal objects will have an identical x and z length (assuming the objects are arranged on the X/Z plane, otherwise you'd have to swap components accordingly). In code: // MyObjects is an array or list of your corner GameObjects (1-8) // K is your ...


1

If (distance between 4 & K) == (distance between K & 3) == (distance between 2 & K) Then it's a circle, therefore there's no diagonal :) If there was a diagonal the distance between the diagonal would be sqrt(2) times bigger than the distance between the adjacent. Pick one of the objects that is not K, and order the others by distance (ignore K)...


1

I am not seeing where you are positioning the particle system, only that you are adding it to "self". I assume you want the particle system to be more or less at the same position as the star sprite. Assuming "self" is a layer, you need to position the particle system using the position of the star sprite, and offset the position where needed. ...


1

It looks like it is probably based on curves - like maybe piecewise Bezier curves, or maybe B-splines. Internally in the code they could also be using hermite splines, catmul-rom splines or some other variant but without seeing the code its nearly impossible to tell what specific curve is being used since many of the above are visually equivalent, but are ...


1

Basic sprite animation is really simple: int frame_to_play = (game_tick * target_fps / tick_rate) % number_of_frames; The result will tell you which frame (the frame_to_play-th) to show. game_tick would be some kind of frame counter that just counts up (has to tick at least as fast as your animation is meant to be played). target_fps is the framerate at ...


Only top voted, non community-wiki answers of a minimum length are eligible