Actionscript 3.0: How to add code to pixels copied via BitmapData - actionscript-3

My question is if I can add eventListeners to the pixels I copied with the instance.copyPixels... If I perhaps copy my character from bitmap I have loaded. Can I make him walk?

You would have to draw the moving parts into different Sprites and then move those arround.
This is the wrong approach though.
Walking animations for example are usualy done with a SpriteSheet and Blitting or BitmapData Frame assignment.

Related

8-direction Figure Animation with Arrow Keys

I've been charged with designing a demo for an isometric video game in ActionScript 3. I have the bitmap spritesheets that show the avatar I'm using standing and walking in each direction. The walking animation is made up of three frames.
My problem, though, is that I need to figure out how to make use of them. I'm not familiar with animation in Flash, and I need input on how to gotoAndPlay() the walking frames for the right direction. I don't think isolating the necessary DIRECTION is going to be a challenge, so much as starting it and keeping it going while the arrow keys are down.
My current code is basically comprised of keyboard handlers for KEY_UP and KEY_DOWN, each containing a switch-case statement that changes the Avatar.currentDirection property. The handler continues to fire while the keys are down, but I need to add animation to the game.
I've seen some examples where they simply embed the animations into an SWF, propagate an array of the various walking stages, and alternate between them using an EnterFrame event handler, but this seems really clunky. I guess in the end I'm trying to make use of Adobe Animate, but I don't know how you're supposed to do that.
Ops, fortunately i'm working with sprites (atlas animations) right now!.
if i'm right, you just needs to use them for playing some animation with functionality.
if you have a well sized sprite which is tiled with isometric slots like it:
(9 frames sized 64x128)
your work is very easy, only create new movieclip from library, inside it, create a borderless rectangle (which is our mask) in a layer (named mask) then import image to the project, and its better to disabling smooth ability from image properties,
now, inside your movieclip, you have to create new layer (under the mask layer) and add your sprite image for each frame, and change its position:
at last, enable masking for mask layer, then its time of coding,
name your animation queries (like image 3) and for loopable animations, insert gotoAndPlay('anim_name') inside last frame. i hope you are familiar with controling movieclip animations which is basic consept of any flash project.
now to extend it for 8 directions support, you just need to play and switch between dirctions according single and multi keypreses,

How to use bitmapdata.draw to get a specific area of the stage?

I'm using a bitmapdata.draw(stage) to draw the stage as a bitmap but I would like to draw an area which is 32 pixels left of the stage instead, so that the area I am drawing as a bitmap is no longer in the viewing window, but the bitmap being draw is (so the stage is a bitmap). How do I draw a specific area with multiple bitmaps and display objects?
This is a very nice article that can help you: http://www.tomauger.com/2013/flash-actionscript/actionscript-3-bitmapdata-draw-offset-and-positioning
You should basically use a Matrix and work your way around with it :)
My honest advise would be not to use such odd techniques as if you want to draw something it should be within the stage..

Draw (shapes) to a texture/sprite in libGDX

In my libGDX game I have several sprites that share the same texture. Now I want to "manually" draw onto some of the sprites (i.e. I want to change some of the pixels in some of the sprites).
How can I modify a texture that is shared amongst seveal sprites without affecting other sprites?
I guess I need to copy the texture before I set it to the sprite?
You can use custom shader to customize sprite texture.
Before drawing the sprite with spriteBatch, simply say:
spriteBatch.begin();
spriteBatch.useShader(shaderProgram1);
sprite1.draw(...);
spriteBatch.useShader(shaderProgram);
sprite2.draw(...);
...
spriteBatch.end();
If you aren't familiar with the shaders you can check this link:
https://github.com/libgdx/libgdx/wiki/Shaders
Also there is option to use frame buffer object, for texture customization, but I think if those texture difference aren't that huge, this is the best solution if you are looking for best performances.
Hope that this gives you an idea.

AS3 for moving a movieclip along a path

I am looking for a simple AS3 script to move/follow a movieclip (arrrow) along a manually drawn path in flash. Like.. it moves for the start point if the line to the end point of the line, also should rotate at curves automatically.
Also is it possible to duplicate this movieclip (arrrow) tho specific distance, like a ground of arrows moving along a path continuously with specific distance from eachother?
I am working on few infoGraphs and need this arrows animation to show the workflow.
I desperately needs this, pls help!
Cheers,
bp
There could be libraries that help with this, as George Profenza mentions in his comment, and it is certainly possible to calculate points along a bezier.
However, a much simpler solution is to do what people have done since Flash 4. Draw the curve in Flash, then create a motion tween along the curve using an empty MovieClip. At runtime, you can use addChild() to insert your MovieClip as a child of the empty one. You will have a lot more manual control this way, compared to the bezier library.

as3 how to ignore MOUSE_DOWN outside mask

I am working on a jigsaw-like game in as3 where irregularly shaped layers imported from photoshop are used to mask parts of their original background.
By setting cacheAsBitmap=true on the mask and its contents the result is a nice irregular shape with its transparent bounding portions left out.
However the invisible bounding areas are still detected at MOUSE_DOWN. I would prefer the mouse not be detected anywhere but on the visible masked part. At the moment I cannot detect the mouse on any other clips on the stage that might appear behind the overlapping transparent areas.
I have seen a solution here involving bitmap pixel detection which I have not found a way to apply as a solution. The contents of my masked areas are either shapes or MovieClips.
I hope someone can help me find a solution
The simplest and the most stable approach to prevent the mouse events on the transparent area of bitmap graphics is to create a separate vector shape as the target for mouse and set the mouseEnabled flag to false to the bitmap or set hitArea property to this shape.
You can create such shape manually in the Flash IDE for the tests and even for the production. Sometimes it's more suitable to write the bitmap tracert script that creates contour shape in runtime by checking the pixel transparency.