PDA

View Full Version : Any examples for swipe controlled Entities?



BigBMan
11-18-2010, 04:53 AM
Got any examples of how to do the following:

1. scrollable text - with and without scrollbar?
2. scrollable list - of entities, likely images representing the next screen. When tapped, loads the next screen.

Thanks!

Seth
11-18-2010, 11:44 AM
Sure, I'll add a new sub-menu to the RTSimpleApp showing an example of making a screen scroll soon.

Seth
11-18-2010, 02:00 PM
Ok, added another menu to the RTSimpleApp example to show how scroll bars work.

486

Basically you can just add any entity/image like normal and it will scroll if needed. (It doesn't care if it is text or clickable images)

If you want dragging to effect entities in some special way, you probably need to hook into the GetBaseApp()->m_sig_input signal and process the messages yourself, or, at a slightly high level, add a TouchHandlerComponent to an entity, and hook into the entities OnOverMove which will be called whenever the user drags over it. (This is what the ScrollComponent.cpp does.. other stuff like OnOverStart, OnOverEnd are also available)

The nice thing about this is it will respect the size of your entity and only send the messages if it's actually over it.

Also, keep in mind that you can hook into these functions/signals from anywhere, you don't have to make special components, you could just as easily wire OnOverMove on some entity image overlay to call a static function in your AboutMenu.cpp. Hmm, that all sounds so complicated, hope it makes sense. :sweatdrop:

BigBMan
11-19-2010, 09:40 AM
I'm having trouble with horizontal scrolling with OverlayEntity objects:



float width = GetScreenSize().x;
float height = GetScreenSize().y;

//setup the dimensions of where the scroll area will go
CL_Vec2f vTextAreaPos = CL_Vec2f(0, 100);
CL_Vec2f vTextAreaBounds = CL_Vec2f(width - 10, height - 300);

pScroll = pMain->AddEntity(new Entity("scroll"));
pScroll->GetVar("pos2d")->Set(vTextAreaPos);
pScroll->GetVar("size2d")->Set(vTextAreaBounds);
pScroll->AddComponent(new TouchHandlerComponent);

EntityComponent *pFilter = pScroll->AddComponent(new FilterInputComponent);
EntityComponent *pScrollComp = pScroll->AddComponent(new ScrollComponent);
EntityComponent *pScrollBarComp = pScroll->AddComponent(new ScrollBarRenderComponent); //also let's add a visual way to see the scroller position

Entity *pScrollChild = pScroll->AddEntity(new Entity("scroll_child"));

x = y = xSpace;
CreateOverlayEntity(pScrollChild, "Ent3", "interface/3_med.rttex", x,y);
x += 500;
CreateOverlayEntity(pScrollChild, "Ent2", "interface/2_med.rttex", x,y);
x += 500;
CreateOverlayEntity(pScrollChild, "Ent1", "interface/1_med.rttex", x,y);

ResizeScrollBounds(&VariantList(pScroll));

SlideScreen(pMain, true);

return pMain;

The same code works if I change the last few lines to



CreateOverlayEntity(pScrollChild, "Ent3", "interface/3_med.rttex", x,y);
y += 500;
CreateOverlayEntity(pScrollChild, "Ent2", "interface/2_med.rttex", x,y);
y += 500;
CreateOverlayEntity(pScrollChild, "Ent1", "interface/1_med.rttex", x,y);

Seth
11-19-2010, 11:13 AM
I'm having trouble with horizontal scrolling with OverlayEntity objects:

Ah, I've never actually tested horizontal before.. turns out there were some bugs. I fixed them (committed to svn), so it should now scroll horizontally properly.

Warning I should have mentioned though: The ScrollBarRenderComponent.cpp currently only draws a vertical bar (if needed). I just haven't needed anything with a horizontal bar yet. :sweatdrop: