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 / Image Pasting Question

Author
Message
Retro Addict
20
Years of Service
User Offline
Joined: 12th Feb 2004
Location: Georgia, USA
Posted: 24th Jun 2004 00:10
I'm using the paste image command (someone tell me if there's a better way) to display a series of pictures to simulate an animated explosion. I'm using a for next loop to display the series of pictures (using the x,y values from my object that I want to "explode"). When I run the program and the object explodes, I see what appears to be the last image in the series shown in the top left corner of the screen. I know it's something simple that I'm just overlooking, but some outside input would be greatly appreciated.....

PC Specs: AMD 1800+ 512M DDR, Radeon 128meg DDR - DB v1.13

To DB or not to DB............duh DB!
Jetmech
21
Years of Service
User Offline
Joined: 25th Oct 2002
Location: Dayton Ohio
Posted: 24th Jun 2004 01:07
A code snippet would tell us a lot more, so we can actually see whats going on, theres quite a few ways to make explosiond depending on the context of your game.

you might want to look into animated sprites if your game is 2D which takes a series of images cut from a main image, (almost like prepare matrix texture) and uses those to animate a single sprite.

however if your using paste image for an explosion in a 3D game then theres many better ways to go about it since the x and y coords for paste image are screen coords and the x and y coords for an object are world coords they wont match up.

give us some code to look at and we'd be able to help a lot more.

zircher
21
Years of Service
User Offline
Joined: 27th Dec 2002
Location: Oklahoma
Posted: 24th Jun 2004 01:21
What you're probably doing is displaying ALL the frames of animation in one sync/frame. The net result is that the last frame of animation is the only one visible since you have overwritten all the other frame before synchronizing with the monitor. You'll need at a minimum some logic to display one frame per loop so that the explosion can be seen as a series of pictures. Depending on your FPS, you may need to add some timing logic so that each frame stays up for X number of milliseconds.

That's just one way, you should also read up on animated sprites in the help files to see if that will work for you.
--
TAZ

History did not begin with PONG. -- Greg Costikyan

Game Beavers
Retro Addict
20
Years of Service
User Offline
Joined: 12th Feb 2004
Location: Georgia, USA
Posted: 24th Jun 2004 02:28
@ jetmech. i posted that message at work and was unable to attach code. i will see about getting that up here.

@ zircher. you're right about the timing. it's all in one loop displaying them all at once. fps is currently running 31-32 on pc's ranging from p3 800 to athlon 1800+ systems with various memory/video configurations. wow consistancy, imagine that....

PC Specs: AMD 1800+ 512M DDR, Radeon 128meg DDR - DB v1.13

To DB or not to DB............duh DB!
Retro Addict
20
Years of Service
User Offline
Joined: 12th Feb 2004
Location: Georgia, USA
Posted: 24th Jun 2004 06:10
ok, here's some sample code.

images loaded prior (1-15)

explosion:
for i = 1 to 15
paste image i,x,y
next i
return

this is a routine that is accessed via a gosub when a target is hit and i want an explosion to appear at x and y coordinates which are varied and not at the top left corner of the screen.
like zircher said, all the images are shown in a single loop. i'm not sure how to correct this without causing a hickup the the game flow or loss of fps (more than 1-2 frames). thoughts?

PC Specs: AMD 1800+ 512M DDR, Radeon 128meg DDR - DB v1.13

To DB or not to DB............duh DB!
Retro Addict
20
Years of Service
User Offline
Joined: 12th Feb 2004
Location: Georgia, USA
Posted: 24th Jun 2004 06:12
sorry make that "varified" and not "varied".

PC Specs: AMD 1800+ 512M DDR, Radeon 128meg DDR - DB v1.13

To DB or not to DB............duh DB!
SandraD
20
Years of Service
User Offline
Joined: 30th May 2004
Location: Down on the corner, out in the street.
Posted: 24th Jun 2004 07:38
Yeah, you're not SYNCing between pastes in that loop...
try something like;

explosion:
for i = 1 to 15
paste image i,x,y
sync
wait 100
next i
return

Any truly great code should be indisguishable from magic.
Retro Addict
20
Years of Service
User Offline
Joined: 12th Feb 2004
Location: Georgia, USA
Posted: 24th Jun 2004 15:43
SandraD - I'm at work so I can't try this at the moment, but that is a subroutine that I gosub too when needed. Can I sync within a gosub'd routine and then sync again in the loop??? Won't this effect my fps as well? Thanks for the input btw....

PC Specs: AMD 1800+ 512M DDR, Radeon 128meg DDR - DB v1.13

To DB or not to DB............duh DB!
zenassem
21
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 24th Jun 2004 17:34
Mike,

Follow what zircher said in his post.

The snippet that SandraD provided is good for testing purposes only. While it will work, it will cause problems for you if you try to incorporate it into any type of game.

You want to avoid having nested "sync loops" inside your main game loop. Ideally you should only have one sync in your main game loop, (preferably the last command). In your logic you will want to increment one frame of animation per loop.

Here's where the timing issues come into play. First you set your sync rate. Keep in mind that the sync rate doesn't control how fast your game loop is actually being processed. For this reason it is important to make sure your logic (or loop) is only processed once per screen refresh.

