开发者

Reposition a sprite in Android using Cocos

开发者 https://www.devze.com 2023-04-11 04:27 出处:网络
Context: I am using 2 sprites of 35x5 one on top of other. Problem: On some event i am rescaling the top sprite to 50 %. It gets rescaled but its dimensions remains same and it lies in centre of lowe

Context: I am using 2 sprites of 35x5 one on top of other.

Problem: On some event i am rescaling the top sprite to 50 %. It gets rescaled but its dimensions remains same and it lies in centre of lower sprite. Think of 2 bars. Top bar getting half and then setting in centre of bottom bar.

What i want: I want to set the starting position of top bar same to bottom bar. so that top bar resides at most left or most right.

What have i tried: On some event, i have called the below function but nothing happens except a fluctuation.

Bar.setPosition(SomeOtherSprite.getPosition().开发者_如何学JAVAx, SomeOtherSprite.getPosition().y+SomeOtherSprite.getContentSize().height/2 + Bar.getContentSize().height/2+2);

Just for the info, that i have started on Cocos2d for Android some 2 days before. Putting a question in effort to get most material regarding Cocos2D in Android on Internet as i was unable to find except : Tutorial for Cocos in Android


Anchor point is a point in a sprite local coordinate system (where (0, 0) is the bottom left corner and (1, 1) is top right). When you are setting sprite position, actually you are setting the position of the anchorPoint. Very convenient!

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号