On Wed, Sep 15, 2010 at 12:19 AM, Mike Wyatt <[email protected]>wrote:
> I have a layer, and I want sprites at position (0,0) to be rendered at > the center of the screen. However, this isn't happening. The sprite > is instead being rendered at the bottom-left corner. > > I figured setting the anchor would have an effect... > > class GameView( cocos.layer.Layer ): > def __init__(self, model ): > super(GameView, self).__init__() > > width, height = director.get_window_size() > self.anchor = width // 2, height // 2 > > ...but that didn't make any difference. What's the deal? > > Anchor is meaningless in current cocos (v0.4.0), a fossil of older versions. Currently, anchor reflects the member transform_anchor. In new code, use transform_anchor and not anchor. (Sorry, this should have been noted in changelog.) You can run this script to convince yourself: #--> anchor_is_transform_anchor.py import cocos from cocos.director import director director.init() print '\nAnchor is meaningless in current cocos (v0.4.0),' print 'a fossil of older versions.' print 'Currently, anchor reflects the member transform_anchor.' print 'In new code, use transform_anchor and not anchor.' print '\nSee:' node = cocos.cocosnode.CocosNode() print 'node.transform_anchor:', node.transform_anchor print 'node.anchor:', node.anchor print '\nWe do node.transform_anchor = 222, 222' node.transform_anchor = 222, 222 print 'node.transform_anchor:', node.transform_anchor print 'node.anchor:', node.anchor print '\nWe do node.anchor = 777, 777' node.anchor = 777, 777 print 'node.transform_anchor:', node.transform_anchor print 'node.anchor:', node.anchor #<-- anchor_is_transform_anchor.py And transform_anchor is used only for rotation and scale, see the attached script. To change the coordinates like you want, the most generic form would be Scene .... OffsetLayer , where you set offset_layer.position = width // 2, height // 2 ........GameView ............Sprites Depending on what exactly you want to do with the layer GameView, maybe you can spare the offset layer and simply change the position of game_view. -- claudio -- You received this message because you are subscribed to the Google Groups "cocos2d discuss" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/cocos-discuss?hl=en.
test_anchor_transform.py
Description: Binary data
