[Last Question today] the Layer of rectangle view

I am sorry that I make a lot of question.
I know that is so sorry for cocos2d-x user. but I am burn to my foot by my work. :slight_smile:

I want to make a layer for scroll view. and I make it!
layer has two sprite. but I want to view in layer, not out layer.

if sprite.x is over layer size, it must be invisible.

I can change a graphic resource alpha value, because my boss doesn’t want to do.
I just make a visible or invisible sprite.

I think a lot of solution like a view port as openGL.
also think changed z-order in sprite each other.

last thinking is so weird.

anyway. I need a special layer for scroll when sprite is some rectangle view.
but, I am newbie. so my brain doesn’t work now.

is it class of cocos2d-x? I am using vc++ 2008 and Windows 7 32bit. so I can’t use a iphone’s UI and android UI like scrollview.


menu.jpg (17.7 KB)

You are always welcome here :slight_smile:
In this case, you don’t need to set yellow rect as invisible. Just set sprites in-screen & half-in-screen to visible, override ccTouchesMove to move the sprites (not move the layer), and don’t forget to preload the next image.
Take it easy.

Thanks a lot of.

Maybe I got a hint for great visible scroll layer.

Thank you very much.

Hello,
if is layer over all screen it is clear.

But what if is layer only part of screen (for example 50, 100, 250, 300)?
Its some possibility how to crop all objects (CCLabelTTF, CCMenu, CCMenuItemImage, CCSprite…) outside of this layer (something like scissor)?

Exist some cocos object, which is for this purpose or which is possible use for it?

Thanks for advice

MG

@Milda Genius
It seems there’s no API to do this now. You had to traverse the children in this layer, calculate their distance relation from object~~>getPosition, object~~>getContentSize or sprite~~>getTextureRect, than decide the the CCRect you would pass to each sprite~~>setTextureRect(CCSize);

if your scene is full of screen and you layer is part of the screen, i have no idea about the solution.
but if your game scene is also part of the screen, i can provide some advices: you could change glviewport to adapt your scene, and of course, you should modify glorthf to adapt you viewport too.

May be you can use CCSprite::setTextureRect() to change the visible rect.
I don’t test it, hope this can resolve it.

Thanks for advices.

I implemented solution by CCSprite::setTextureRect(), its working. I will send my example as inspiration for other users.

But one problem stays. Its restoration of textureRect after my modification to original state. I didnt find any method how to get this information from modifed CCSprite.
I can store original textureRect in userData or store it in my scroll Layer, but dont exist some better solution?

Example on:

Storing it in userData is the best way I can see…