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.

2D All the way! / Sprite, play sprite

Author
Message
Code Stealer
21
Years of Service
User Offline
Joined: 12th Feb 2004
Location:
Posted: 16th Feb 2004 14:16
OK, real problem time, rather than me just flaming other peoples threads.

I was trying to learn the sprite commands at the weekend. Im fine with playing animation through the use of cutting out my images from my bitmaps then setting the image number on the sprite to the frame I want. However, then I looked at the play sprite command. This takes a bitmap and cuts it into frames for me, then plays those frames in a sequence.

Can I tell db to take those frames from an image rather than a bitmap? Or, how can I load my own sequence of images into the sprite?

Basically, Im trying to understand a way to get all the frames I want(at least 100 per charachter on screen) organised into the neatest and fastest code I can.

Any help would be good.

GIve me more power!
Pincho Paxton
22
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 16th Feb 2004 15:29 Edited at: 16th Feb 2004 15:32
Well you can use the Load Image "YourSprite.bmp",1

It might need ......Load Image "YourSprite.bmp",1,1

Two ,1,1

I think that turns off AA, I'm not sure, because I don't have DBPro.
Then you can time your animations like this...


T=Timer() + 500......half a second, whatever you want

Do

If T<= Timer then

paste your sprites here!
T=Timer() + 500......half a second, whatever you want
Endif

Loop


Pincho.

