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 / Re: Create animated sprite

Author
Message
rob3d
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: Canada
Posted: 9th May 2003 09:40
Just a couple of questions
I created and animated sprite with the "create animated sprite" command. The image is 376x2030 pixels and is a deck of cards with some jokers and a front face. My command to create the animated sprite was: create amimated sprite,1,"udeck.png",4,14,1
I was finally able to display the sprite after using the cls command which doesn't seem to be mentioned anywhere, but I digress.
When I displayed the sprite with the play sprite command all the cards got displayed but they also got cropped in both the vertical and horizontal directions! I checked the width and height of the sprite as well as the sprite scales by printing them on the screen will the program was running and they all checked out to what they should have been width 376/4=94 and 2030/14=145 and the x and y scales were both 100.
Is there some kind of sprite must be divisible by 16 pixel rule or something? Why are the sprites clipped?
What does the Image number parameter at the end of the have to do with anything. Are you creating an animated sprite and also kind of executing the load image command at the same ime?
One last question. Does anyone have the new DarkBasic programming book and what is your opinion of it? It costs over $100 canadian after taxes but it might be worth it if it has more information than just the command reference I got with the software. Finding just the right sample code can be difficult sometimes. I spent a couple of hours looking for a card shuffling routine when I know I have a great routine that sets each card to an ramdom array variable from a book I bought back in the Eighties. Alas it is buried in some box from our move.
Kentaree
22
Years of Service
User Offline
Joined: 5th Oct 2002
Location: Clonmel, Ireland
Posted: 9th May 2003 17:38
CREATE ANIMATED SPRITE Sprite Number, Filename, Across, Down, Image Number

Sprite Number= Pretty obvious
Filename=Filename of image you want to use
Across/Down=The amount of images up and down you want to cut up
Image Number=The image number in which the file will be stored.

So yes, the image is also loaded by this command.
If the command doesnt work, do it manually with get image & for...next loops.



Which would put images 1 to 56 as the cards. Then you could use

sprite spriteNo,xCoordinate,yCoordinate,imageNo

to animate them then.

Whatever I did I didn't do it!
rob3d
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: Canada
Posted: 9th May 2003 18:05
Thanks for the reply
Yes I agree your code looks good and I will probably use code such as that to program my game, but I was just more or less fooling around trying different ways to display sprites and wanted to know why the create animated sprite cropped the images it captured. it seemed like a great command but if crops the images it isn't very useful. Even if I knew how much cropping would occur I could have padded the images before I assembled then into the large bitmap(since it took about an hour to assemble the image in photoshop I don't look forward to making another large image with padded pictures, even if I knew how much padding should occur).
There seems to be a multitude of ways to do some of things i want to do in my program, but when something doesn't work as it should I like to find out why.
Kentaree
22
Years of Service
User Offline
Joined: 5th Oct 2002
Location: Clonmel, Ireland
Posted: 9th May 2003 18:46
Well the reason probably is that DBPro still has a lot of bugs. The only solution is to download each patch when they come out. But luckily there's usually a way around a problem, just ask and you'll be helped.

Cheers,
Kentaree

Whatever I did I didn't do it!
rob3d
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: Canada
Posted: 9th May 2003 19:05
Thanks for your reply.
Do you think I should address this problem directly to the folks at DarkBasic to find out if this is a reported bug?
Kentaree
22
Years of Service
User Offline
Joined: 5th Oct 2002
Location: Clonmel, Ireland
Posted: 9th May 2003 19:11
My bet is that they'll already know, it wouldnt be an uncommon command to use. Also, there's really no point if there's a working alternative, as long as this doesnt compromise performance too much or makes it too difficult to do. Them poor people at DBS are busy enough as it is

Whatever I did I didn't do it!
CloseToPerfect
21
Years of Service
User Offline
Joined: 20th Dec 2002
Location: United States
Posted: 10th May 2003 02:42
I've used create animate sprite on several different sizes and have found no problems with it. might be something with your syntax.

CTP
rob3d
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: Canada
Posted: 10th May 2003 07:50
CTP

It cropped the images on my computer. I could email you the code and image and see what you get.

