Hi !
I'm very new to cocos2d, and I'm running into the following problem:
I've a background layer (with an image), and I want to display a modal
'login window' over it, centered on screen.
I've started from an example of this list (text input).
My problem is that when I move the login layer, its Labels and
Textfields move along, but the Rectangles do not.
The Labels are added to the Layer, the Rectangle to a batch of the
layer.
I've reproduced the problem here: the label moves, unfortunately its
background frame does not follows as expected. (run this script from
the 'samples' directory)
import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '../..'))
import pyglet
import cocos
from cocos.director import director
from cocos.layer import Layer
from cocos.scene import Scene
from cocos.actions import MoveTo
from cocos.sprite import Sprite
from cocos.cocosnode import CocosNode
from cocos.text import Label
class Rectangle(CocosNode):
'''Draws a rectangle into a batch.'''
def __init__(self, x1, y1, x2, y2, color, batch):
self.vertex_list = batch.add(4, pyglet.gl.GL_QUADS, None,
('v2i', [x1, y1, x2, y1, x2, y2, x1, y2]),
('c4B', color * 4)
)
class loginLayer(cocos.layer.Layer):
def __init__(self, *args, **kwargs):
super(loginLayer, self).__init__()
self.width = kwargs['width'] if kwargs.has_key('width')
else director.get_window_size()[0]
self.height = kwargs['height'] if kwargs.has_key('height')
else director.get_window_size()[1]
self.batch = pyglet.graphics.Batch()
Rectangle(0, 0, self.width, self.height, [255, 255, 255, 255],
self.batch)
self.add( Label('Hello', x=180, y=70, anchor_y='bottom',
color=(255, 0, 0, 255)))
def draw(self):
self.batch.draw()
class introLayer( Layer ):
def __init__( self ):
super( introLayer, self ).__init__()
# load an image
self.image = pyglet.resource.image('flag.png')
self.sprite = Sprite( self.image )
self.sprite.position = ( director.get_window_size()[0] / 2,
director.get_window_size()[1] / 2)
self.add( self.sprite )
cocos.director.director.init(width=800, height=600, caption="Hello")
intro_layer = introLayer()
login_layer = loginLayer (width=400, height = 140)
login_layer.do( MoveTo( ( 50, 50 ), duration = 1 ))
main_scene = cocos.scene.Scene ()
main_scene.add( intro_layer, z = 0 )
main_scene.add( login_layer, z = 1 )
cocos.director.director.run (main_scene)
print "end"
--
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.