当前位置:编程学习 > wap >>

Cocos2d-精灵的几个常识

性能考虑
该部分是总结的cocos2d的在线文档
1)如果有每个帧有25个以下的精灵需要更新,可以直接使用精灵
[python]
class TLayer(cocos.layer.Layer): 
    is_event_handler = True 
    def __init__(self): 
        cocos.layer.Layer.__init__(self) 
        world_width, world_height = director.get_window_size() 
        rand_color = [255, 0, 0] 
        icolor = 0 
        for i in range(qty_balls): 
            ball = Ball((world_width*random.random(), 
                         world_height*random.random()), 
                        color=rand_color 
                        ) 
            rand_color[icolor] = random.randint(50, 255) 
            icolor = (icolor + 1)%len(rand_color) 
            self.add(ball) 
self.time = 0.0 
self.schedule(self.update) 

class TLayer(cocos.layer.Layer):
    is_event_handler = True
    def __init__(self):
        cocos.layer.Layer.__init__(self)
        world_width, world_height = director.get_window_size()
        rand_color = [255, 0, 0]
        icolor = 0
        for i in range(qty_balls):
            ball = Ball((world_width*random.random(),
                         world_height*random.random()),
                        color=rand_color
                        )
            rand_color[icolor] = random.randint(50, 255)
            icolor = (icolor + 1)%len(rand_color)
            self.add(ball)
self.time = 0.0
self.schedule(self.update)

2)如果每个帧有25-100个以下的精灵需要更新,需要先添加到BatchNode中
[python]
class TLayer(cocos.layer.Layer): 
    is_event_handler = True 
        def __init__(self): 
            cocos.layer.Layer.__init__(self) 
            batch = cocos.batch.BatchNode() 
            self.add(batch) # we add a batch to the layer ...  
            world_width, world_height = director.get_window_size() 
            rand_color = [255, 0, 0] 
            icolor = 0 
            for i in range(100): 
                ball = Ball((world_width*random.random(), 
                             world_height*random.random()), 
                            color=rand_color 
                             ) 
                rand_color[icolor] = random.randint(50, 255) 
                icolor = (icolor + 1)%len(rand_color) 
                batch.add(ball) # see ? we add sprites to the batch, not the layer  
            self.batch = batch 
            self.time = 0.0 
            self.schedule(self.update) 

class TLayer(cocos.layer.Layer):
    is_event_handler = True
        def __init__(self):
            cocos.layer.Layer.__init__(self)
            batch = cocos.batch.BatchNode()
            self.add(batch) # we add a batch to the layer ...
            world_width, world_height = director.get_window_size()
            rand_color = [255, 0, 0]
            icolor = 0
            for i in range(100):
                ball = Ball((world_width*random.random(),
                             world_height*random.random()),
                            color=rand_color
                             )
                rand_color[icolor] = random.randint(50, 255)
                icolor = (icolor + 1)%len(rand_color)
                batch.add(ball) # see ? we add sprites to the batch, not the layer
            self.batch = batch
          &n

补充:移动开发 , 其他 ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,