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 / Sprite spawning, killing sprites and background issues

Author
Message
Deego
16
Years of Service
User Offline
Joined: 21st May 2008
Location:
Posted: 21st May 2008 22:55 Edited at: 21st May 2008 23:57
As my first coding project, I'm making a simple 2d game where sprites fall from the top of the screen, and by clicking on them, they disappear and a score is tallied.

Since I want to be able to have the sprites detect a mouseclick and be destroyed by it, I realized I couldn't make my background a sprite without nuking it on a click. [EDIT: This has been fixed since posting]What's the best way to set a background without it being a sprite?

Also, clicking on a descending sprite in this code crashes the program with "runtime error 302 : sprite does not exist at [its line]." This is probably because of the way I set up my sprite spawners, which either creates only one sprite or all ten sprites in one spot. How would I go about creating a sprite spawner that takes a sprite and copies it to a random location? Is there a better way to kill the sprites than with the mouseclick system I have? And how do I get everything working together?

Thanks for any help.

Ed222
17
Years of Service
User Offline
Joined: 3rd Nov 2007
Location: Calgary
Posted: 22nd May 2008 01:41
you need to include the media for other people to play it.
Quote: "set a background without it being a sprite?"

load the background image and use the paste image command in the loop

Deego
16
Years of Service
User Offline
Joined: 21st May 2008
Location:
Posted: 22nd May 2008 02:22
Here's the latest version of the code, and an executable with the files if someone wants to see for themselves. The graphics are temporary until I actually have a working game.



I'm good with using and placing images now, but I'm still having trouble setting up a random xpos for the sprites (they all bunch on the same location) and spawning the sprites. And now, for some reason, the sprites don't move any more.

I can set up individual sprites, but it's not very practical to have 30+ individual sprites coded when I should be able to set up some sort of cloning/spawning system using 3 or so sprites for many enemies.

Any help is appreciated.

Attachments

Login to view attachments
pcRaider
17
Years of Service
User Offline
Joined: 30th May 2007
Location:
Posted: 24th May 2008 07:12 Edited at: 24th May 2008 13:27
The first code is good.
The second code is bad.
You should test it with a smaller code.
Do you know an array?


Do you use an old version of DBP?
Deego
16
Years of Service
User Offline
Joined: 21st May 2008
Location:
Posted: 25th May 2008 03:35


I'm trying to create an array of sprites that I can call up on my sprite spawner. I'm just learning arrays, so is it possible or necessary to store sprites like this? I get an error saying "cannot define parameter of sprite P"

I use the newest version of DBP. Thanks for help.
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 25th May 2008 10:41 Edited at: 25th May 2008 10:44
An array can only store a single value of the type declared in each 'cell'. In your case, 'viri' is an integer.

Sprite is a command not a function so it returns no value to actually store in your integer array - hence the error.

In this case, the only real use for arrays is to store the X and Y screen position of the sprites:



If you need any further info on any of the different types of arrays in DB, check out tutorial 1 here:

http://forum.thegamecreators.com/?m=forum_view&t=99497&b=10

TDK_Man

Deego
16
Years of Service
User Offline
Joined: 21st May 2008
Location:
Posted: 25th May 2008 23:13 Edited at: 26th May 2008 00:17
That's a fine piece of code, TDK, fixed my problem right up. I've actually learned most of what I know so far about coding from your tutorials, they're great.

[EDIT]I want my sprite spawner to delay before releasing the next sprite.



As you can see from my note, trying to make the program wait until performing the next P results in the screen turning black and nothing else happening.

I'm actually kinda sad that a wait function doesn't work in a for/next procedure. It seems so intuitive. So what's the best way to delay each cycle?
Deego
16
Years of Service
User Offline
Joined: 21st May 2008
Location:
Posted: 27th May 2008 02:55
My first goal with programming is to make gameplay, and my only problems on this front, for this game at least, is being able to delay each sprite's descent, and make it so clicking on a sprite will destroy that sprite, and only that sprite.

At least I figured out the timing on my own. Instead of trying something like this:



I'm doing this:


To change when the sprites appear at the top of the screen, I just need to modify my ystart array. Space and time are related, dude

Anyway, all I want to know now is how to differentiate between my sprites on a mouseclick() event, or any event, really. The one I have set up now affects all the sprites, and even if I set up Delete Sprite P in the "if s<>0 then...", it will delete all the sprites and then when I move off the sprite they all reappear (due to the RefScreen gosub). How do I make only the sprite I click on disappear? How do I target specific sprites in a code like this?

My code so far, for reference.


I'm liking coding more and more as I learn. I look forward to the day when I can be helping people instead of asking for it.
pcRaider
17
Years of Service
User Offline
Joined: 30th May 2007
Location:
Posted: 27th May 2008 20:35
HIDE SPRITE p
Deego
16
Years of Service
User Offline
Joined: 21st May 2008
Location:
Posted: 27th May 2008 22:45
That works, heh. I remember reading in the help files that come with DBPro that you should delete sprites when you're done to make the program run faster, and trying to delete one of these sprites results in a crash. Also, you can still click on a hidden sprite, but I guess I can set up something that takes away any effect that sprite may have had (adding score, damaging the city, etc.) once you click on it.

Thanks for the help!
Deego
16
Years of Service
User Offline
Joined: 21st May 2008
Location:
Posted: 27th May 2008 23:00
I had a system before that included "delete sprite P" that would make every sprite on the screen disappear, I figured it would be the same for "hide sprite P." But it isn't! Thanks for the help!
pcRaider
17
Years of Service
User Offline
Joined: 30th May 2007
Location:
Posted: 28th May 2008 08:55
delete sprite ?
ok
this one.


Please attach the media.
Deego
16
Years of Service
User Offline
Joined: 21st May 2008
Location:
Posted: 28th May 2008 23:55 Edited at: 29th May 2008 04:27
All your help has been great, guys. The gameplay for my first project is nearly done. A weird bug arose, however. Whenever I click the mouse, all the sprites slow down to the starting speed, when they should be incrementally faster.



I want to do something so that when the mouse is held down, it doesn't keep executing my mouseclick()=1, so the player actually has to click on each one. I actually am making this game like a Wii game. I'm controlling it with a laser pointer that works like a mouse, and each mouseclick fires the laser, just like pulling a trigger. The crosshair is to help calibrate this, and to show the player where they are hitting on the screen.

Images attached this time, along with the code so you don't have to copy and paste. Sorry for forgetting so many times.

[edit] I just implemented sprite exist(), so much better than shrinking, hiding, and rotating my sprites. Thanks!

Attachments

Login to view attachments
Deego
16
Years of Service
User Offline
Joined: 21st May 2008
Location:
Posted: 29th May 2008 05:19
OK, nevermind about that post, I'd be able to edit it if I wasn't such a newbie that I can't see it right now. I fixed both problems with a function that differentiates when a mouse is clicked and when it was held down. The game plays great, and all I need to do now is create 3 images (start screen, bad ending screen, good ending screen), and maybe spice up the graphics a bit. I want to make the sprites explode when shot and glow when they hit the city, which would involved animated sprites, something I'm sure I can find a lot of information about on these forums.

Thanks for the help, and if anyone wants to see the final project, just say so and I'll upload it.
pcRaider
17
Years of Service
User Offline
Joined: 30th May 2007
Location:
Posted: 30th May 2008 13:45
You must use "Sync Rate 60".
Because so that even other PCs get the same result.
60 is a good value, and most displays use it.

Login to post a reply

Server time is: 2024-11-25 23:36:41
Your offset time is: 2024-11-25 23:36:41