Code Stealer
21
Years of Service
User Offline
Joined: 12th Feb 2004
Location:
Posted: 16th Feb 2004 15:35
So what yor`re saying is that I can load a bmp straight to an image rather than to a screen, then use that image with the play anim command?

GIve me more power!
Pincho Paxton
22
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 16th Feb 2004 17:41
Yes you can do that.

Code Stealer
21
Years of Service
User Offline
Joined: 12th Feb 2004
Location:
Posted: 16th Feb 2004 18:02
How do specify that you want to use an image rather than a screen as the source for your "play sprite" command? Or can I just make all my frames as, say, 32x32 .bmp files than just load them all in as "images"? How many images can I use in DBpro, 6400?

GIve me more power!
Pincho Paxton
22
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 16th Feb 2004 19:32
Do this....

You can save your Image at their correct size..32*32..Whatever..
Say you name your Images....


MyImage1.bmp
MyImage2.bmp..........Then you can......


for n = 1 to 100

Name$ = "MyImage" + str$(n) + ".bmp"
Load Image Name$,n,1..........not sure about the second 1

next n

Now all of your images are given a number from 1 to 100 or however many images you have. Now you only need 1 sprite! But you keep changing its Image number in a loop. Make sure you time the change like I said earlier.

Pincho.

CloseToPerfect
22
Years of Service
User Offline
Joined: 20th Dec 2002
Location: United States
Posted: 16th Feb 2004 20:29 Edited at: 16th Feb 2004 20:30
put all the images for 1 sprite into 1 sprite sheet, so for 100 images it would be 10x10
use
create animated sprite 1, "spritesheet1.bmp", 10, 10, 1
to cut up the sheet into frames
use
play sprite 1, 1, 100, 50
to start the frames in order 1 to 100
now your loop
do
use set sprite frame to select which frames you want to show( you don't have to show all 100 at a time, say you have 10 sets of 10 animation, thats fine.
use the sprite command to place the sprite as usual.
sprite 1, mousex(), mousey(), 1
loop

all 100 images loaded and looping in what 4 commands, is that compact enough, there is a bug with create animated sprite look,here
http://www.thegamecreators.com/?m=forum_view&t=14254&b=15

I have a work around for it for ,but since p5 it's not such a big problem , you may not notice it anymore.

RGT may be gone but the best DBP forum is still alive and kicking, check it out.
http://www.dannywartnaby.co.uk/rgt/
Code Stealer
21
Years of Service
User Offline
Joined: 12th Feb 2004
Location:
Posted: 17th Feb 2004 11:49
Sounds good to me, I like the idea of having my images cut out before, as Ive been having problems sorting outthe order of cutting out sprites with commands, so loading all the images in is a better way for me I think.

GIve me more power!
Code Stealer
21
Years of Service
User Offline
Joined: 12th Feb 2004
Location:
Posted: 21st Feb 2004 01:00
I got this far with my piece of code and Ive put the graphics for it up on the interweb, so to check them out take the .zip from

http://homepage.ntlworld.com/curtisfell/uber/

ok, here is the code. Any help is good help.


sync on
hide mouse
set display mode 1024,768,16

load image "uber_stand_r1.bmp",1
load image "uber_stand_ru1.bmp",2
load image "uber_stand_u1.bmp",3
load image "uber_stand_lu1.bmp",4
load image "uber_stand_l1.bmp",5
load image "uber_stand_ld1.bmp",6
load image "uber_stand_d1.bmp",7
load image "uber_stand_rd1.bmp",8

load image "uber_run_r1.bmp",9
load image "uber_run_r2.bmp",10
load image "uber_run_r3.bmp",11
load image "uber_run_r4.bmp",12
load image "uber_run_r5.bmp",13
load image "uber_run_r6.bmp",14
load image "uber_run_r7.bmp",15
load image "uber_run_r8.bmp",16

load image "uber_run_ru1.bmp",17
load image "uber_run_ru2.bmp",18
load image "uber_run_ru3.bmp",19
load image "uber_run_ru4.bmp",20
load image "uber_run_ru5.bmp",21
load image "uber_run_ru6.bmp",22
load image "uber_run_ru7.bmp",23
load image "uber_run_ru8.bmp",24

load image "uber_run_u1.bmp",25
load image "uber_run_u2.bmp",26
load image "uber_run_u3.bmp",27
load image "uber_run_u4.bmp",28
load image "uber_run_u5.bmp",29
load image "uber_run_u6.bmp",30
load image "uber_run_u7.bmp",31
load image "uber_run_u8.bmp",32

load image "uber_run_rd1.bmp",33
load image "uber_run_rd2.bmp",34
load image "uber_run_rd3.bmp",35
load image "uber_run_rd4.bmp",36
load image "uber_run_rd5.bmp",37
load image "uber_run_rd6.bmp",38
load image "uber_run_rd7.bmp",39
load image "uber_run_rd8.bmp",40

load image "uber_run_d1.bmp",41
load image "uber_run_d2.bmp",42
load image "uber_run_d3.bmp",43
load image "uber_run_d4.bmp",44
load image "uber_run_d5.bmp",45
load image "uber_run_d6.bmp",46
load image "uber_run_d7.bmp",47
load image "uber_run_d8.bmp",48

load image "uber_run_ld1.bmp",49
load image "uber_run_ld2.bmp",50
load image "uber_run_ld3.bmp",51
load image "uber_run_ld4.bmp",52
load image "uber_run_ld5.bmp",53
load image "uber_run_ld6.bmp",54
load image "uber_run_ld7.bmp",55
load image "uber_run_ld8.bmp",56

load image "uber_run_l1.bmp",57
load image "uber_run_l2.bmp",58
load image "uber_run_l3.bmp",59
load image "uber_run_l4.bmp",60
load image "uber_run_l5.bmp",61
load image "uber_run_l6.bmp",62
load image "uber_run_l7.bmp",63
load image "uber_run_l8.bmp",64

load image "uber_run_lu1.bmp",65
load image "uber_run_lu2.bmp",66
load image "uber_run_lu3.bmp",67
load image "uber_run_lu4.bmp",68
load image "uber_run_lu5.bmp",69
load image "uber_run_lu6.bmp",70
load image "uber_run_lu7.bmp",71
load image "uber_run_lu8.bmp",72

n=9
sprite 1,100,100,n
remstart
sprite 2,100,160,n+16
sprite 3,100,240,n+24
sprite 4,100,320,n+32
sprite 5,160,100,n+40
sprite 6,160,160,n+48
sprite 7,160,240,n+56
sprite 8,160,320,n+64
remend

x=100
y=100

rundir=1

do

sync
wait 50

sprite 1,x,y,n



if rightkey()=1 and downkey()=0 and upkey()=0
n=n+1
x=x+20
if n>16
n=9
endif
rundir=1
endif

if rightkey()=1 and upkey()=1
n=n+1
x=x+20
y=y-20
if n<17 or n>24
n=17
endif
rundir=2
endif

if upkey()=1 and leftkey()=0 and rightkey()=0
n=n+1
y=y-20
if n<25 or n>32
n=25
endif

rundir=3
endif

if leftkey()=1 and upkey()=1
n=n+1
x=x-20
y=y-20
if n<65 or n>72
n=65
endif

rundir=4
endif

if leftkey()=1 and downkey()=0 and upkey()=0
n=n+1
x=x-20
if n<57 or n>64
n=57
endif

rundir=5
endif

if leftkey()=1 and downkey()=1
n=n+1
x=x-20
y=y+20
if n<49 or n>56
n=49
endif
rundir=6
endif

if downkey()=1 and leftkey()=0 and rightkey()=0
n=n+1
y=y+20
if n<41 or n>48
n=41
endif

rundir=7
endif


if rightkey()=1 and downkey()=1
n=n+1
x=x+20
y=y+20
if n<33 or n>40
n=33
endif

rundir=8
endif

if downkey()=0 and leftkey()=0 and rightkey()=0 and upkey()=0
n=rundir
endif

if x<2 then x=2
if x>980 then x=980
if y<2 then y=2
if y>720 then y=720

loop

GIve me more power!
PowerFang
21
Years of Service
User Offline
Joined: 6th Feb 2004
Location: Australia (But currently in the USA)
Posted: 21st Feb 2004 14:42
Help with what?? if you have a problem let us know what it is

The one thing i noticed, i think this will be causing your animations to not show correctly:

n=9
sprite 1,100,100,n
sprite 2,100,160,n+16
sprite 3,100,240,n+24
sprite 4,100,320,n+32
sprite 5,160,100,n+40
sprite 6,160,160,n+48
sprite 7,160,240,n+56
sprite 8,160,320,n+64


sprite 1 = Image 9
sprite 2 = Image 25
sprite 3 = Image 33
sprite 4 = Image 41
sprite 5 = Image 49
sprite 6 = Image 57
sprite 7 = Image 65
sprite 8 = Image 73 <- does not exist

So you start with 8 sprites on the screen with sprite 8's image not existing.

You arent using images 17 -> 24 :- your first jump (n+16) should be (n+8)?

You also only move sprite 1 so why do you need 8 sprites?

When you stop moving and start running right, it will cycle through the 8 stand images (thats what i guess images 1 - 9 are) because:

rundir = 1
n = rundir

then when you move right n = n + 1
so it will go through all those images instead of the running right images. So you need a condition if n < 9 then n = 9

or something like that.

I havent run the program these are just things i noticed in the code.....i might be wrong.

But let us know what the problem is then we can help better
Code Stealer
21
Years of Service
User Offline
Joined: 12th Feb 2004
Location:
Posted: 23rd Feb 2004 11:06
Er, sorry its me pateing up something Ive not cleaned up! I put 8 sprites in origionally to test the loading of the images, then "rem"ed out my workings! Anyway, Im now onto the joys of maps and walls. Ive got my map drawn in the back ground but cant seem to get any collisions working between the player and the back ground...

GIve me more power!
CPU
21
Years of Service
User Offline
Joined: 4th Jul 2003
Location: Carlsbad, CA
Posted: 8th Mar 2004 03:07
i'm not a mod but next time code stealer please post the code in a codebox, it's alot nicer for other people to read. also the loading image procedure could probably be better done with a loop and it wouldn't be so hard to load all those images, just a thought.

CPU

Sparring - Loved by many, Pefected by few.

I'm going to live forever, or DIE IN THE ATTEMPT!!!"
Code Stealer
21
Years of Service
User Offline
Joined: 12th Feb 2004
Location:
Posted: 8th Mar 2004 11:56
I cant seem to post code up as a snippet! It jsut doesnt apper if I put it in the box below....

Also, please can you explain how to make the loading of images into a good loop, how do you handle all the different filenames? Help with this sort of thing will really help my code! Thanks. Im working on a turn based strategy battle game at the moment and am going to have up to 4 players, who can choose an army from orcs, elves, human or dwarf, and can choose a colour out of 4 colours, so that each player can be the same race if they want to. Its going to be pretty simple graphics, but I need a good way to load in all the images into the correct slots, ie if player 1 chooses dwarves as his race and green as his colour, I want to load the green dwarf images into the image slots allocated to player 1. Just pseudo code will do, just to help me understand a bit better how to layout structured filenames.

GIve me more power!
Pincho Paxton
22
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 8th Mar 2004 17:35
The very first post I made to you was how to load animations in a loop. Here's 1 example.......

for n = 1 to 8

FileName$ = "uber_run_r" + str$(n) + ".bmp"

Load image Filename$,n+8

Next n

Code Stealer
21
Years of Service
User Offline
Joined: 12th Feb 2004
Location:
Posted: 8th Mar 2004 18:09
Ahh, Ok, thanks. Ill give it a try. I know it must be a simple routine, but its just getting the syntax right that causes the headaches!

GIve me more power!
Code Stealer
21
Years of Service
User Offline
Joined: 12th Feb 2004
Location:
Posted: 3rd Apr 2004 19:47
Ahh! FOund the thread again. Ok Ive come to put this bit in and have a question:

Should I dim str$(n)?

GIve me more power!
Tapewormz
22
Years of Service
User Offline
Joined: 15th Sep 2002
Location: Winnipeg, Mantoba, Canada
Posted: 3rd Apr 2004 23:56 Edited at: 4th Apr 2004 00:11
I load 1 image that contains all my sprites and use code to grab the sprites from the single image. You can use a couple of for next loops and a get image or get sprite command to do this.

To me it's a little easier than having 100 sprite files. Plus I'm lazy...

ie:



Quote: " Timesoft - Your wife is death. How? NO idea.
But it is murder. REVENGE!!!!!!!!!"

Hands down the funniest synopsis for a game ever. All your base are belong to us!
Pincho Paxton
22
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 4th Apr 2004 00:25
No you don't Dim it because it is a Command, and not an Array.

Morloc
21
Years of Service
User Offline
Joined: 21st Mar 2004
Location: UK
Posted: 4th Apr 2004 00:43
Hmm at the moment Ive only got say 30 images but im sure its gonna grow alot larger. You thinks it worth looking at load one image and chopping into images Tapewormz?

also am i the only one who has problems with png's crashing dbc. Ive had 2 pngs go screwy now.

Morloc
Tapewormz
22
Years of Service
User Offline
Joined: 15th Sep 2002
Location: Winnipeg, Mantoba, Canada
Posted: 4th Apr 2004 00:55 Edited at: 4th Apr 2004 00:55
Well the 10 lines of code saved you 30 lines of loading...and if its going to grow...then it's obvious which is more efficient.

Quote: " Timesoft - Your wife is death. How? NO idea.
But it is murder. REVENGE!!!!!!!!!"

Hands down the funniest synopsis for a game ever. All your base are belong to us!
Morloc
21
Years of Service
User Offline
Joined: 21st Mar 2004
Location: UK
Posted: 5th Apr 2004 16:34
The only problem i can see is that all my graphics are different sizes. The only way round this is to a have multiple gfx bitmaps for the different sizes ie bitmap1 32x32, bitmap2 64x64 etc etc.

Morloc
Code Stealer
21
Years of Service
User Offline
Joined: 12th Feb 2004
Location:
Posted: 5th Apr 2004 17:34
Well, thats just it, you can write a piece of code that loads the graphics, which is what Im doing. Im gonna use about 2000 frames(Im an animator so doing lots of frames is what Im good at!) so I wanted to write a routine that lets me load all the graphics for a charachter with just a couple of lines of code. Ive got it working too, so writing code to cut one image into many is probably just as hard or easy as writing code to load many images. Its just up to you to name them all sensibly....

Anyway, the reason I prefer the idea of using individual files that I load in is that my animframes can be different sizes, say for an explosion which starts small but gets bigger. Im using dbpro with rotations, so my collisions are going to be quite crude, so having control of the sprite size on a per anim frame level seems quite usefull to me.

GIve me more power!
Pincho Paxton
22
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 5th Apr 2004 18:53
Yeah, I think it's actually less code to load them in as images all seperated. There is also less waste of black 0,0,0. This consumes speed, and memory. Like cutting metal sheets, you will waste some metal from a large sheet, but can crop the pieces exactly around the edges, if you use lots of small sheets.

Pincho.

Login to post a reply

Server time is: 2025-05-15 19:58:45
Your offset time is: 2025-05-15 19:58:45