How would I be able to do this? I plan on having a class with every single image in my game, and then using that to carry out what i need done in each class. I don't need code, a simple answer is fine (Code would be appreciated though).
Related
Let me explain,
Theirs a plugin (video game mod) I want to make to add things to Another plugin (a different mod) but I don't want to change anything in the plugin I'm not making. But to add the stuff I want, I'd have to add some variables to some arrays in a certain class, which I could totally do form another class but Their finalized, and all the spots are taken.
SO after looking into how final variables work (i kinda guessed) I though it might just be easier to
make a copy of the class in question, put it in my plugin, change the variables so their not final, and... OVERRIDE the original class when the program starts... some how.
Ok not easy, but that was the only thing that came to mind, where I still didn't edit the original files, and my plugin could be removed and added without changing anything.
I've looked into Classloaders and something someone called a patching assistant (it implements ClassFileTransformer) but I have no idea what I'm doing. SO I thought I'd post what I'm trying to do on here and see if anyone had any advice, I'll keep trying to figure out whether a class loader or patching assistant are viable for what I want in the mean time.
Thanks in advance!
You can do this with reflection:
http://java-performance.info/updating-final-and-static-final-fields/
Although it's probably not such a great idea - these fields are final for a reason.
I am trying to write code for my latest class assignment where we create a Harness Record System, the code needs to keep track of Harness's in a system, be able to create new Harnesses and edit/loan/check old ones. I have gone down the route of using a GUI rather than the console as it is easier for the user to use. Although, I'm having trouble coming up with ideas on how to write code that differentiates old Harnesses written into the code, with new Harnesses that overwrite the previous input of the user.
So my question is, is there any way to write a code that can create objects once the user clicks a certain button, so that when that button is clicked the information inputted by the user into that object comes up, rather than just the most recent input of the user.
I know this is a silly and badly worded question, but my brain is just fried at the moment, I'm in need of help.
My code is below, I'm using two different classes and the SWT kit, if anyone could have a look at my code and help me out I would be so grateful, really struggling to find a way to overcome this:
Harness Class: http://pastebin.com/HqJqGfTN
HarnessSelection Class: http://pastebin.com/EE4C2WCs
The 'new' keyword is how you create new object instances. I haven't read all of your code but make sure you understand what the 'static' keyword does - it makes all instances of that class share the same value for that field. Perhaps all of your harness instances are sharing the same static variables.
i was wondering if it would be possible to have one central class just for images. Also, how would i use an image from one class in another? I couldn't find the answer to this at all, on other sites. I'm sorry for this dumb question, but i'm fairly new to programming, and the loading of images and sprite animations is what frustrates me the most, and i won't be able to advance to anything else, unless i get these kinds of problems out my head! Thank you for everyone that helps!
create a new object in clasee and using this object to invoke the function
also you can set class as static class
Hey guys I'm new to programing and I'm just gettin into UI design.
There are some things I've gotten so far, like I should only use a JFrame per application and other guidelines like that. What I don't understand is... what is the proper way to join your business logic with the GUI?
What I mean is, let's pretend I've just created an application that runs on console (or whatever), and I want to create a GUI for it, so, I've seen on the net that people create a JForm-derived class as a main class and that's it. But is this the proper way? I would like to keep my original "Main class" (the class that uses every other class I've created for my project) and define the form as a field of it, something like that.
Is it possible? If so, how can I achieve this? I have all my logic on that main class I just talked you about, so when I instantiate the form inside of it, I don't know how to make the form use and alter the fields and use the methods I defined in the main class (Sorry if I'm not making myself clear).
How you do, experienced people, do it? What is the "good practice" way? Thanks for taking your time and sorry if it's a noob question.
I'm no professional but I can't stand working with JFrames and Graphics objects.
Most of the time I use the lwjgl library. I know this library is for games but It is
great for UI's as well. The reason it is so easy is because you simply give buttons their
X and Y coordinates without having to worry about layouts. You can make your own images and
import them easily, so if you want your button to look like an image you created no problem.
Because it is made for games it is also very fast and fluid.
This may not be the best way but it works for me so I thought I would share anyway.
Hope it helps.
Here is the lwjgl website: http://www.lwjgl.org/
Here is a video series that helped get me started: http://www.youtube.com/watch?v=0v56I5UWrYY&feature=c4-overview-vl&list=PL19F2453814E0E315
Paranaix already mentioned in his comment about the model - view - controller architecture.
I mostly construct Java Swing GUI applications.
I build the model first. This could be considered a "first cut", since I update the model as I construct the view.
Next I build the view. I construct all of my Swing components by hand. I find that GUI builders harm more than they help. Building the view usually causes me to modify the model.
Finally I construct the controller.
Here's a more detailed description of how I put together a dice game from my blog.
I am trying to use the AssetManager class in LibGDX and I understand how it works but I am trying to implement a loading screen. I have followed the AssetManagerTest.java file here,
but I am having a hard time trying to figure out how to get it to work correctly. Can someone point me in the right direction? My goal is to load the assets (textures, sounds, fonts, ... etc) and update a bar with the percentage complete on the screen. I don't understand the ResolutionFileResolver and the Resolution[] in the link I provided. What are they for? My goal is to support a static class that can give me access to all of the assets I need in my game from any screen. Is there a preferred method to do this? Thanks.
After looking at the source for ResolutionFileResolver as well as the other 'resolvers', I think it's just a way of loading textures that best match the screen resolution, but the match is just based on filename patterns.
So in AssetManagerTest, he's got textures for screen sizes 320x480, 480x800, and 480x854. It looks like each group of textures should be in a directory called ".320480" or ".480800" or ".480854" (although the name can be anything you want, like "low", "high", and "wide" if those are your directories), and he specifies all this info when creating the array of resolvers on line 56 of the test.
The advantage of doing all this stuff is that when he calls manager.load(), he just picks out a filename like "data/animation.png". Then the resolver finds the pack of textures that most closely matches the current screen resolution, and loads that one.
I think the rest of the example should be pretty clear, at least for the basics of AssetManager. Create a manager, set the loader, call load(), call get() to use it, and then call unload() when done.
For updating a progress bar, you'll just need to do that manually after each call to load.
And using a static class for asset management is certainly one possibility. Another similar option is to just use a singleton. It has its haters, but I think in a simple project in a garbage collected environment it should be ok, although it's about the same as a public static.
Another option--maybe the best?--is to use a base class that has a static copy of your game globals, and then all other game classes inherit from it. This is the approach used in Replica Island. See the base class and the object registry. Replica Island is well commented and worth checking out for Android & Java games.