Syntaxus Dogmata

An Insane Developer's Journal

Spritely Sprites in Spriteland

The last quandary I’m slated to tackle is the whole cascading effects feature I’ve wanted for VertX.  See this post I made several days ago for details.  Originally, I was ruing the task of getting all of that working in VertX, but now I’m not so sure it’s going to be the chore I was expecting.

What I’m discovering now is that I don’t have much cascading left to do in the hierarchy, really.  My initial thought was to have sprite objects able to contain other sprite objects, but after thinking about it, I’m coming to realize that such a thing would be overkill for what I want to do with sprites.  Instead, I’m leaning toward having sprites contain multiple graphics (Texture2D objects), and manipulating them during the sprites’ Update() and Render() cycles.  That way their locations and transformations can be relative/cascaded or not as the game developer chooses.

So, in the time it’s taken me to get to this cascading effects issue, I’ve removed the Widget class from the hierarchy, added the Frame class, and decided that sprites don’t need to contain other sprites.  These three things together has made cascading effects something of a non-issue.  All I have left to do, really, is create a sprite with multiple textures, and voila!  I’m in business.

Once that’s done, I have a decision to make.  I could proceed to work on the Animation class, which is pretty exciting and a big leap toward making VertX’s a viable game development framework.  I’m tempted, however, by the prospect of working on Tetris again.  I’m in this to make games, after all, not merely to make an XNA-based framework for game development.  Tetris wouldn’t require any animations (that I can foresee right now), so this is an opportunity to actually put my framework work to work and make it work.

Yeah, that sounds more appealing.  I’ll extend VertX as needed with future games that are more sophisticated.

Apr 17, 2010 Posted by | VertX™, Video Games | , | Leave a comment

Frames Are On!

I finished the introduction of Frames into VertX.  They work great, and the Screen class has been refactored the way I described in my last post.  Screens became so simple, in fact, that I wondered if I hadn’t made a huge mistake and turned it into something of a vacuous class.  But looking at it now that everything’s working, there’s enough functionality there to justify its existence, I think.

As I worked, the thought occurred to me about how adding frames affected things like collision detection and mouse clicks in the future.  VertX doesn’t feature such things right now, but it will fairly soon, and I couldn’t help but wonder if adding frames into the hierarchy wasn’t unwittingly sabotaging such matters.

I figured collision detection wouldn’t be a problem, as long as I made it a rule that sprite collisions would only be detected between sprites in the same frame.  Implementing this rule would make frames quite useful, in fact, as they would separate out the sprites whose collisions I don’t care to detect from those sprites whose mutual interaction I do care about.

Mouse clicks, on the other hand, nearly made me reconsider what I was doing with frames.  Every time the player clicks somewhere on the screen, I have to figure out what it is the player is clicking at.  It’s a form of screen-wide collision detection that transcends all sprite layers — including any frames that happen to overlap at those screen coordinates.

Obviously, this already violates the rule I established two paragraphs up, and I don’t envy the poor bastard (me) who is responsible for writing the algorithm that works through all the frames and sprite layers in order to serve up the sprite that was clicked… if any!  Not only that, but it must do so in a manner that doesn’t severely impact performance for that game cycle.  How would it look if every time the player clicked the mouse, the game froze for an eighth of a second just to figure out what it was they were clicking at?

If you’re waiting for ol’ Syndog to pull a proverbial rabbit out of his hat with some slick mathematical solution coupled with a brilliant coding twist, expect to be waiting a while.  I get the feeling the solution to this problem will require a lot of experimentation and trial & error engineering to pull it off.

But just because my hat is bereft of all lagomorphs in this matter, that doesn’t mean I don’t have a few tricks up my sleeve.

The first is a flag I’ve already implemented the Frame class, labeling it as mouse-sensitive.  If there are no “clickable” sprites in a particular frame, then there’s no reason why the mouse click algorithm should consider that frame at all.  That alone can cut out a huge number of sprites from the process of elimination.

Another idea I had was to make only one frame mouse-sensitive at any given time, which would narrow the field even further, but I think that’s too impractical a limitation to place on the game developer.  When it comes to the organization of their sprites among the screen’s frames, I want them to have as much liberty as possible.  Mouse sensitivity will certainly affect the way they organize their sprites among the frames, but I don’t consider it overly restrictive, as having only one mouse-sensitive frame would be.

One way or another, I’ll work it out.  Who knows?  Maybe I’ll get lucky, and the process won’t be all that intense to begin with, and I’ll find I was concerned over nothing.  Were I a gambling man, that’s not the way I would bet, but stranger things have happened.

Apr 17, 2010 Posted by | VertX™, Video Games | , , | Leave a comment