From some time I have started having following problem. I play the level it loads files through AssetManager and it displays images. I finish the level, it unloads the files. When I play again the level, it only displays fort, player, enemies, bullets but it stopped displaying the rest of the images like ground, background, trees etc, instead it shows me white plain color.
However just right now, instead of getting the textures from AssetManager ground = manager.get("environment/fields_ground.png"); I just changed everything into creating new objects like ground = new Texture("environment/fields_ground.png"); and it doesn't produce this error. I guess there is something wrong or missing.
It actually was just white plain, but when I created ground as a new texture instead of using AssetManager then it happened as on the picture. I don't unload player image, arrows, but I do unload fort, but the problem doesn't seem to affect it. I assume that something is wrong happening with the AssetManager or it fails to properly clear the screen and batch new images. But files are loaded fine, otherwise it would throw errors. It initializes images otherwise there would be errors and it displays images properly for the first time.
I had a silly mistake, which I didn't notice, because I have too many classes to look at. The mistake was that I disposed ground, background and other objects. After I finished the level it called method to dispose these things and then I played level again and it loaded something what was disposed. Therefore, it caused this problem.
Problem was:
ground.dispose();
background.dispose();
textureEnvironment.dispose();
Solution:
Remove these lines of code.
Related
For reference the effect I'm going for is this:
I'm working in Processing 3, NOT p5.js.
I've looked around processing forums, but i can't find anything that works in the current version or doesn't use PGraphics and a mask which from what I've read can be expensive to use.
My current ideas and implementations have resulted to drawing shapes around the player and filling the gaps in with a circles with no fill that has a large stroke weight.
Does anyone know of any methods to easily and inexpensively draw a black background over everything except a small circular area?
If this is the wrong place to ask this question just send me on my way I guess, but please be nice. Thank you:)
You could create an image (or PGraphics) that consists of mostly black, with a transparent circle in it. This is called image masking or alpha compositing. Doing a Google image search for "alpha composite" returns a bunch of the images I'm talking about.
Anyway, after you have the image, it's just a matter of drawing it on top of your scene wherever the player is. You might also use the PImage#mask() function. More info can be found in the reference.
This might be a weird question but what is the right way to think about how images are projected onto the screen?
if we have an image already on the screen and we render another image onto the screen does the new image go ON TOP of the old one, thus making the old one not visible anymore. or does it go behind the old one thus making the new one not visible till we clear the screen off of the old one.
I used to think that the new image goes on top of the old one, however, after working with buffers for a little bit (ie BufferedImage and BufferedStrategy) I come to think that is not the right way it happens.
so can someone please clarify this matter
thanks
Generally speaking, you can think of it like a painters canvas. Every time you paint something new you are painting over the top of what is there.
When dealing with buffers, the process is the same, but know you are dealing with whatever was painted last to THAT buffer.
So if you have three buffers, [1] is on the screen, you are painting [2] which gets pushed to the screen, it doesn't have the content of [1], but what was ever painted to [2] when it was painted last...
So you have [1][2][3], then you have [2][3][1], then [3][1][2]. Each buffer will be out of date by at least two paint cycles.
This is why it's important to clear you buffers and rebuild them from scratch each time, as you don't know the last time a buffer was painted
It depends on what and how you are drawing.
The screen "refreshes" itself at a certain rate, (for example 60 times a second). At that point whatever the graphics card has in its memory gets drawn.
There are lots of different ways of putting things into that graphics card memory though and they have different behaviour.
BufferedImage does not directly go to the screen. Instead it's "copied" into the graphics card and that is used to draw to the screen.
Swing hides all that away from you though - you just need to worry about the repaint and it will handle the rest. The actual handling of this comes from the Control you are using, for example JButton, JPanel, etc.
I'm currently using a Canvas with an associated BufferStrategy. How can I copy the contents (image) of the Canvas and save it to a BufferedImage. So far I've only tried
BufferedImage image = ...
g = image.createGraphics();
canvas.printAll(g); //or paintAll
However, it appears that only a 'blank' (filled with the background color) screen is being drawn; I it's assume because that's the default behavior of Canvas.paint(). Is there as way for me to retrieve the image currently on screen (the last one shown with BufferStrategy.show()), or do I need to draw to a BufferedImage and copy the image to the BufferStrategy's graphics. It seems like that would/could be a big slow down; would it?
Why (because I know someone wants to ask): I already have a set of classes set up as a framework, using Canvas, for building games that can benefit from rapidly refreshing screens, and I'm looking to make an addon framework to have one of these canvases tied into a remote server, sending it's displayed image to other connected clients. (Along the lines of remotely hosting a game.) I'm sure there are better ways to do this in given particular cases (e.g. why does the server need to display the game at all?) But I've already put in a lot of work and am wondering if this method is salvageable without modifying (to much of) the underlying Game framework code I already have.
I'm making a 2D Java program with LWJGL and its OpenGL. It uses LWJGL's display.
I would like one image to show above the second image on screen, but it's blocked out, I assume by default. Does LWJGL have a setting so that the image has 'priority' over the background, so that it sends the image in front of it?
OpenGL has no concept of "priority" in the way you mean. If there is no depth testing (or other testing), then what you see is in the order you gave it to OpenGL. So if you want something to appear on top of something else, it is up to you to draw it after what it should appear on top of.
I'm developing Side Scroll 2D Game, using AndEngine
I'm using their SVG extension (I'm using vector graphic)
But I discovered strange and ugly effect, while moving my player (while camera is chasing player exactly, means while camera is changing its position)
Images of my sprites looks just different, they are like blurred or there is effect like those images would be moving (not changing their possition, just jittery effect, really hard to explain and call this effect properly) Hopefully this image may explain it a bit:
Its more or less, how does it look in the game, where:
a) "FIRST" image is showing square, while player is moving (CAMERA isn't) image looks as it should
b) "SECOND" the same image, but with this strange effect "which looks like image moving/blurring during camera moving [chasing player])
Friend of mine told me that it might be hardware problem:
"the blurring that you notice is actually a hardware problem. Some phones "smooth" the content on the screen to give a nicer feel to applications. I don't know if it's the screen or the graphics processor, but it doesn't occur on my wife's Samsung Captivate. It happens on my Atrix and Xoom though. It's really noticable on the Xoom due to the large screen size."
But seems there is way to prevent it, since I have tested many similar games, where camera is chasing player, and I could not notice such effect.
Is there a way to turn this off in code?
I'm grateful for previous answers, unfortunately, still problem exist.
Till now, I have tried:
casting (int) on setCenter method which is being executed on updateChaseEntity
testing game using PNG images, instead of SVG extension and vector graphic
different TextureOptions
hardwareAcceleration
If someone have different idea, what may cause this strange effect, I would be really grateful for help - thank you.
Some devices (Xperia Play) bleed everywhere when trying to draw things that are moving quickly. For example a red icon on the application list leaves a blur behind it. You could try hardwareAcceleration in the manifest (on and off) to see if it makes a difference.
You'd probably get the same effect if you weren't using svg
When your player's just going to the right and camera begins chasing him, all other sprites except player are moving to the left. Try to print the absolute coordinates of your "blurring" sprite (or some of its anchor points) to the log. The X-coord of sprite should be decreasing linearly. If you notice it's increasing some times, it could be a reason of blur.
Hope this will help.
It sounds like it's due to the camera moving in real increments, making the SVG components rest on non-integer bounds, and the SVG renderer making anti-aliasing come into effect to demonstrate this. Try moving the camera in integer increments by casting camera values to int.
I'm not familiar with this engine but I wonder why would you use vector graphics for pixelated art style. I'll be surprised if your character in the screenshot is really a vector art... maybe it's texture imported in SVG? I attempted back in the day to use flash a few times and I was making the same mistake... I'm not saying it's not possible but it's not intended to create pixel art with flash or any other vector software. There is a reason why most flash games have similar look.
Best way to debug it, is try a different looking sprite.
Maybe it is just the slow response time of your device display.
I'm also an Andengine developer, and never seen such behavior.
Sometimes you fix jittering using FixedStepEngine, it might help.
If you can post your code maybe we can better help you.