How to put a sprite behind other sprites in pygame? - pygame

I want to put a sprite on screen, but I want it in the back layer behind other sprites, so that it does not cover up those sprites when they pass by each other.
How would I go about doing this?

One way is to just blit the Surface/Sprite that should go to the background before the other Surface/Sprite that should go to the foreground.
If you use the Sprite class, you could also use the LayeredUpdates or LayeredDirty groups to handle this for you by using a layer attribute or kwarg when adding the Sprite to the group.

Related

Masking a sprite with an image mask. Phaser

I have a collection of images that creates an animation put in single sprite and an image mask that i want to apply. Do i just have to apply mask to the srpite or to every image in sprite? and How?

Its possible do a hole in movieclip with mouse click?

I have a movieclip moving and when I click him I want that appears a hole.
Its possible do that with actionscript? how?
If your hole should appear there the mouse clicks, you could create new Sprite, draw two circles (one bigger than your MovieClip, another at size of you hole, both at position of your click) using his graphics property. Fill it with any color. It should look like donut.
After that assign created Sprite as a mask for your MovieClip.
youMovieClipId.mask=createdSpriteId;
After that, you could add mask as child of your MovieClip, using
youMovieClipId.addChild(createdSpriteId);
Now created mask will follow your MovieClip.

AS3: Create sprites from loaded image

I don't know if the title is misleading as the image I'm loading is actually a sprite image consisting of a multi-state button. I want to load this image and split it into several display objects (sprites?) in AS3, to create a SimpleButton with an over and down state.
Right now I'm just loading the image with Loader and URLRequest, and then creating a sprite from the loaded content.
Is this possible or is there any other way of doing this, without having to load two separate images?
Thanks in advance,
Pierre
There is. You can use the mask function of the Sprite class. First you set the mask to normalstate button part of the image,, and on mouseover you set the mask to the other state and on mouse down you set the mask to the clickstate button part of the image
Please mark as answer if this helped.

erasing a movieclip

I have a fully working flash application, made in as3. Now i dynamicly added a movieclip and i would like to be able to erase that movieclip with a eraser of some sort, my goal is to be able pick up a sponge with the mouse and then start dragging over the movieclip and erasing the parts where i dragged over it.
Anyone who can help?
Looks like this might be what you're looking for:
http://www.piterwilson.com/personal/2008/05/07/bitmapdata-erasing-in-as3-with-custom-brush-shape/
Is the background behind the MovieClip always the same?
If so you can put an image of the background over the MovieClip you want to erase, and mask that image so it becomes invisible, then add a click listener that draws a circle in the mask when clicked. This way it'll look like the MovieClip is being erased.
With getPixel you can loop over the mask and detect the percentage of the MovieClip that has been erased, so you can remove the clip from stage when it's fully erased.

Is it possible to move the stage in actionscript 3.0?

Hi to keep it short and simple let's say I have a stage with 400x400 size in pixels, but I've drawn a map of 1000x1000 size in pixels. I want my player to be able to "walk" about the stage, but it appears stage.x and stage.y are read-only? Is there any method or way to have the stage "scroll" about, without having to move each object on the map?
Don't move the stage, move the 1000x1000 object,then it'll look like the whole thing is moving.
You should see the stage like a window. You can see everything behind it depending on the size of the window. You cannot change the size of the stage, or move it.
Just like a window you can measure the size of the stage. You can use this to navigate for example movieclips across the stage with actionscript.
Why don't you put the map and the other objects in a seperate layer, and move the map around. Other objects (for example a big red dot to tell the user its' location on the map) are on a fixed position on the map. Just move the map following a sort of path according the red dot.
Not entirely sure what you want to do, but it isn't possible to move the stage.
You can put all the movieclips (the player and the map, if you want) in one movieclip, put only that movieclip on the stage and move that.
But if you only want the map to scroll, just move the map around.
The other answers are correct, but there's an alternative to moving the map:
ScrollRect
Attach a rectangle to a your map's scrollRect property. Moving that rectangle will have the same apparent effect as moving the stage around.
There are minor pros and cons to using scrollRect vs. moving the world, but try them both and see which works better for you.