Author Topic: How to make a container (containing buttons) scroll left and right  (Read 2652 times)

Micboy

  • Jr. Member
  • **
  • Posts: 79
  • Karma: +0/-2
    • View Profile
Hi,

I have read: http://dragonfiresdk.net/forum/index.php?topic=360.0
but it seems rather complicated! Is there an easier method? Without elasticity and friction?

For example, could I do something like:
Code: [Select]
int OnDrag(int id,int event,int x,int y)
{
// Record initial coordinates when pressed down
if (event == 1)
{
nOldX = x;

}

// Record new coordinates when moving
if (event == 2)
{
               nNewX = x;
}
}

return id;
}

then set new position of container?
Thank you in advance,

Micboy

Micboy

  • Jr. Member
  • **
  • Posts: 79
  • Karma: +0/-2
    • View Profile
Re: How to make a container (containing buttons) scroll left and right
« Reply #1 on: January 16, 2013, 02:36:31 pm »
This sort of works, but it jumps between touches:
Code: [Select]
int nOldX;
int nOldY;
int nNewX;
int nNewY;
int xDif;

int OnDrag(int id,int event,int x,int y)
{
// Record initial coordinates when pressed down
if (event == 1)
{
nOldX = x;
//nOldY = y;
nNewX = x;
//nNewY = y;
}

// Record new coordinates when moving
if (event == 2)
{
nNewX = x;
xDif = nNewX - nOldX;
ContainerSetxy(cn2[1], PackX+xDif,0);
//nNewY = y;
}

// Erase coordinates when released
if (event == 3)
{
nOldX = 0;
nOldY = 0;
nNewX = 0;
nNewY = 0;
}

return id;
}

Micboy

  • Jr. Member
  • **
  • Posts: 79
  • Karma: +0/-2
    • View Profile
Re: How to make a container (containing buttons) scroll left and right
« Reply #2 on: January 16, 2013, 02:44:05 pm »
Code: [Select]
int nOldX;
int nOldY;
int nNewX;
int nNewY;
int xDif;

int OnDrag(int id,int event,int x,int y)
{
// Record initial coordinates when pressed down
if (event == 1)
{
nOldX = x;
//nOldY = y;

}

// Record new coordinates when moving
if (event == 2)
{
nNewX = x;
xDif = nNewX - nOldX;
ContainerSetxy(cn2[1], PackX + xDif, 0);
//nNewY = y;
}

// Erase coordinates when released
if (event == 3)
{
//nOldX = 0;
//nOldY = 0;
//nNewX = 0;
//nNewY = 0;
}

return id;
}

Modified again! Sorry!


Just wondering whether the Touch Area position change as well if the container it is in moves???

DeadSn0wMan

  • Guest
Re: How to make a container (containing buttons) scroll left and right
« Reply #3 on: January 17, 2013, 09:12:58 am »
Why don't you download the project? You don't need to do anything complicated as long as you don' want to modyfi it. I recomend to dowload the project and then use the functions that it came with. It can seem more complicated than it is but you basicaly only need to use the ScrollButton Create() and Update function and the Scroller Update() function. There is no reason to re-invent the wheel.

Micboy

  • Jr. Member
  • **
  • Posts: 79
  • Karma: +0/-2
    • View Profile
Re: How to make a container (containing buttons) scroll left and right
« Reply #4 on: January 17, 2013, 12:15:09 pm »
Im new to making header files! What should I do?
Also, how should I change the program to only move left and right? Sorry, my vs Studio is down at the moment so cannot experiment at prsent!

DeadSn0wMan

  • Guest
Re: How to make a container (containing buttons) scroll left and right
« Reply #5 on: January 17, 2013, 01:46:33 pm »
In your visual studio version there should be a tab called project in this there should be an option to add an existing item. Then just chose the all headers you have downloaded

Micboy

  • Jr. Member
  • **
  • Posts: 79
  • Karma: +0/-2
    • View Profile
Re: How to make a container (containing buttons) scroll left and right
« Reply #6 on: January 17, 2013, 02:33:12 pm »
Sorry, I can't seem to make sense what all of the 'scroll' code means? Which part do you think I would need to make just one container move up and down?

For example, shall I write:
scroller1.Init(cn2[1], 360, 1000, 0);
scroller1.SetHorizontalScroll(true);

Also, what does the Centre page function do? (Sorry, i dont quite understand the code) - Basically, I need to make my container of size 360px length, 1000px width move left and right. How would I set this min X and max X values?
« Last Edit: January 17, 2013, 02:57:42 pm by Micboy »

DeadSn0wMan

  • Guest
Re: How to make a container (containing buttons) scroll left and right
« Reply #7 on: January 18, 2013, 07:38:29 am »
To be honest I think you should read up the basics in C++ so you can understand the most part of the code yourself. Otherwize you will get stuck again and again without knowing what's wrong. You can google thenewboston if you want some good C++ tutorials.

If you still don't want to do that (which I don't recommend) you can dowload the scrolling code project here: http://www.mediafire.com/?2ipll7cb2zlxpie and then try to read to the green comments which explains everything in the code. Then add the code to your project and then try it out for yourself(see how in my previous post).

After you done that you can return with some spesifik code questions in this thread, but for now I feel that it's pointless to try and help you build your own scroller class (which will be way more difficult) insted of using the one that allredy exists.