Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / What is the best way to animate and Move my object

Author
Message
Jonk
19
Years of Service
User Offline
Joined: 31st Jul 2005
Location: East of Java
Posted: 13th Jan 2014 16:48
I am trying to move an player object and play the correct coresponding animation frames. I would like to also animate the object when it is not moving but I am having problems. Also how do I setup anmimations for key combinations ie forward and right?


player1move:

`player idle
`loop object player1,1490,1513


if keystate(17)
play object player1,1970,1986
move object player1helper,-player1speed#
endif

if keystate(31)
play object player1,1970,1986
move object player1helper,player1speed#
endif

if keystate(32)
play object player1,782,801
move object left player1helper,player1speed#
endif

if keystate(30)
play object player1,762,781
move object right player1helper,player1speed#
endif

return

"There are no perfect ideas only perfect intentions"
chafari
Valued Member
18
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 13th Jan 2014 18:08 Edited at: 13th Jan 2014 18:11
Hi there
We can make a trick. We can SET OBJECT FRAME to force our object to play exactly the part of the animation we need for each KEY .Take a look to the attached example.



I'm not a grumpy grandpa

Attachments

Login to view attachments
Jonk
19
Years of Service
User Offline
Joined: 31st Jul 2005
Location: East of Java
Posted: 14th Jan 2014 11:14
Thanks chafari
that code seems to work well but i was wondering if there is a way to slow the frame rate? I did try the sleep command but it gave me drastic hits on my fps.



"There are no perfect ideas only perfect intentions"

Attachments

Login to view attachments
chafari
Valued Member
18
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 14th Jan 2014 15:15 Edited at: 14th Jan 2014 15:30
You need something like a timer. Try this:



I'm not a grumpy grandpa
Derek Darkly
13
Years of Service
User Offline
Joined: 22nd Sep 2011
Location: Whats Our Vector, Victor?
Posted: 14th Jan 2014 16:01 Edited at: 14th Jan 2014 16:05
Another way to do a timer could be as simple as:



The timer length (???) can be adjusted depending on which frames you're using. (Running may call for more speed than walking.)

The use of a subroutine here is just one example...
Most people seem to prefer functions, but I'm rather "laissez-faire" about it.

D.D.
Jonk
19
Years of Service
User Offline
Joined: 31st Jul 2005
Location: East of Java
Posted: 15th Jan 2014 07:00
Ok thanks for that, using the timer() expression seems to work well however I have another two problems now.

(1) if two buttons are pressed simultaneously eg "W" and "A" the animation stops. Idealy I would still like the forward animation to play.

(2) I would like to play a frame sequence when the object is not moving eg if no button is being pressed



"There are no perfect ideas only perfect intentions"
chafari
Valued Member
18
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 15th Jan 2014 11:01
Quote: "if two buttons are pressed simultaneously eg "W" and "A" the animation stops"


You could put conditions for two pressed KEY:

if keystate(32) and keystate(31)
conditions
conditions
endif



We can put conditions also if no key is being pressed , and even randomly:

if rnd(2000)=20
conditions
endif


I'm not a grumpy grandpa
Ortu
DBPro Master
17
Years of Service
User Offline
Joined: 21st Nov 2007
Location: Austin, TX
Posted: 17th Jan 2014 21:03 Edited at: 17th Jan 2014 21:08
i prefer to have the key input set a state instead of having them directly control the ppsition and animation, then once you have processed all inputs, you can use the state to determine what to do and which animation to play.

say any movement key will set an 'isMoving' state to true, and the shift key will set an 'isSprinting' state to true.

after updating all states you can play the forward animation if any wasd key or combination was pressed, change it to a sprint animation if space was also pressed not because (keystate w and keystate a and keystate space) but rather because (isMoving and isSprinting) regardless of the specific keys used to set them.

this way you dont have to specify an if statement and work out logic for every possible combination, and you also retain information about the input after the fact to use throughout the program. this can be useful in a variety of ways including AI prediction and multiplayer networking among others.

i can post some code when i get home if you would like a more specific example.

Jonk
19
Years of Service
User Offline
Joined: 31st Jul 2005
Location: East of Java
Posted: 18th Jan 2014 15:25
Thanks Ortu I would very much like some example snippets if it is not to much trouble the idea you suggest sounds good. I'm gonna go and tinker with some code to test it out

"There are no perfect ideas only perfect intentions"
Jonk
19
Years of Service
User Offline
Joined: 31st Jul 2005
Location: East of Java
Posted: 20th Jan 2014 13:22
Ok I managed to get some code going that seems to work well.

I did what Ortu said and used the keystates to set a flag which then jumped to a routine that played the relevant animation and moved the object before setting the flag to off before the next cycle.



"There are no perfect ideas only perfect intentions"

Attachments

Login to view attachments
Ortu
DBPro Master
17
Years of Service
User Offline
Joined: 21st Nov 2007
Location: Austin, TX
Posted: 22nd Jan 2014 07:43 Edited at: 22nd Jan 2014 08:10
Sorry for the delay, it has been busy for me.

Good to see you working through it and get something working!

However, in your current code, you are still trying to work out every logical combination of key presses manually to set your states. You are being too specific with your states. The idea is not to have a separate state for each combination, but rather have more general states which can then be layered over each other to created greater complexity. Modularization.

For example, if you have a 'forward' state and a 'left' state, you don't need a 'forwardleft' state, you can test for forward+left by checking the first two.

Here is more in the way of what I was talking about, hopefully the code will explain it more clearly.



Login to post a reply

Server time is: 2024-11-23 15:28:17
Your offset time is: 2024-11-23 15:28:17