0
votes

I am making a game in Cocos2D Version 3.1 using spriteBuilder. I am creating my animation by add the list of frames into an array and storing it in the cache. When I need to run the animation, I get it from the cache and play it on the screen. This works great for my running animation. I have another animation in which my character is sliding. When I play my sliding animation after my running animation, my character appears to be sliding in mid-air, not intersecting the ground. The reason for this is probably because the frames are loaded immeadately after the running animation, so they are loaded in the same place as the running animation. Since the frames of the sliding animation are smaller than the running animation, it makes it seem like the player is floating.

I would like to know if there is any way I can make the frames load a bit lower, so that they are touching the ground. Is the only way to do this to push the position of the hero down when the slide animation is loaded, and then back up when I want to load the run animation?

Thanks

1
tip: always use the same frame size for a set of animations. The extra transparent space will be cut off if you create spritesheets. - LearnCocos2D
@LearnCocos2D I'm not sure I completely understand what you mean. When I create my graphics in Illustrator, I export them as a PNG with a transparent background. Is this wrong of me to do this? - user2852657
no but your exported png files should all have the same dimensions to avoid that problem you are having - while you can fix this in code that fix would be brittle and correctly applied and removed depending on what frame the sprite is currently displaying. You don't want to go there. - LearnCocos2D
I am also creating sensors for my character using CGRectMake. My bounding boxes are proportional to the size of the character, for example the x position is self.boundingbox.origin.x and the height is self.boundingbox.size.height. Wouldn't having all png files having the same dimensions affect the sensors? - user2852657
Yeah, I tried this. Each frame for my characters animation is about 100 pixels by 100 pixels. So, I created a 200 by 200 pixel document in illustrator and exported the png files so that each was now 200 by 200 pixels. Hence, the size was the same. Apparently, spritebuilder smart spritesheets did not cut off the extra transparent space, because my character's sensors are off. The game thinks the character has run into a wall, when he really hasn't. Can you tell me how to fix this? - user2852657

1 Answers

0
votes

Are you using (or will be using) gravity in your game? If no force is pushing the sprite down you could push the position of the sprite down everytime you load the animation, or just use the same frame size for all animations.

EDIT: You seem to know where the bottom of the frame should be. On the ground? So if you want the bottom of a sprite to be in the same place when you load animation, set the position like:

sprite.position = ccp(x, theBottomY + sprite.boundingBox.size.height/2);