• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
destructivArts

Standardizing Frame Rates and Handling Objects

4 posts in this topic

I'm writing a 2D platform game engine in Java using the awt package. (its pretty basic right now)
I have everything set up in a class that extends JPanel, so I'm using the paintComponent method to draw graphics on screen.
The class also implements Runnable, and I'm using a thread, which sleeps for a constant amount of time, to keep frame rate.
My first problem, however, is that the image keeps flickering randomly.
I looked up ways to solve this, the first being to Double Buffer, which I have successfully done. I use a separate method to load all the graphics onto a BufferedImage with Graphics2D. While this helped, it still flickers quite a bit.
I also read on the Java API that the repaint() call will be processed as soon as possible. I guess this means that it won't always happen immediately.
[b]So my first question is: How would I rewrite, or create a new, paint method that I can have executed immediately?[/b]

My second question deals with handling my game objects.
Everything that appears on screen that the player can interact with in some way (platforms, enemies, doors, etc.) is a child class of an Entity class. Sometimes, like when the player nears the side of the screen, I need to affect all the objects at once. In this case I need to shift them all. Now, all of these objects are in separate ArrayLists, with one ArrayList for each type of object. [b]Would it be a bad idea to put all the ArrayLists inside a Vector so that I can just loop through the vector and then each ArrayList so that I don't have to call them by name? [/b]My problem here is that I don't know how many object types I'm going to need, and it would be easier to write a general, nested for loop that only has to call the vector by name.

Any help would be greatly appreciated,

Thanks,
Peter
0

Share this post


Link to post
Share on other sites
[quote][b]So my first question is: How would I rewrite, or create a new, paint method that I can have executed immediately?[/b][/quote]
Use a [i]BufferStrategy[/i]. It allows you to "blit" to an off-screen image like you would normally using an API like SDL and doesn't restrict you with Swing's obnoxious threading issues with regards to [i]paint()[/i] and [i]repaint()[/i]. That is, you can [i]flip() [/i]your buffer whenever you like, thus controling the rendering speed yourself (for the most part, but it is an improvement since Swing tends to ignore [i]repaint()[/i] requests at random). Furthermore, the surface is almost guaranteed to be hardware accelerated and Java will handle all the details for you. Here's a simple example: [url="http://gpsnippets.blogspot.com/2010/10/how-to-use-bufferstrategy-in-java.html"]http://gpsnippets.bl...gy-in-java.html[/url]

[quote][b]Would it be a bad idea to put all the ArrayLists inside a Vector so that I can just loop through the vector and then each ArrayList so that I don't have to call them by name? [/b][/quote]
First, a [i]Vector[/i] is just a synchronized [i]ArrayList[/i] so there's not any particular need to use them. If you're having synchronization issues, I'd look at an alternate strategy (synch blocks, copy-on-write, etc.) instead to avoid any potential overhead.

Second, to answer your specific question - not really. I mean, it's not ideal or anything but you aren't going to fail miserably if you do it until you start generating a lot of objects. If it works well enough for you, more power to you.

That said, if you are having issues or want something that's a bit more scalable, I'd look into an alternate partioning scheme such as a basic quadtree or similar. The key issue is that most of those objects [i]don't[/i] move - things like doors and static platforms don't actually change their positions. You can track an offset into your level and compute the "drawing" coordinates from that without needing to store those objects, drastically cutting down the objects you need to iterate over on a per-frame basis.
1

Share this post


Link to post
Share on other sites
Ok, I'll look up the BufferStrategy. Thanks, that sounds exactly like what I was looking for.

On the second issue though, (I'll admit your using a lot of words I am unfamiliar with)
but just to clarify:
- All objects in my game will 'move'. They have an initial x and y position, but when the player moves into a region roughly 100 pixels from the edge of the screen, instead of the player moving, all the objects move in the opposite direction. Because it's not a 3d game, I don't see how I can move a camera that dictates what's on screen. (Although now that I think about it, I can think of several ways I could do just that.)
- The only reason I suggested Vectors is because I know they can hold different data types within one Vector.

I'm relatively new in this area of programming, so I apologize for any misconceptions I have regarding this type of code,
Thank you for your help,
Now... to Google!

Thanks again,
Peter
0

Share this post


Link to post
Share on other sites
I'll admit that I'm not quite sure what a quadtree is, but I think what Kyan is getting at is that if you have a bunch of objects that don't actively move around the screen (such as doors as were his example), then you may be able to have those objects themselves process, in their own code, the camera offset and apply it to their draw position, saving you the trouble of storing them in a container and looping through them whenever the big camera shift function is called.
1

Share this post


Link to post
Share on other sites
Ok, I've implemented the idea of using a camera object to get everything thats on screen. Now i only move the player and the camera when the player nears the edge of the screen. Thank you guys so far, now I have to read up on these BufferStrategies.

Thanks again,
Peter
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0