I am working with box2d, and generating a few grounds of variable size (all rectangles). The image the grounds use is 500px by 200px, however, when I create and size my grounds, the background image stretches to fill the body. I am trying to have it aligned to top left and just tile with no resizing but am really unsure of how to control it.
I imported the image as a movieclip to my library, if it helps, and also have a basic empty class for it (EarthGround.as). I've been doing a little research but really haven't found anything definitive about manipulating the movieclips associated image.
You have to be specific with that. Maybe a screen shot would help.
Until then, possible causes could be:
Box2D uses real world values where 1 pixel = 1 meter. You have to
choose a scale factor.
Box2d uses the center of any object as its registration point. You
should always do the same with your flash sprite/movieclip, to keep
it simple.
Related
I've built an game in Libgdx which uses a single FitViewport passed-in to some Screens (Splash/Intro/Game/Menu/Pause etc.).
Each Screen has it's own Stage containing Groups of Actors - I've written a custom render loop to allow Screens to fade-in/out or slide around or render behind each-other - that's all great.
I now want a 'UI' screen which will rotate on smartphones to match their orientation (everything else in the game will NOT rotate).
I can make this work visually by using a TransformMatrix on the SpriteBatch but that doesn't affect the Stage's 'touch' detection (or debugdraw) and it seems there is no way to do this within the Stage (localtoparentcoords allows for rotation and scale but NOT transformation)
Bear in mind that it will not be 'square' (the FitViewport enforces 16x9 ratio) so it needs translation as well as rotation...
Note: I've tried to mess around with cameras but that's the wrong paradigm - cameras are a different view of the same thing - I want different things (transformation and rotated) drawn into the same view!
Note also: I've already started to create my own version of a Screen/Stage class to do this - I think it might be quicker than kicking the existing code into working properly but I'll be surprised if I'm the first person to want this?
I think I've sort-of solved this by stepping-back a bit and looking at how the Stage/Actor system works.
The idea of rotating AND transforming an entire Stage is fraught with complexity - that I could do it at the SpriteBatch level was a distraction which led to a lot of wasted time - sadly.
It was only when I realised that as I was calculating the position of all my UI (Actor) elements relative to either the screen center or a corner, I may as well take the further step of rotating and transforming them at the same time! I also realised that Grouping them ,made this very simple (indeed I could have static and rotating elements simply by using 2 separate Groups!)
Rotating/Moving an Actor will, of course, adjust it's bounding box/touch-area as well - so I now have a proper Stage/Group/Actor model which rotates as the device is rotated - I could be just static information (scores) or even a dynamic menu or an overlay for a 'cue' in a pool game or whatever...
As Edison would have said - I didn't waste 2 days, I just spent 2 days coming up with a large number of ideas which I now know not to work!
I'm making a top-down game in flash, and I need to have the whole game zoomed in; the characters and scenery are really small. If I increase the height and width in flash, it messes up the image, putting pixels and strange coloration where they shouldn't be. What I am looking for is a way to change the size of the pixels, or something to that effect.
You'll 'mess up' a bitmapped image by enlarging it beyond its resolution. Two easy solutions: 1. Make your characters and scenery as vector images. Or 2. If you want them to be bitmaps (jpgs, png, whatever) create them initially at a size == the largest size you'll get to in your zoom. Then scale them down on stage to their starting scale. When you zoom in they'll look good.
I've just started using actionscript 3 and I am currently trying to make a scrolling runner game in Flash CS5, similar to the Flood Runner games from Tremor games. The difference is, however, that my game is not an endless runner game and the character has a destination that she must reach before time runs out. Alot of the tutorials I've read on the subject use the player character's x and y positions to scroll, but in my game the background scrolls independent of the character. The tutorials I've read about this do not address my problems specifically.
TL;DR: I do not want to loop my background but have a series of multiple background images.
I am trying to figure out the best way to patch together multiple background images seamlessly. Currently, I have one background movie clip object at the maximum pixel width. The background object scrolls to the left independently of the position of the player character, who can only jump.
What I am thinking about doing is this:
Every time a point at the far right edge of one background image reaches the far right stage boundary, I have my actionscript call an addChild command for the next background object and instantiate it at the far right stage boundary. It will scroll at the same speed as the preceding background object.
I also need to figure out how to remove the background objects once they have completely exited the stage for memory purposes.
So, what would be the best way to tackle this?
Your basic concept will work, and to remove you just need to evaluate when the background image is off the screen :
if (backgroundImage.x < -backgroundImage.width)
{
// image is no longer on the screen.
removeChild(backgroundImage);
}
I am working on a map application and I have come across an issue with how my tiles are laying while scaling.
Here is a basic look at my structure:
There is obviously a lot more going on, but you get the idea. Now, I scale the Map App Sprite to zoom in. When that scaling occurs, there is a gap between each tile.
You can see the gap where 4 tiles meet here:
I am caching everything as a bitmap. For each Layer (which all extend Bitmap), I have smoothing set to true and pixelSnapping set to PixelSnapping.ALWAYS (pixel snapping shouldn't help here, but it shouldn't hurt either).
Does anyone have any suggestions on how to fix this issue?
(For the sake of completeness, the Map app is built entirely using AS3 and it is embedded in a Flex app)
Using integers for tile x,y locations and calculating those locations correctly is most likely the fix here, unless the images have seams in them!
The code that calculates and sets the x,y locations would be needed to properly pinpoint the issue in the code.
But, also if you are scaling that container sprite, you would want to ensure that you scale so that the width/height of a tile is an integer value.
For example, if you scale your sprite that contains these tiles, the widths/heights of the individual tiles might not always be integers, therefore creating those seams you see.
What you could do in that case is do your scaling by adjusting your width/height values by integer values, taking into account proportions, as opposed to using scaleX and scaleY on your container sprite.
Without seeing your code it's difficult to be sure, but it is possibly just a visual artifact due to scaling - eg: a 250px wide bitmap scaled to 155% should be rendered at 387.5px wide but thats impossible so its rendered at 388px wide - with the 0.5px part rendered as 1px at 50% alpha to give 'appearance' of 0.5px.
Ensuring scaled bitmaps widths/heights are always integers may solve it?
This looks like a rounding error.
Without code it's hard to know: it would be a great asset to you and us if posted a barebones example of your tiling class. In the process of subtraction you may very well discover your solution.
I'd offer that you should test what happens when you scale and algin four 100x100 bitmap images at various fine grain steps, to detect if it's a Flash rendering issue or a defect in your class.
I was wondering how does pygame.blit manages the images blitted on screen. When I blit an multiple images on the screen, I see that each image is stacked on top the previous one.
How do I clear all these images? Wouldn't(somehow) there be a big problem when there are LOTS of images stacking on top of each other on the screen? Currently, I'm just blitting a white bg or custom bg on the whole screen to "clear" the screen. So far no problems or anything since the app I am working on is very small.
When you blit an image to a surface, it basicly draws it on the surface. The location of the blitting or the object blitted is not saved and cannot be changed. It's like if you were painting the images onto a canvas. The new ones would go over the old ones and there would be no way to get rid of one image if it were colliding with another image.
The most common approach to solving this is to just completly clear the screen using surface.fill(), and redraw the images each frame.
To answer your question about if there woudl be problems when there are lots of images, no. The window will only be saved as each individual pixel being a certain color, much like a regular picture you would take a camera, so no matter how many objects you blit, the game will always take the same amount of time.
There are multiple approaches:
Clean the whole background, as you are doing.
If the computer keeps up with the fps, perhaps it's better to leave it like this.
Clean only the areas where you blitted objects (see pygame.sprite.RenderUpdates)
In your case, if you have many stacked objects, perhaps it's better to write your own solution, trying to find the union between colliding rectangles, to avoid reblitting the same background over and over.