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! / Unknown Image Error

Author
Message
Swampert
15
Years of Service
User Offline
Joined: 17th Dec 2008
Location: Somewhere in the Interwebs
Posted: 18th Dec 2009 01:34
While attempting to use GET IMAGE to get a bullet created with the BOX command, the program compiles perfectly but when I fire the bullet, it gives me a runtime error.

The error trace reports that it is coming directly from the GET IMAGE command. I checked to make sure I didn't miss any parameters and such but... What should I do

Ashingda 27
16
Years of Service
User Offline
Joined: 15th Feb 2008
Location:
Posted: 18th Dec 2009 07:18 Edited at: 18th Dec 2009 07:18
Are you using DBC or DBPro?

If you're using DBC you may have to sync sometime after you get/load the image and befor you start to use or modify it.
Swampert
15
Years of Service
User Offline
Joined: 17th Dec 2008
Location: Somewhere in the Interwebs
Posted: 18th Dec 2009 13:14 Edited at: 18th Dec 2009 13:17
I'm using DBP and that doesn't seem to be the problem
Van B
Moderator
21
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 18th Dec 2009 14:18
That function is crazy!

Firstly, don't grab an image like that, because you only need to grab it once - at the start of the program. So grab your image, then when you want to fire a bullet, use a function for that. But, don't use DO LOOP inside your function.

Really, what you are doing is grabbing a bullet then going into an endless loop, updating the bullet and deleting it when it gets past a certain position - THEN - you are still in the same loop, and the next time it tries to delete the bullet, it's already deleted - so you get that error.

It's not a good way to handle bullets mate - use a typed array to track all the stuff you need, and use a bullet update function that steps through all the bullets and handles them - plus a function to 'birth' a bullet is a much neater way to work. I don't think you'll get far with that method.

So...

Grab your bullet, or draw it in an art package and load the image instead.
Use an array to track the position and speed of each bullet, and a seperate sprite for each (or paste image, which might be neater for 2D).
Make a function to 'birth' a bullet, setting it as active and setting the speed and position etc.
Make a function to update the bullets, stepping through them all and updating them all if they are active.
Use the DO LOOP and call the birth function when you need it, and call the update function every loop - before the sync.


Health, Ammo, and bacon and eggs!
Swampert
15
Years of Service
User Offline
Joined: 17th Dec 2008
Location: Somewhere in the Interwebs
Posted: 18th Dec 2009 15:31
Ah. Ok. I understand most of that but can you give a better description of how the arrays should be set up and the function to update them? By updating as active, do you mean to create a BULLET type?
Van B
Moderator
21
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 18th Dec 2009 16:27
Yeah, decide on how many bullets you need, and make a typed array to store that info, plus store the state of the bullet. Then you can re-use your bullets, what you'd actually be doing is setting how many bullets are active at once.

Type Bulletype
x as float y as float z as float
xs as float ys as float zs as float
state as byte
Endtype
Dim bullet(128) as bulletype
global bullet_cur
Something like that. Then you would step through bullet() in the update function...

Function bullet_update()
for b=0 to 127
If bullet(b).state=1
inc bullet(b).x,bullet(b).xs
inc bullet(b).y,bullet(b).ys
inc bullet(b).z,bullet(b).zs
if bullet(b).x>640 then bullet(b).state=0
position object b+100,bullet(b).x,bullet(b).y,bullet(b).z
endif
next b
Endfunction

3D I know, but you could easily make it 2D, just ignore .Z.

Each time you fire a bullet, you would increment the bullet_cur global, and if that exceeds 127 then reset it to 0 - this would recycle your bullets, but you have to balance and be careful that you have enough bullets for the fire rates. Anyhoo - to fire a bullet with this sort of system, just set it's position and speed, then set it's state to 1 - and it'll get updated with the bullet update function.


If your still not getting anywhere, I could make a little example for you, no worries.


Health, Ammo, and bacon and eggs!
Van B
Moderator
21
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 18th Dec 2009 17:37
Here's a little example, uses paste image - but could easily be changed to objects or sprites - thing with paste image is that you can avoid having to manage the residual media. Like if you use sprites, you'll have to delete or hide them, same with objects, but paste image is an instant thing. You could also paste a sprite - which is very handy if you decided to rotate the bullet sprite to suit the direction, allows for nicer bullet textures, rockets for instance.




Health, Ammo, and bacon and eggs!
Swampert
15
Years of Service
User Offline
Joined: 17th Dec 2008
Location: Somewhere in the Interwebs
Posted: 19th Dec 2009 12:49 Edited at: 19th Dec 2009 13:15
You sir, are a genius.

(Seriously, I like the way you think. I need to start studying the things you say more.)

Is this how all systems such as bullets and character stats should be done? By updating with typed arrays?
Ashingda 27
16
Years of Service
User Offline
Joined: 15th Feb 2008
Location:
Posted: 19th Dec 2009 17:32
It doesn't necessarily have to be a type, you just need some sort of variable, it's up to your preference.
Van B
Moderator
21
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 20th Dec 2009 01:38
Glad to help Swampart. Typed arrays are really more of a convenience, some people don't use them and prefer to use several seperate arrays instead. Personally I like the neatness it can instil in code layout.

Storing the basic parameters in a neat type is really handy, the same system for example would be good for particles. Types can contain as many elements as you like, they can also be assigned to variables too. So you might have a type for characters, with variables for health and stuff like that - but if you want to have the player data handled through a global, then types are great for that. When a games in the early stages, often the data will change, and certainly more data types are needed - if you use types, then it makes that a lot easier. You only have to add a new variable to the type for instance, instead having to handle another array.


Health, Ammo, and bacon and eggs!

Login to post a reply

Server time is: 2024-03-29 13:33:21
Your offset time is: 2024-03-29 13:33:21