How to smoothly move a button in cocos2d Xcode

I have a jump button that jumps when I click on a player in the game. This button should be movable, how can I do it? I saw CCSprite moving images, but I don’t know how to do it with a button, and I don’t have the UIViewController class, the scene is pushed by CCDirector .

Also, how can you zoom in a bit and zoom out the scene to make it more attractive.

+4
source share
2 answers

If the button is made using CCMenu, you can use either the actions or the ccTouchesMoved method.

But if the button is made by UIButton, you can use ccTouchesMoved and reposition the UIButton based on where the user dragged a finger across the screen.

0
source

My recommendation would be to create a HUDLayer, so everything I write now will have this in mind.

HUDLayer will be CCLayer , which is on top of others, and is fixed on the screen. To be on top, you need to add it last or with the corresponding zOrder.

In this layer, you must map the ccTouchesBegan event and just work with users. For example, a character may jump when the user lands on the right side of the screen. To do this, just see if there is a CGRectContainsPoint(rightSideOfScreen, touchLocation) , and if so, take a character jump and show buttonSprite on touchLocation.

To hide the sprite, use ccTouchesEnded, so when the player releases the transition button, you can also hide the sprite.

0
source

Source: https://habr.com/ru/post/1500891/


All Articles