简体   繁体   English

Cocos2d中的Scrollview - android

[英]Scrollview in Cocos2d - android

How to Implement Scrolling functionality in cocos2d Surfaceview in android? 如何在android中的cocos2d Surfaceview中实现滚动功能? Please give me some suggestion. 请给我一些建议。

There is no scroll view available in cocos2d, but check the below details if it can help you. cocos2d中没有可用的滚动视图,但请检查以下详细信息是否可以帮助您。

This example for screen reslution 320 x 480. 此示例用于屏幕重新分析320 x 480。

  1. Make one node with required height. 使一个节点具有所需的高度。 Ex : My screen height is 320 and I made a node of height 640. 例如:我的屏幕高度为320,我制作了一个高度为640的节点。
  2. Add it in the layer and set the position to (0, 320) 将其添加到图层中并将位置设置为(0,320)
  3. in method CCTouchMoved() increase the node position as per user touch move value EX : CGPoint touchLocation = CCDirector.sharedDirector().convertToGL(CGPoint.ccp(event.getX(), event.getY())); 在方法CCTouchMoved()中根据用户触摸移动值增加节点位置EX:CGPoint touchLocation = CCDirector.sharedDirector()。convertToGL(CGPoint.ccp(event.getX(),event.getY())); node.setPosition(0, 320 + (touchLocation.y - touchlocation.y of touch began)) node.setPosition(0,320 +(touchLocation.y - 触摸的touchlocation.y开始))

Hope it will work for you and if any other details required then comment on this 希望它能为您服务,如果需要任何其他细节,请对此进行评论

You can direct add android ui scrollview in cocos2d-android 1 like that 你可以直接在cocos2d-android 1中添加android ui scrollview

Activity mActivity=CCDirector.sharedDirector().getActivity();

View view=(LinearLayout) LayoutInflater.from(mActivity).inflate(R.layout.level_scroll,null);

mActivity.runOnUiThread(new Runnable() {

@Override
public void run() {
    // TODO Auto-generated method stub
    mActivity.addContentView(view, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));

}

}); });

You can make level_scroll.xml as per your requirement. 您可以根据您的要求制作level_scroll.xml。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM