"Memory" and "efficiency" are commonly misused terms, so I'll give you an answer for four different elements that may affect the performance of your game.
I will be oversimplifying way too many things to keep it short and concise, but there are tons of inaccuracies in this text below, so take it with a pinch of salt. However, the main concepts should be ...
Once an image is loaded off the disk and is formatted for rendering, it will use the same amount of memory regardless of whether that image was saved to disk using PNG, JPEG, or GIF.
General rule of thumb: JPEG is a lossy format, and will degrade image quality in order to make the image smaller on disk. PNG, on the other hand, is a lossless image format, ...
Hue-shifting is one possibility that would let you get a range of colors without losing the color details. The basic idea is to convert each pixel from RGB to HSV space, then offset the hue by a user-defined amount, then convert back to RGB. Actually, this can be done more efficiently by applying a rotation matrix to the RGB values: create a matrix that ...
Use parallax scrolling. Have multiple background layers which scroll with different fractions of the speed of the main viewpoint. The lower the layer, the slower it scrolls. This isn't just a great way to provide an illusion of depth, it also makes the backgrounds look less repetitive because the objects on the different layers will appear in different ...
Just a couple of things to add to @Marco's answer:
.gif is sorely outdated. I would completely avoid using .gif files as much as possible. I think people only use them these days because of in-browser animations, and animated png's aren't well supported at this time.
So all you have is jpg and png.
PNG: Is lossless. The only thing you are considering ...
You can implement IPointerEnter and IPointerExit interfaces and keep boolean for 'over state':
public class TestOver : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
public bool isOver = false;
public void OnPointerEnter(PointerEventData eventData)
Precisely, to repeat a texture.
So, if you have a quad, and the texture coordinates go from 0 to 1, the texture will be drawn once. If the coordinates go from 0 to 2 and wrap is set to GL_REPEAT, then the texture will be drawn twice.
Try it and see it by yourself
The problem you are facing is that you can't simply "tint" the whole image, the appearance you see is more than just a base color. For one you have fine gradients from one one material to the other, but more importantly you also have reflections,highlights and shadows, which are not influenced by the base color. (Those are basically added on top of it.)
The image format is only a way to save raw data of pixels, so as long as you use bitmaps, the format usually does not make a difference in execution after the loading step. What matters is the pixel data supplied to the graphics API. There are three formats commonly used in the web:
.gif The (now normally deprecated) GIF format is used for images with 256 ...
The parallelogram coordinates you're using are easier to work with, but they do have the drawback of being weird for rectangular maps. One approach is to store it with the offset coordinates but actually use parallelogram coordinates in your game logic.
Observation: in each row of the map, the grid data is contiguous. All the wasted space is on the left ...
The commonly used formats are PNG and PVR.
The PNG (Portable Network Graphics) format is compressed but lossless. It's a commonly used format (basically any image-editing software can write to PNG).
The PVR (PowerVR) format is a format that is much closer to the native memory structure of images on the GPU of the iPhone. Therefore it also allows for some ...
For best quality results, you should probably first render the SVG at high resolution and then scale it down, using a good scaling algorithm. For example, here's the result I got by taking your 256 × 357 px image and scaling it down to 71 × 99 pixels in GIMP using Lanczos3 resampling:
It looks noticably sharper than the version you got using ...
A way to build an infinite background for a 2D game is the following:
Using a graphics editor software (like iDraw for Mac) create an image A that represents a portion of your background. This image should have a limited size.
Duplicate A and mirror it on the Y axis, this is B
Now paste (horizontally) togheter A and B, this is AB.
Finally import the image ...
You could use polygons, or you could do a quick and dirty hack and just get a political map like this one:
. Then, pick a unique color for each country and flood fill it in paint or photoshop. Then, you have a simple file that just has the mapping of countries/provinces to particular colors. Just something like this:
Personally, I would prefer simplicity over saving memory. Don't optimize until needed!
If you're still bent on saving a few bytes, here's how you can do it:
Slice the parallelogram in half to form two right triangles
Rearrange the two triangles to form a rectangle.
(Note I added the green buffer strip so the math works out nicely.)
Python code to map ...
Just fake the wrapping (I assume we're talking about working in Photoshop/Gimp and not doing it at runtime in a game):
Depending on your editor there might be an easier way to do this.
Double the size of the canvas while keeping the original image in the center (i.e. don't scale it).
Copy/tile the actual texture to fill the (still blank) space outside the ...
Edit: Just saw that my answer was based on your code but didn't actually answer your question. I kept the old answer in case you can use that information.
I have fixed 2 issues with the original code:
- The +1 addition in the calculation of end x and y was by mistake inside the brackets, but it needs to be added after the division.
- I forgot to ...
Not really, no.
There's one scenario: you're calling the draw method so often you don't leave yourself the resources to do anything else. That's not your FPS negatively affecting how the game runs, though. The cause would be a badly written game, engine or framework; the FPS would just be a side-effect.
You have a glitch that surfaces on your desktop. Your ...
Yes, you can encounter texture coordinates greater than 1.0 and smaller than 0.0.
This depends completely on the model, you loaded. Normally, for each vertex there is position, normal, and texture coordinate stored. In most mesh file formats, the texture coordinate is not restricted to any range.
This is used to repeat a texture. For example, to span a ...
Not all textures use texture coordinates that come from the mesh data. For example, with projective texturing, you transform the world into the space of the texture. Well, a lot of that world falls outside the [0, 1] range of the texture. Without some sort of clamping mode in place, you're going to get problems.
I suspect you are using an inefficient implementation of the flood fill algorithm especially that the application freezes when applied on large images.
By looking quickly at your code I can identify few problems
It seems your code has a Big O( N^2 * K ) and might even be O(N^3), which translates to your code like this:
toProcessList.Count // Looping ...
JPG is lossy. Don't use that for sprites -- you will end up with nasty artifacts that will look bad. There's a couple reasons you might want to use colur-keying, but they're a bit lost in todays hardware. Taking a quick look at color key advantages:
They use up less disk space -- there is no alpha channel to store
By consequence, their memory foot ...
Layers work well.
Here's some maths:
Suppose you have a railway track that's been poorly made such that the like __ __ notice the gap between them. When the wheel rolls over them it makes a small notch (tiny notch).
If the track length is l and the wheel has radius r then 2pi r is the circumfrence of the wheel, ration=l/(2pi r) if the ratio is say 10.25 ...
Here is another idea which seems to be missing:
In case of long distance backgrounds, like sky boxes, Parallax layers doesn't really feel good. Think of the stars for example, when walking on earth, or even better through out the night, all the stars move together, though we know they are hundreds or thoughts light year away from each other. The thing is ...
SDL uses a type called SDL_RWops for this purpose. This is essentially a wrapper around a stream. When you call a function like IMG_Load(filename) it is just a small wrapper around IMG_Load_RW(ops) which constructs the ops using SDL_RWFromFile. You can create an SDL_RWops yourself (it's just a struct with some function pointers) if you have a custom stream ...