Create a CCLayer with specific size

I’m going to create a Mac app with drawing function. There will be a drawing area which is in specific size, for example, (300,300) in the middle of the whole screen. The reason I use specific size of layer is that I only allow user to draw within this area and record the coordinate in this area.

I tried to setContentSize to (300,300) after the new method and before the init() function. But the contentSize is not (300,300) inside the init() function. What’s wrong with my method? Any suggestion? Thanks

I don’t know of a way to restrict child’s coordinates in respect to its parent (which is effectively what you want) by just setting some value. I think you’d just want to track the when the user is drawing and explicitly not do any thing if they go out of bounds.

C.J. Kimberlin wrote:

I don’t know of a way to restrict child’s coordinates in respect to its parent (which is effectively what you want) by just setting some value. I think you’d just want to track the when the user is drawing and explicitly not do any thing if they go out of bounds.

Thanks for your reply. Actually I thought this as your suggestion. It is my last option because it’s not as easy as restrict the size of the sub-layer. My question is why setContentSize has no effect. The size is always the same as its parent layer.Then what is the purpose of setContentSize.

I know that content size has to do with textures that are applied to nodes (like the size of an image for a sprite). I’m not sure if it has additional uses or not. It shouldn’t be too hard to restrict the drawing to within your desired size. You should just need to convert the touch (or mouse) coordinate to the layer’s coordinate space and make sure the x less than the width of draw space and y is less than the height of draw space. Should be simple enough :).