自定义滚动型的andengine [英] Custom ScrollView in andengine

查看:92
本文介绍了自定义滚动型的andengine的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎样才能让一个自定义的滚动型这将所有的方面。而我怎么也找不到,我拍了拍滚动型的 andengine

How can I make a custom ScrollView which moves all the sides. And how do I also find the position where I tapped the ScrollView in andengine?

在此先感谢。

推荐答案

我写了这是一项正在进行的工作,但功能齐全,欢迎您使用小ShapeScrollContainer.java类,

I wrote a small ShapeScrollContainer.java class which is a work in progress but is functional and you are welcome to use,

https://skydrive.live.com/redir?resid=EB5E1E510A150D4D!105

有允许用户在容器区域内滚动,它可以自动添加到内容ShapeScrollContainer得到相应地移动。如果内容是ShapeScrollContainer的范围之外移动时,将设置内容项目知名度假的,(如后文所述,你也可以把它淡出内容,因为它接近这些边界)。

It allows a user to scroll within the container area, contents which you add to the ShapeScrollContainer automatically get moved accordingly. If content is moved outside of the bounds of the ShapeScrollContainer, it will set the content item visibility to false, (as described later you can also get it to fade out the content as it approaches these bounds).

我已经包含了完整的Java文档与讲解各法。本质上,它扩展了矩形,并实现了IScrollDetectorListener,IClickDetectorListener接口。只需将其添加到您的场景中,你会另一种形状,

I have included full java doc with explanations for each method. Essentially it extends Rectangle and implements the IScrollDetectorListener, IClickDetectorListener interfaces. Simply add it to your scene as you would another Shape,

ShapeScrollContainer ScrollableArea = new ShapeScrollContainer(x, y, width, height, new IShapeScrollContainerTouchListener()
{

    @Override
    public void OnContentClicked(Shape pShape) {
        // TODO Auto-generated method stub

    }

});
mScene.registerTouchArea(ScrollableArea);
mScene.attachChild(ScrollableArea);

该OnContentClicked接口方法被调用,如果您添加到ShapeScrollContainer项目得到由用户点击。该pShape参数将是一个指针,它被点击的形状。该ShapeScrollContainer移动内容没有摄像头,所以你还没有加入到容器中的任何其他子画面将出现不受影响。

The OnContentClicked interface method will get called if an item which you added to the ShapeScrollContainer gets clicked by a user. The pShape argument will be a pointer to the Shape which was clicked. The ShapeScrollContainer moves the contents not the camera so any other sprites you have not added to the container will appear unaffected.

您就可以致电该ShapeScrollContainer.Add()方法来增加您的精灵,动画/瓷砖精灵,矩形等例如,一个ChangeableText,

You then just call the ShapeScrollContainer.Add() method to add your Sprites, Animated/Tiled Sprites, Rectangles e.t.c. For example, a ChangeableText,

final ChangeableText mMessage = new ChangeableText(x, y, mFont, "Scroll Me", HorizontalAlign.LEFT, 14);
mMessage.setVisible(true);
mMessage.setZIndex(10);
mMessage.setBlendFunction(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
mScene.attachChild(mMessage);

ScrollableArea.Add(mMessage);

一旦添加一切ShapeScrollContainer有多种方法,它满足你的需要,

Once you have added everything the ShapeScrollContainer has a variety of methods to tailor it to your needs,

//Whether you want to allow user to scroll vertical/horizontal
ScrollableArea.SetScrollableDirections(false, true);
//Only allow the user to scroll in a direction to available content
//(no more content in that direction - the user will be prevented from scrolling)
ScrollableArea.SetScrollLock(true);
//By how much over the last content in any direction the user is allowed to scroll (% of height/width)
ScrollableArea.SetAlphaPadding(10.0f, 0);
//Allow ShapeScrollContainer to increase alpha of contents and by what distance it starts inside
//the ShapeScrollContainer itself. (Fades content as it approaches the edges due to user scrolling)
ScrollableArea.SetScrollLockPadding(50.0f,0.0f);
//Whether scroll bars will be visible, (horizontal/vertical)
ScrollableArea.SetScrollBarVisibitlity(true,true)
//...
//A lot more methods to refine the ScrollableArea appearence and behaviour - see java doc

希望这是使用。

Hope this is of use.

这篇关于自定义滚动型的andengine的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