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 / Moving Animated Sprites

Author
Message
ricky hanks
18
Years of Service
User Offline
Joined: 10th Sep 2006
Location:
Posted: 17th Sep 2006 21:40
Hello!
I am having a problem with my sprite "Sledge". He has an Idle animation for the left and right directions and he has a running animation for the left and right directions. I have no problem getting him to animate and move to the right direction, however when I try to get him to move to the left his idle animation for the right direction stays going. Heh, but he moves to the left. I would like for him to switch over to the left running animation when the Leftkey is pressed and when he is stopped in the left direction, his left idle animation will kick in.

I have included my code. I hope that that will be enough to give you an idea of what I am trying to achieve. If not I can send the actual files. Any help would be awsome!
Thank you.

jinzai
18
Years of Service
User Offline
Joined: 19th Aug 2006
Location: USA
Posted: 17th Sep 2006 22:45 Edited at: 17th Sep 2006 23:09
Hey, ricky hanks!

Right now, I am a little occupied watching football, and other things. A couple of things however.

First of all...your code is very clean, and tidy...that is essential to creating a program of some substance. You are well ahead of the game in that department.

Before you get a thousand snippets that essentially ask you to change your coding style...I want to point out that you can also inc variable, 1...or another amount. I still use variable = variable + 1 alot. I SERIOUSLY doubt that the executable is ANY different. I have been reading the release notes to help me find out how DBProworks in the compiling stage. Personally, I would prefer to be able to use variable += 1. inc is more like an opcode to me for x86 processors. The only difference MIGHT be that inc uses the cx (whatever the 32 bit equivalent is) register.

One thing I would do is replace the gosubs with actual functions.
People use gosub because they believe that it is faster. (I do not know, but I have my doubts.) I will argue that functions are more powerful than subroutines...for one thing they accept parameters, and return values. DBPro does not fully leverage the abilities exposed by functions, like passing by reference...too bad. I think that will be in some time in the future, so I code with that hope.

The semi-colon might be tripping you up, because an if statement will break out to the next line, and the semi-colon is like a line continuation character. Make your if loops like this to avoid that.
if condition = 1
take action1
take action2
take action n
endif
There is nothing to gain by using the semi-colon in this case, and it messes up your intended logic.

Nice code so far!
ricky hanks
18
Years of Service
User Offline
Joined: 10th Sep 2006
Location:
Posted: 17th Sep 2006 23:39
Thank you for your reply jinzai.
Well, I'm currently beind drawn away by the Spouse trading show marathon. Hehe.

I changed up the If\Then to If\EndIf.


I think that it looks much cleaner and more easy to follow. Thanks for that tip. Perhaps You can explain more on the difference on Functions and Sub-Routines. Would that be the same as the difference between GoSub and coding directly into the Loop?
Also, I do use the Inc command a little in one of my 3D projects. The only other project I have. And I have learned alot from it! Mostly I have learned that I am not quite sure when it is right to use such statements as "Inc" or "GoTo" or even "GoSub"

I am also sorry that I failed to mention this is being coded in the Demo Version(Pro is on its way in the mail!).

I included a photo to give some sort of visual representation of my problem. So hopefully it will make it more clear in explaining my problem.

Thanks Again.

Attachments

Login to view attachments
ricky hanks
18
Years of Service
User Offline
Joined: 10th Sep 2006
Location:
Posted: 18th Sep 2006 00:53
Ok, I have Fixed Sledge's slidind problem, thanks to the If\EndIf statements.


Sync On : Sync Rate 30
Hide Mouse

Rem Load Animation: Sledge Idle R.
Load Image "C:\Documents and Settings\Compaq_Administrator\Desktop\Sledge\SledgeRight1.bmp",1,1
Load Image "C:\Documents and Settings\Compaq_Administrator\Desktop\Sledge\SledgeRight2.bmp",2,1
Load Image "C:\Documents and Settings\Compaq_Administrator\Desktop\Sledge\SledgeRight3.bmp",3,1
Load Image "C:\Documents and Settings\Compaq_Administrator\Desktop\Sledge\SledgeRight4.bmp",4,1
Rem Load Animation: Sledge Idle L.
Load Image "C:\Documents and Settings\Compaq_Administrator\Desktop\Sledge\SledgeLeft1.bmp",5,1
Load Image "C:\Documents and Settings\Compaq_Administrator\Desktop\Sledge\SledgeLeft2.bmp",6,1
Load Image "C:\Documents and Settings\Compaq_Administrator\Desktop\Sledge\SledgeLeft3.bmp",7,1
Load Image "C:\Documents and Settings\Compaq_Administrator\Desktop\Sledge\SledgeLeft4.bmp",8,1
Rem Load Animation: Sledge Running R.
Load Image "C:\Documents and Settings\Compaq_Administrator\Desktop\Sledge\sledgerunr1.bmp",9,1
Load Image "C:\Documents and Settings\Compaq_Administrator\Desktop\Sledge\sledgerunr2.bmp",10,1
Load Image "C:\Documents and Settings\Compaq_Administrator\Desktop\Sledge\sledgerunr3.bmp",11,1
Load Image "C:\Documents and Settings\Compaq_Administrator\Desktop\Sledge\sledgerunr4.bmp",12,1
Rem Load Animation: Sledge Running R.
Load Image "C:\Documents and Settings\Compaq_Administrator\Desktop\Sledge\sledgerunl1.bmp",13,1
Load Image "C:\Documents and Settings\Compaq_Administrator\Desktop\Sledge\sledgerunl2.bmp",14,1
Load Image "C:\Documents and Settings\Compaq_Administrator\Desktop\Sledge\sledgerunl3.bmp",15,1
Load Image "C:\Documents and Settings\Compaq_Administrator\Desktop\Sledge\sledgerunl4.bmp",16,1


