Hi!
I’m using UPBGE with a python mainloop as described here:
I started from the default cube and I created two actions on this cube in the Dope Sheet Action Editor:
- ActionRotation: frame 1 with Z Euler Rotation = 0°, frame 30 with Z Euler Rotation = 45°
- ActionScale: frame 1 with X Scale, Y Scale and Z Scale = 1, frame 30 with X Scale, Y Scale and Z Scale = 0.5
This is the code in main.py:
#! bpy
import bge
import time
import timeit
# active scene cube
scene = bge.logic.getCurrentScene()
# the object "Cube"
cube = scene.objects["Cube"]
keyboard = bge.logic.keyboard
LOOP = True
FPS = 60 # Frames per Second
last_time = timeit.default_timer()
bge.logic.setExitKey(bge.events.LEFTARROWKEY)
while LOOP:
# mainloop
# wait until next frame
current_time = timeit.default_timer()
# sleep time until next frame
sleep_time = 1 / FPS - (current_time - last_time)
if sleep_time > 0:
time.sleep(sleep_time)
last_time = current_time
# change scene
# read keyboard input
k_events = bge.logic.KX_INPUT_ACTIVE
# uparrow key pressed
if keyboard.events[bge.events.UPARROWKEY] == k_events:
cube.playAction("ActionRotation", 1, 30)
cube.playAction("ActionScale", 1, 30)
# downarrow key pressed
if keyboard.events[bge.events.DOWNARROWKEY] == k_events:
cube.playAction("ActionScale", 30, 1)
cube.playAction("ActionRotation", 30, 1)
# escape key pressed
if keyboard.events[bge.events.ESCKEY] == k_events:
# Stop mainloop -> exit program
LOOP = False
# render next frame
bge.logic.NextFrame()
But it doesn’t work as I want.
When I press UPARROWKEY I see only the ActionScale action, when I press DOWNARROWKEY I see only the ActionRotation action.
What I want to do is to have a kind of queue where the actions are performed only when the previous ones are finished.
So if I press UPARROWKEY I will see the rotation and after the scale, if I press DOWNARROWKEY I will see the scale and after the rotation.
What is the best way to do this?
I tried to pass priority=0 and priority=1 to playAction(), but in this case the action with lower priority is not played after the other action.