Change animation frame by pressing a button

0 favourites
  • 11 posts
From the Asset Store
Selection frame like in RTS games, works both on mobile and desktop devices.
  • Hello guys,

    I came to a problem that I thought would be one of the easiest things. I have a menu. It consists of a background sprite on a locked background layer and an other sprite with 3 frames, each has one of the menu buttons highlighted. This sprite is on the top layer. I would like to make it work like this: when I press the down button, it jumps to the next frame on the sprite with the button highlights, when I press the up button it jumps to the previous.

    It doesn't work. I use events like on the picture below. My background sprite is animated, but the one that has the highlighted menu button frames is not. I've added the keyboard to the project. I thought the problem could be because I haven't set which animation to choose, but that sprite only has one.

    <img src="" border="0" />

  • see if the mainmenu_items object have the animation speed set to 0

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Yes it does.

  • can you post a .cap?

  • Sorry, I cannot post links yet.

  • well, is hard to say without a closer look

    but i think is something with you object animation, see if the frames are correct, if there is a animation (sometimes we copy the same frame by mistake), see if the animation start with frame 0 on the properties of the object and check if there is no other event blocking this action.

  • Finally found the problem. I had three of this event, obviously for all three menu items to step to the next upon pressing the down key. When I removed the last two it worked well. When I removed only the last event (which supposed to jump from the third to the first button upon pressing the key) and ran the program it jumped instantly to the last menu button thus skipping the middle.

    I think the source of the problem might be that the program runs the events instantly and jumps through all the menu items on one single press.

  • yes, you have to keep in mind that the events need to be a sequence sometimes

  • Seems to work this way.

    <img src="" border="0" />

  • Yeah, i use same way. I kind of understand why it works, but don't know how to explain it XD Not sure if it's the right way too and will not introduce some lags in the long run.

  • So, your events were like this?

    keyboard: on down arrow pressed
    mainmenu_items: animation frame=0
    ---> mainmenu_items: set animation frame=1
    keyboard: on down arrow pressed
    mainmenu_items: animation frame=1
    ---> mainmenu_items: set animation frame=2
    keyboard: on down arrow pressed
    mainmenu_items: animation frame=2
    ---> mainmenu_items: set animation frame=0

    Adding the wait works well as you delay the frame from getting set right away so the 2nd and 3rd events won't be true and run. On a side note you should be able to do "wait 0" as it will just delay till the end of the event sheet.

    Another approach I like to take in a situation like this is to also use the modulus operator to simplify the logic. eg:

    keyboard: on down arrow pressed
    ---> mainmenu_items: set animation frame= (mainmenu_items.AnimationFrame+1)%3
    keyboard: on up arrow pressed
    ---> mainmenu_items: set animation frame= (3+mainmenu_items.AnimationFrame-1)%3
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)