0
\$\begingroup\$

I want to implement something in my LibGdx game, where a small stick is positioned vertically.On tap,I have to increase the length of the stick with tap frequency.Later I want to rotate,perform collision and do all those things that a sprite can do.It is an advanced form of fly Swatter game. I am wondering how can I do it.I found some ways.But I am not sure it will work nicely.

1.Creating an array of small sticks and adding it to the base stick to increase the length.(Rotating array of object at a time is difficult,I know.)

2.Scale the image to increase the size of the stick.

Important thing is that this stick and rotation is an super important event in my game.

I only have experience of a simple running in LibGdx. It would be very helpful if experienced persons give some ideas to implement this game in LibGdx.

\$\endgroup\$
2
  • \$\begingroup\$ Have you an idea of how many times you can resize the stick ? Sprite allow to rotate and perform collision with some tricks. \$\endgroup\$ Jan 31, 2017 at 8:20
  • \$\begingroup\$ I want to increase the length on tap,up to a specific distance.It will stop resizing when reaching that distance. \$\endgroup\$
    – Niranjana
    Jan 31, 2017 at 8:24

1 Answer 1

0
\$\begingroup\$

If your stick is unicolor, you could just resize it like you want, you'll have no loss of quality. If your stick is multicolor and you don't need too much states, you could do as much textures as you have sticks.

For solution one, juste use

// Keep in mind : scale is from sprite origin
sprite.setScale(scaleX, scaleY);

For solution two,

int nbStates = 10; // Number of texture you need
Texture textures[nbStates];

// Maybe use a for loop to load textures
for (int i = 0; i < nbStates; i++)
    textures[i] = new Texture("sprites/stick" + i + ".png");

Then on tap use :

sprite.setTexture(textures[stickState]);
\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .