# This code is so you can run the samples without installing the package
import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
#


import cocos
from cocos.director import director
from cocos.sprite import Sprite
import pyglet


## the following is in case we want to get the images
## from other directories:
# pyglet.resource.path.append("/data/other/directory")
# pyglet.resource.reindex()

import cocos.actions as ac

class TestLayer(cocos.layer.ColorLayer):
    def __init__(self):
        super( TestLayer, self ).__init__(255,0,0,255)

        self.transform_anchor = 0,0

    def on_enter(self):
        print 'layer transform_anchor:', self.transform_anchor
        super(TestLayer, self).on_enter()
        self.do(ac.Repeat(ac.Rotate(360, 1.0)))
        self.do(ac.Delay(3)+ac.CallFunc(self.change_anchor_transform))

    def change_anchor_transform(self):
        print 'in change_anchor_transform'
        w,h = director.get_window_size()
        self.transform_anchor = w // 2, h // 2
        print 'layer transform_anchor:', self.transform_anchor

                       
        
if __name__ == "__main__":
    print 'We set the tranform anchor to (0,0) in layer __init__,'
    print 'and begin to rotate at 1 turn per second'
    print 'After 3 seconds, we change the transform_anchor to'
    print 'width/2, height/2'
    print 'The only change to be seen is a change in the center of rotation'
    director.init()
    test_layer = TestLayer ()
    test_layer.position = 100,100
    main_scene = cocos.scene.Scene (test_layer)
    director.run (main_scene)

