Quote: "I think I should of mentioned that what I'm doing is in 3D, so I'm assuming "if upkey()=0 and animation playing(objwalk)=0" was ment for 2D since I got an error at this line."
OOPS! Sorry about that! I used the wrong command! ANIMATION PLAYING is for movies. I meant to use OBJECT PLAYING. In fact, there are several times in the code where I used animation <something> instead of OBJECT < something>. I've updated the block with a complete example not made in as much haste as last time.
I've changed the method slightly, accounting for loading idle.x first. It's basically the same, with a few changes.
sync on
sync rate 60
objidle=1
load object "idle.x",objidle
rem set our animation variables
startidle#=1
endidle#=total object frames(objidle)
startwalk#=endidle#+1
rem append the animation
append object "walk.x",objidle,startwalk#
rem now we can get the last animation frame
endwalk#=total object frames(objidle)
rem a variable to keep track of whether or not we've released the up key
walkengage=0
do
rem test for upkey
if upkey()
rem is it already walking and is this the first time the upkey is pressed
rem or has the upkey been held and not released?
if walkengage=0
rem stop what's doing and make it walk
stop object objidle
play object objidle,startwalk#,endwalk#
loop object objidle,startwalk#,endwalk#
walkengage=1
endif
endif
rem upkey has been released
if upkey()=0
rem stop everything and idle
stop object objidle
loop object objidle,startidle#,endidle#
walkengage=0
endif
sync
loop
Quote: "I had "models/idle.x" loaded as object 1 before, my goal is to stop idle and play walk when the upkey() or downkey() is pressed. Shouldn't I have to load both the idle and walk?"
That's fine to load either first, in this case idle.x. That makes more sense than the way it was worded at the top. And no; both do not have to be loaded. The idea behind the process is this:
1. On your hard drive are a series of the SAME model each saved as a different file.
2. Each model has it's own animation set
3. You load only ONE of these models as an object in DBC - that is if you only have 1 instance of this model in your game. If, for example you had 10 ninjas or something, then you would load the base model 10 times - in this case, the idle.x
4. Once the base model is loaded, you then APPEND additional animation sets to that object. You keep track of the start and end frames for each set and you play or loop those specific sets according to the action required for your game.
If there is still a problem, try loading the individual objects and running their animations to see if they even have animations and also to get an idea of their frames. Try something like :
sync on
sync rate 60
objidle=1
objwalk=2
load object "idle.x",objidle
load object "walk.x",objwalk
rem let's set the object speeds to super slow so we can observe the frame counts
set object speed objidle,1
set object speed objwalk,1
do
text 0,0,"Idle frame = "+str$(object frame(objidle))
text 0,20,"Walk Frame = "+str$(object frame(objwalk))
rem switch between animations
if object playing(objwalk)=0 and idleplay=0
rem show idle and hide walk for demo purposes
show object objidle
hide object objwalk
play object objidle
idleplay=1
walkplay=0
endif
if object playing(objidle)=0 and walkplay=0
rem show walk and hide idle for demo purposes
show object objwalk
hide object objidle
play object objwalk
idleplay=0
walkplay=1
endif
sync
loop
This should give you an idea if your objects will even animate and what their start and end frames are.
Then, try playing with the other code I posted before.
Enjoy your day.