I have just tried another option where I made one long bitmap 94x8120 pixels with all the cards in it and use the right and left mouse buttons to scroll the sprite up and down the page while listing the y position of the sprite. What I got was a very long 8120 pixel sprite that was distorted in the y direction with some of my cards at the end of the deck being only about 15 pixels high. When I scolled the sprite using the mouse button it scrolled okay for a while then stops dead for a while then continues on to the end. The card bitmaps in the middle of the deck seem to be close to true aspect ratio with the ones at the end getting progressivly smaller.
Am I just expecting too much from the language using such large bitmaps?
rob3d
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: Canada
Posted: 10th May 2003 08:46
Kentaree

I tried your code (which should work) and all I got was a window with a black backround. My text commands didn't even print!
Maybe my compter is cursed: Athalon xp2600+, 1 gig of ram and radeon 9700 pro AIW video card.

My latest non working code is noted below, I would be pleased if anyone could point out the error of my ways. I have been progamming in basic since the early eighties with my first computer an Apple II plus and on the Amiga in AMOS basic and on the PC in Delphi and I have never quite had as many problems as I am having with DarkBasic Pro. I see all the great games from the retro contest and I know DarkBasic Pro is very capable, but I can't seem to get it to do much of anything for me. Once again here is the code based on your snippet:
Rem Project: cardtest
Rem Created: 5/9/2003 10:02:51 PM

Rem ***** Main Source File *****

sync rate 30
sync on
backdrop off

load bitmap "udeck.png",1
set current bitmap 1
imageNo=1
for y=0 to 13
for x=0 to 3
get image imageNo, x*94,y*145,((x+1)*94)-1,((y+1)*145)-1
inc imageNo
next x
next y

sprite 1,100,100,6
sprite 2,100,100,15

do
rem cls
text 10,10,str$(sprite width(1) )
text 10,20,str$(sprite height(1) )
text 10,30,str$(sprite scale y(1) )
text 50,50,"hello"
sprite 1,100,100,6
sprite 2,200,100,15

sync
loop
CloseToPerfect
21
Years of Service
User Offline
Joined: 20th Dec 2002
Location: United States
Posted: 10th May 2003 18:20
I thought I had a bit map of a deck of card 4 wide 12 tall but I can find it. email me your image and I see what I can do. glad to help.

jchase1970@farts.com
or
jchase1970@hotmail.com if the first doesn't hold it.

CTP
CloseToPerfect
21
Years of Service
User Offline
Joined: 20th Dec 2002
Location: United States
Posted: 13th May 2003 04:49 Edited at: 31st Jul 2003 04:59
well, I guess this command is screw up. It would seem that for ever slice of the image it loses 1 pixels.

sorry, I tried everything, when I used it I didn't need it to be that precise and never noticed it losing the pixels like that.

click the source button to see the code you posted, fixed and working like you want with no croping.

CTP
CloseToPerfect
21
Years of Service
User Offline
Joined: 20th Dec 2002
Location: United States
Posted: 13th May 2003 05:54
I wrote 2 functions to do the animating for you souce in the souce button

dim sprite_index(number of sprites needed,3)
at the begining of you program make a array like this, in the demo I made it 100 sprite in size, dim sprite_index(100,3), good for upto 100 sprites

function set_sprite_frames(sprite_number,arcoss,down,image$,starting_image_number)
this function cuts the image sheet up into the frames
sprite_number, number of the sprite to use
arcoss, number of cuts across
down, number of cuts down
image$, file name of sprite sheet
starting_image_number, 1 image number index

function advance_frame(sprite_number,start_frame,last_frame,delay)
this function advances the sprite 1 frame
sprite_number, the sprite number
start_frame, the begining frame number
last_frame, the last frame number
delay, delay time in milliseconds

function animated_sprite(sprite_number,sprite_x,sprite_y)
this function displays the sprite
sprite_number, the sprite number
sprite_x, where you want it horizontal
sprite_y, where you want it vertical
no need to specify a image number as it hadles it internal


note, I did not include any error checking, like does the file exist.

CTP

Login to post a reply

Server time is: 2024-11-24 14:47:18
Your offset time is: 2024-11-24 14:47:18