Rem Sledge Animations
sledgex= sledgex

IdleR=1
SledgeIdleRight= 1
SledgeIdleR:
SledgeIdleRight= SledgeIdleRight + 1
If SledgeIdleRight > 4 Then SledgeIdleRight= 1
Sprite 1,sledgex,240,SledgeIdleRight : Scale Sprite 1,200
Return

IdleL=0
SledgeIdleLeft=5
SledgeIdleL:
SledgeIdleLeft= SledgeIdleLeft + 1
If SldgeIdleLeft > 8 Then SledgeIdleLeft= 5
Sprite 1,sledgex,240,SledgeIdleLeft : Scale Sprite 1,200
Return

RunR=0
SledgeRunRight=9
SledgeRunR:
SledgeRunRight= SledgeRunRight + 1
If SledgeRunRight > 12 Then SledgeRunRight= 9
Sprite 1,sledgex,240,SledgeRunRight : Scale Sprite 1,200
Return

RunL=0
SledgeRunLeft=13
SledgeRunL:
SledgeRunLeft= SledgeRunLeft + 1
If SledgeRunLeft > 16 Then SledgeRunLeft= 13
Sprite 1,sledgex,240,SledgeRunLeft : Scale Sprite 1,200
Return

Rem Sledge Movement
Movement:

If Rightkey()=1
RunR= 1
RunL= 0
IdleR= 0
IdleL=0
sledgex= sledgex + 10
EndIf

If Rightkey()=0
RunR=0
IdleR=1
IdleL=0
sledgex= sledgex
EndIf

If Leftkey()=1
RunR=0
RunL= 1
IdleR=0
IdleL=0
sledgex= sledgex - 10
EndIf

If RunR = 1
Sprite 1,sledgex,240,SledgeRunRight
If RunR=0
IdleR=1
EndIf
EndIf

If RunL = 1
Sprite 1,sledgex,240,SledgeRunLeft
If RunL=0
IdleL=1
EndIf
EndIf

If IdleR=1
Sprite 1,sledgex,240,SledgeIdleRight
EndIf

Return

Rem Main Loop
Do
GoSub SledgeIdleR
GoSub SledgeIdleL
gosub SledgeRunR
gosub SledgeRunL
gosub movement
Sync : Sleep 20
Loop

So now his Left walking animation is functioning wonderfully!
Ahem... However He will not Idle facing the left side. I need to find a way to determine if Sledge is facing the left side or the right side. The first and only real thought that comes to mind is of course to use a variable. I just don't know how.

Example:
If SledgeDirection=0 Then He is facing the right side.
To bad that isn't an actual command...
ricky hanks
18
Years of Service
User Offline
Joined: 10th Sep 2006
Location:
Posted: 19th Sep 2006 00:42
^Im sorry about that, I must forgot to do the code command...
D Ogre
21
Years of Service
User Offline
Joined: 19th Nov 2003
Location:
Posted: 21st Sep 2006 00:03 Edited at: 21st Sep 2006 00:51
I don't know if your still having a problem with your code, but I do
have a solution that I have posted many times here in the forums.

Here's a link for a somewhat recent topic that I helped with:
http://forum.thegamecreators.com/?m=forum_view&t=82482&b=7

It explains how to do it with both a 3D textured plain as well as 2D sprites.
There is some example media that can be used to demonstrate the code there as well...

Although I do agree with Jinzai, functions are a better way to code, but
the code I wrote does not employ the use of it. I feel that it keeps things
a little simpler for the beginner grasp intially.

I think using INC or DEC in your code is not going to make a huge difference
as far as the performance standpoint rather than say variable = variable + 1.
I think it's just a matter of preference. It's quicker and cleaner to type it
with INC or DEC. However, it does create problems when using it with an array
in DBC. The compiler has a fit about using it for arrays. I believe you can get
away with it in DBPro though, if I remember correctly.

Using colons in your code and IF/Then versus IF/ENDIF is also a preference. I
use them both when coding. It depends on what I am trying to do and what looks
better to me. As long as your code is neat, clean, and has go structure to it so
you and others can read it, then your on the right track.
ricky hanks
18
Years of Service
User Offline
Joined: 10th Sep 2006
Location:
Posted: 22nd Sep 2006 00:41
Thank you D Ogre!
This weekend when I have time off work I'll will fix all my problems. I had also previously tried to animate plains in my 3D program.



That is how I did it, even though that's irrelevant since I haven't looked at how you do it yet. But this weekend I will fix it. I am determined!

Thank you very much>

Login to post a reply

Server time is: 2024-11-26 12:32:09
Your offset time is: 2024-11-26 12:32:09