forums

TNT Basic Forums > Programming Q&A
Couple Questions
< Last Thread     Next Thread >
Author
Thread        Post A Reply

12-12-2001 06:58

Posted by:
Tony Rose

Click Here to Email Tony Rose   Find more posts by Tony Rose

Hey,I just want to start by saying,I LOVE TNT! It really rocks,I am learning it very fast and since I love to design this really rocks. In two days I have a sidescrolling game w/ a controlled WWII aircraft. Id like to evolve this into a great shoot-em-up game but I have a few questions. First,I figured out how to make my plane shoot bullets,but the problem is,It wont shoot off another sprite until the first one is turned off,this makes it hard for me to make a machine gun fire effect. How would I make the sprites fire out rapidly and not every second or so? Another thing,I like the idea of the built in map editor,but it seems to bring my framerate to hell with a fairly large (several screens in width) map. So far I am just using one large picture and having the viewport scroll it,this is fine,but could someone explain why my FPS goes to 20-30ish on my 400mhz G3 on these simple maps? Please reply,I cant wait to get some good machine gun fire! (I am registering soon,only 15,so cash is hard to come by)

Thanks!

Tony Rose aka Muzein

12-12-2001 07:37

Posted by:
Socrates

Find more posts by Socrates

Machine gun fire

If TNT had data encapsulation this would be a lot easier, but what you do is make an array of X and Y coordinates for your bullets and a variable to count how many are in play at a time. Then every time the player fires you increase the bullet count and make a new sprite that uses the next set of cooordinates in the array. Then you have a loop from 1 to the number of bullets that updates all the bullet coordinates (moves them right presumably), and then every time one goes off screen you delete that sprite and reduce the bullet count. If the bullet count reaches maximum (the size of your X and Y arrays) then you either have to redim the array, or just not let the player fire again until some bullets have gone off screen. An array of say 20 bullets is probably more than enough, but it depends how big they are and how fast you want them to move.

Please TNT, give us classes so this kind of problem can be solved a bit more easily instead of being the nightmare it is now. Bump it up to top priority, even Quicktime should be low priority by comparison.

Just for your information Tony, with classes you could make an array of bullet objects and the bullets would handle stuff like moving, colliding and moving off screen themselves. All you would have to do is call them each with an update method or something similar. Campaign for data encapsulation in TNT!

12-12-2001 10:56

Posted by:
Mark Tully

Find more posts by Mark Tully

Drawing maps

Hi Tony,

If you're completely redrawing the map every frame that might slow things down, are you doing that?

You can either only redraw the map when it needs to scroll, or you could open a huge canvas and completely render the map before you start, then the code would be the same as it is for scrolling the picture.

Hope this helps!

12-12-2001 22:02

Posted by:
Tony Rose

Click Here to Email Tony Rose   Find more posts by Tony Rose

Thanks

Thanks for that bullet system,I now have some pretty darn good bullets setup. One question I have,I cant seem to be able to make a sprite not scroll with the screen. Even if I just post the coordinates i,e. sprite 1,123,123,001 the sprite scrolls along at the same speed as the viewport. I want the sprite to sit still so I can scroll over it (Transparent clouds to fly through). Oh and I noticed the program says it supports anti-aliased sprites,How does this work,can TNT actualy anti-alias my sprites in-game?

12-12-2001 22:18

Posted by:
Socrates

Find more posts by Socrates

Scrolling, etc

Your scrolling problem is due to the canvas in which you are drawing the sprites. The screen is constructed from canvas 0, so put the sprites in this canvas to ensure that they don't move when the background scrolls. Alternatively, if this is inconvenient, just add the scroll factor to all sprites every frame to counteract the scrolling effect - if your viewport scrolls right 10 pixels every frame, add 10 to the x coordinates of all sprites every frame.

As for antialiased sprites, TNT can't antialias them for you, but it can use a translucent mask. This means you'll have to draw a greyscale mask that has smooth transitions from black to white around the edges of your sprite. This can be done in Photoshop, and most 3D rendering packages will do it for you if your sing rendered sprites, but I'd guess this is a little tricky if you've never done it before.

Alternatively, you could try using the FX matrix to antialias the whole screen, but I'm not sure how fast this would be. If you apply a matrix something like

0.1, 0.1, 0.1
0.1, 0.2, 0.1
0.1, 0.1, 0.1

it might work, but I haven't tried it and I'm not sure if that's right, or how fast it would be, you'll probably have to play around with the values or it might just end up a blurry mess. Perhapse One of the TNT team could comment on whether this is viable...

12-13-2001 12:31

Posted by:
Mark Tully

Find more posts by Mark Tully

Anti-aliasing

As Socrates points out, the anti-aliasing of sprites is achieved by using a translucency mask with soft edges. That makes the edges of your sprite on screen be slightly translucent, effectively merging it slightly with the background and removing the sharp contrast between the sprite and background - effectively anti-aliasing your sprite.

Creating the masks is a job for photoshop! I can't remember how (I have to figure this out every time I use photoshop) you can copy the greyscale translucency mask from a layers mask and use that. I would use anti-aliasing only on the larger sprites, because it does slow things down slightly. I wouldn't use it for your bullets.

You can read more about this in the "Changing the Image Mask" section of the user guide.

As for the FX Matrix routine, this routine is slow - sorry. We never intended it to be good for real time use, more for preprocessing graphics/sprites before you use them. Also, it is applied to canvases, but as with all drawing commands, it will not affect the sprites because they are drawn on as the frame is drawn to the screen (ie inside the draw frame command).

Your matrix looks good though, although you needn't bother with floating values, the matrix is automatically normalised.

Here's one I use for a light gaussian blur, load an image up, read these values into an array and pass them to FX Matrix:

' light gaussian blur
Data 0,1,0
Data 1,2,1
Data 0,1,0

Some others to play with are:

' Heavy defocus
Data 1,0,0,0,0
Data 0,0,0,0,0
Data 0,0,0,0,0
Data 0,0,0,0,0
Data 0,0,0,0,1

' Find Edges
Data 0,0,-1,0, 0
Data 0,0, 0,0, 0
Data -1,0, 4,0,-1
Data 0,0, 0,0, 0
Data 0,0,-1,0, 0

' Emboss
Data -10,0, 0
Data 0, 5, 0
Data 0, 0, 10

But as I stated, these aren't fast enough for real time effects and they will not affect sprites (although they will affect images pasted onto the canvas with "paste image").

Have fun!

Mark

12-13-2001 14:07

Posted by:
Mark Tully

Find more posts by Mark Tully

Example posted

I've just posted a FX Matrix example in the downloads -> examples section of our site. It demos all the effects above - check it out!

Mark

All times are GMT        Post A Reply

Forum Jump:
< Last Thread     Next Thread >

< Contact Us - TNT Basic >

Powered by: vBulletin Lite Version 1.0.1 Lite
Copyright © Jelsoft Enterprises Limited 2000.