Hello Guest

Author Topic: Finding specific frames & a lack of accuracy?  (Read 4441 times)

cipher

  • Newbie
  • *
  • Posts: 13
    • View Profile
Finding specific frames & a lack of accuracy?
« on: March 28, 2014, 05:01:51 am »
Hello readers,

So I'm having a bit of a problem, but first I'll explain what I'm trying to do. Basically I've created something that functions like a radial menu (think a pie slices into 5 pieces, each piece being an option you can select). Since the art I'm working with isn't very GUI friendly, I thought I'd do it in 2Dtoolkit. Basically I plan to have it cycle around, then based on what frame it's on when you press the select key, it will do whatever is shown.

The problem is, is that it just doesn't work. I'm starting small, with a three section radial. It starts on one frame, and if you press one key, it should scroll to the left, and to the right with the other key. Except it barely ever seems to do that. Sometimes I can get it to work going to the proper frame from to the left or right once from the starting point, but that's it. I've looked and tried a lot of things on this forum, but I haven't been able to find something that works. Here's my current strategy:

Code: [Select]


anim.Play ("Radial1");
anim.Pause();
                                if(Input.GetKeyUp(KeyCode.U) && currentFrame == 0){
anim.SetFrame(1);
currentFrame = 1;
}
if(Input.GetKeyUp(KeyCode.O) && currentFrame == 0){
    anim.SetFrame(2);
currentFrame = 2;
}
if(Input.GetKeyUp(KeyCode.U) && currentFrame == 1){
anim.SetFrame(2);
currentFrame = 2;
}
if(Input.GetKeyUp(KeyCode.O) && currentFrame == 1){
anim.SetFrame(0);
currentFrame = 0;
}
if(Input.GetKeyUp(KeyCode.U) && currentFrame == 2){
anim.SetFrame(0);
currentFrame = 0;
}
if(Input.GetKeyUp(KeyCode.O) && currentFrame == 2){
anim.SetFrame(1);
currentFrame = 1;
}


Looks pretty simple, but nothing ever seems to work right. I don't even know if the first frame in the animation counts as frame 1 or 0, but whatever number I put in doesn't seem to matter. I just have the three images of the radial set up in an animation. If anyone has any suggestions or better ways to do this, I would be really thankful. I only have a few days left to get this working.

Thanks for reading !

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Finding specific frames & a lack of accuracy?
« Reply #1 on: March 28, 2014, 10:06:14 pm »
Why are you using animations to display static sprites? Assuming your sprites are called "Radial1" - "Radial5" you can simply do sprite.SetSprite("Radial1"); and so on...
Anyway you probably want to decouple the input from the direction, and set the sprites at one point. That way you can use rotate a vector over time, extract the angle from the vector and decide what sprite to assign then.

cipher

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: Finding specific frames & a lack of accuracy?
« Reply #2 on: March 28, 2014, 11:38:05 pm »
I'm sorry, I'm not the most talented of programmers, so a lot of these things are over my head. I'm going to keep working on it, but I thought I'd post the updated code (all and all it has the exact same problem as what I have initially, it's just prettier). The current radial menu thing just has three options. If I put this code it, it works fine from the starting position:

Code: [Select]
if (Input.GetKey(KeyCode.I)) {
if(abilityPhase1){
if(Input.GetKeyUp(KeyCode.U) && sprite.CurrentSprite.name == "Radial1_Return")
sprite.SetSprite("Radial1_Feed");

if(Input.GetKeyUp(KeyCode.O) && sprite.CurrentSprite.name == "Radial1_Return")
sprite.SetSprite("Radial1_Sit");

With that you can properly scroll left or right once before it of course stops. But now, when I add the next two if statements...

Code: [Select]
      if(Input.GetKeyUp(KeyCode.U) && sprite.CurrentSprite.name == "Radial1_Feed")
sprite.SetSprite("Radial1_Sit");

if(Input.GetKeyUp(KeyCode.O) && sprite.CurrentSprite.name == "Radial1_Feed")
sprite.SetSprite("Radial1_Return");

It somehow breaks the first part that was initially working, and pressing either U or O will take you to Radial1_Sit, then nothing works. Using this strategy, there's another two statements that are needed, but if I add those, then nothing works at all. I'll keep working at it, but I don't even see why it's doing that

cipher

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: Finding specific frames & a lack of accuracy?
« Reply #3 on: March 29, 2014, 12:48:51 am »
Well I decided to just try and re-rig the thing in a GUI, exact same results. So I guess this problem isn't relevant to 2DTK, enough though it initially seemed like it.

Thanks for reading... hopefully I'll figure something out.