Now the last timing issue has to do with the speed of the actual animation (in your example the explosion animation). Each animated object needs it's own timing code.

Here is breakdown of different Timing that has to be addressed:

1- Sync Rate - Setting the sync rate controls how often the screen should be refreshed/redrawn (not 100% accurate). It requires that you have a sync command in your game loop. It is recommended you have only one sync command, and that it be place at the end of your loop.

2- Timing code for the main loop- You need to make sure that the main loop logic is only processed as fast as the screen refresh. If you do not, it is likely that your logic will be processed more times then you are refreshing the screen. In a case where your incrementing the animation image once per loop, this would cause you to miss certain animation frames.

3- Timing code for the specific animation- Now that you have your refresh rate and have your game loop in sync with eachother, it is important to control the timing of each spefic animated sprite/image. The reason is: you may need some objects to run through there animations at a faster or slower rate than other objects. For example: it 's possible that an explosion animation has 12 frames that should be processed in say 1 second of game time. It's also possible that another object has 12 frames of animation but it should be processed in 2 sedconds of game time.

Final Thoughts
As jetmech pointed out, for certain animated sprites it is easier to use the play sprite commands. As long as your srite animation goes through each frame without changing order. This would seem to work in your case.


zircher
21
Years of Service
User Offline
Joined: 27th Dec 2002
Location: Oklahoma
Posted: 24th Jun 2004 19:39
Good post, zenassem. As a general rule, you only want one sync at the end of the main loop.

In the case of the drawing subroutine, you could add a play animation flag and have it display one frame each loop incrementing the frame counter and setting the play animation flag to zero when you're done. Twelve frames of animation would play in 333 ms at 36 fps. You could easily double that by playing the same frame twice before moving to the next image.

This works fine when you only have one explosion going on at a time. With multiple explosions, you might be better served by playing sprites even though that is more complex than what you have right now.
--
TAZ

History did not begin with PONG. -- Greg Costikyan

Game Beavers
Retro Addict
20
Years of Service
User Offline
Joined: 12th Feb 2004
Location: Georgia, USA
Posted: 25th Jun 2004 00:58
Zenassem/Zircher: I follow what you're saying, but I am not certain on how to implement. Do you know of an example I can draw from?
Here's some simple code I threw together that shows what I'm trying to do. It's just a cone hitting a sphere and when that happens I'd like an explosion (made with ExGen) to occur...Clear as mud?

` Explosion test routine

hide mouse
sync on
cls

` Startup variables
x1=50
y1=0
z1=0

` Load explosion pics here

` Make player
make object cone 99,5
yrotate object 99,180

` Make object for player to collide with
make object sphere 98,10
position object 98,50,50,0

` Set camera position
position camera 60,45,-80
point camera 60,45,0

set global collision on


` Main Loop
do
set cursor 0,0
print "FPS: ",screen fps()
set cursor 200,0
print "Use ARROW KEYS to move"

` Player controls
if rightkey() then x1=x1+1
if leftkey() then x1=x1-1
if upkey() then y1=y1+1
if downkey() then y1=y1-1
if fire = 0 and spacekey()=1 then fire = 1: bx=x1:by=y1+3:bz=xz

` Keep player on screen
if x1>120 then x1 = 120
if x1<0 then x1 = 0
if y1<0 then y1=0
if y1>90 then y1=90

` Check for player hitting object
if object collision(99,0)=98 then set cursor 450,0:print "Collision"
` set explosion routine here

` Update player\meteor location on screen
position object 99, x1,y1,z1

` Keep camera in same position
position camera 60,45,-80
point camera 60,45,0

sync
loop

PC Specs: AMD 1800+ 512M DDR, Radeon 128meg DDR - DB v1.13

To DB or not to DB............duh DB!
zircher
21
Years of Service
User Offline
Joined: 27th Dec 2002
Location: Oklahoma
Posted: 25th Jun 2004 01:11 Edited at: 25th Jun 2004 01:16
try this...

The code sets the flags, called the animation routine, and resets itself when done.



Note that the flags are set when there is a collision. I have not done anything to remove the collision on subsequent runs through the loop. You can either add flags to stop testing or perhaps change the collision check to only happen when playAnimation = 0.
--
TAZ

[edit for typos]

History did not begin with PONG. -- Greg Costikyan

Game Beavers
Retro Addict
20
Years of Service
User Offline
Joined: 12th Feb 2004
Location: Georgia, USA
Posted: 25th Jun 2004 05:13
zircher: I understand what the code is doing and with a little modification, I have implemented it to do what I'm after...However, the explosion images are not pasting in the proper x,y position as my object "explodes". They are pasting in the top left corner. If I increase the x,y values, it moves some, but still doesn't cover my object. Is this because the image is 2d and I'm pasting in a 3d environment? Thoughts?

Regardless, this was a HUGE help!

PC Specs: AMD 1800+ 512M DDR, Radeon 128meg DDR - DB v1.13

To DB or not to DB............duh DB!

Login to post a reply

Server time is: 2024-09-22 14:33:01
Your offset time is: 2024-09-22 14:33:01