Sprite Sheet Animation while moving it to another place - animation

I am trying to make sprite sheet animation work with another Action. For this purpose i've a Sprite sheet .png file without any .plist file. My problem is that the spritesheet animation works but with other action like this one in following code block it just doesn't. It will first move it to the destination and then animates it but all i want it to move while animating itself.
void animatespritesheet()
{
for(i=0;i<10;i++)
{
_spriteFrame=CCSpriteFrame::create("bulb_f.png",CCRectMake(i*75,0,75,75));
_anims->addObject(_spriteFrame);
}
_animation=CCAnimation::createWithSpriteFrames(_anims,1.0f);
CCSprite* sprite = CCSprite::createWithSpriteFrame(_spriteFrame);
//sprite->setPosition(ccp(256,256));
CCAction* axn = CCRepeatForever::create(CCAnimate::create(_animation));
/*CCAction *axn1 = CCMoveTo::create(1.0f,CCPoint(200,200));
CCMoveTo* move = CCMoveTo::create(1.0f,CCPoint(200.0,200.0));*/
_spriteBatch->addChild(sprite);
sprite->runAction(axn);
//sprite->runAction(move);
//sprite->runAction(CCSequence::Create(move,axn,NULL);
}
_anims is a CCArray. the png file is 75*750 file which contains 10 frames.
I just can't get this thing done by myself. Please Help me out on this. I Really need help on it.

Use a CCSpawn to run both actions at the same time (this examples assumes cocos 3.0).
[CCActionSpawn actions:action1, action2, nil];

Related

How to save images into playerprefs and display them to another scene?

I'm a beginner in Unity. And so far of what I read, playerprefs could store image in a byte form. Still, I'm having trouble in this one. Because, I'm having an error in converting texture2d to bytes. In which, I use this code
Texture tex = Resources.Load("Sprites/white_black") as Texture2D;
byte[] texbyte = tex.EncodeToPNG();
// ^ this line always result as NullReferenceException on my console.
I have two scenes: Scene1 is images that were going to save to playerprefs which is an example below:
While in Scene 2, all the images that were saved in playerprefs will be show using a button like in below pic:
Also, if you could recommend me other solution I'll search on it. Thank you.
You should not save images in PlayerPrefs but you could just save the name of the sprite to PlayerPrefs, and then load it in another scene from resources, like so: Resources.Load(spriteName);

AS3 annoying issue with png as a cursor - stopDrag and startDrag

I've never run into this problem in the past, but when I use a png as my default cursor in an application i'm developing, it stops working with the startDrag and stopDrag.
When before I import the png of the simple vector graphic (a scribble) it works fine.
Do the alpha channels throw the code out?
If so, is there a work around that still allow me to use the png in this way?
It's a png of some tweezers with dropshadow.
// ------------------------ tweeze tool
Mouse.hide();
stage.addEventListener(MouseEvent.MOUSE_MOVE,follow);
function follow(evt:MouseEvent){
tweezed_one.x = mouseX;
tweezed_one.y = mouseY;
}
Your question is not so clear.
But what I understood is that you are not aware of mouseChildren while using custom cursor.
Add this line where you created it,
tweezed_one.mouseChildren = false;
Now you will be able to drag and drop.
For more info see mouseChildren

Can be smoothing image in a loaded SWF?

I'm trying to load an SWF into another in AS3/Haxe. The loaded SWF contains some images - but only on some Shape.graphics elements. (Like graphics.beginBitmapFill(); ...)
This images are not smoothed, and jaggy.
Can this images be smoothed anyhow during runtime?
Any hack interested! :)
Thanks in advance!
Tom
Update: Sorry, but I forget to mention, that I'm loading more AS2-SWFs (AVM1) into one AS3-SWF (AVM2) with AVM2Loader, which hack the loaded bytes, and convert the AVM1 SWFs into AVM2 - it works very well. :)
So, in these SWFs I need to find the images/bitmaps, but only found the Shapes, which graphics elements has the 'images'. If I clear this graphics, then all images are gone, so I think, the images are in some graphics.beginBitmapFill(...);, without smoothing. I want to reach them, and switch smoothing on at runtime, if possible.
(Sorry, if the first time I was not enough clear.)
Edit (Jan 23 '14): I found solution for it. It is not fast, and required Flash Player 11.6. Every MovieClip graphics properties has a new readGraphicsData function, which give all the graphics commands (Vector IGraphicsData) to draw the whole MC. And iterate in these commands, if I change every bitmapFill command smooth parameter to true, and redraw the MC, it will be smoothed, and nice.
That's it. Not fast, but working.
I found solution for it. It is not fast, and required Flash Player 11.6. Every MovieClip graphics properties has a new readGraphicsData function, which give all the graphics commands (Vector IGraphicsData) to draw the whole MC. And iterate in these commands, if I change every bitmapFill command smooth parameter to true, and redraw the MC, it will be smoothed, and nice.
That's it. Not fast, but working.
function onLoad(event):Void
{
pic.forceSmoothing = true;
}
Smoothing is a property of bitmaps that's off by default.
var image = new Bitmap(bitmapData);
image.smoothing = true;
Typically, your bitmapData will be in the loader.content.bitmapData when loading externally, but it's up to you were you've stored it.
Update:
If you want to smooth all images in a loaded SWF without any knowledge of the structure of the SWF, then you'll have to recursively dig through the hiarchy of that SWF, and depending on whether or not the object is a Bitmap, turn on smoothing.
function recursivelySmooth(obj):void {
for (var i:int = 0; obj.getChildAt(i); i++) {
var item:* = obj.getChildAt(i);
if (item is Bitmap) {
item.smoothing = true;
} else if (item.hasOwnProperty("numChildren") == true) {
recursivelySmooth(item);
}
}
}
This was written freehand, so you may have to doublecheck everything is correct, but that's the basic idea. Just call recursivelySmooth() on your swf, and it'll dig through all objects that can have child elements and smooth them.

How to overlay TWO images and save them into AN image? (Flash CS5)

I am a total noob with Flash. And i am no programmer. Just good with photoshop (image designing).
Here is my problem. I found a simple drawing application and modified it, only the interface, not the codings.
It provides a 'save button' that enables to save the drawing (drawn on MovieClip) into diskdrive. And then i modified it, put another layer on top of the MovieClip a Graphic. But then when i try to save it, it only saves the MovieClip as a .png image. What i want is that it saves the MovieClip along with the Graphic layered on top of it into one .png image. How can i do that?
Maybe it'll be more helpful if I provide the code to the 'save button'?
** /* Save */
private function export():void
{
var bmd:BitmapData = new BitmapData(600, 290);
bmd.draw(board);
var ba:ByteArray = PNGEncoder.encode(bmd);
private function completeHandler(event:Event):void {
var loader:URLLoader = URLLoader(event.target);
trace("completeHandler: " + loader.data);
}
private function saveSuccessful(e:Event):void
{
saveDialog = new SaveDialog();
addChild(saveDialog);
saveDialog.closeBtn.addEventListener(MouseEvent.MOUSE_UP, closeSaveDialog);
}
private function closeSaveDialog(e:MouseEvent):void
{
removeChild(saveDialog);
}
private function save(e:MouseEvent):void
{
export();
}**
EDIT: i have put 'bmd.draw(topLayer);' under the first draw() call but then when i published a preview it says "Access of undefined property topLayer". i checked its property first it mentions this 'Instance of: topLayer' and it is a Graphic.
Check the codes. There should be a construction fileReference.save(someOtherName) somewhere, probably with different name for fileReference, but it will be declared nearby as FileReference=new FileReference(). Then, track that someOtherName above, it should be an output of PNGEncoder.encode() of yet another variable, which should be of type BitmapData. Find out what is drawn on that bitmap data, there will be a line bitmapData.draw(someMovieClip). Find out if that someMovieClip is only the layer that's drawn upon in your program. You can add a similar line right after that one to draw your shape (you should have its name so you could reference it in code), this will draw your Graphic over the thing that you draw.
In case the entire graphics drawn by you can be fit within a single screen, just take a screenshot of your application in progress, load it up into Photoshop and have fun with your graphics be correctly on top of whatever it saves. Or, use an existing saved image as a background layer, place a screenshot as foreground, clear the areas that are not your graphics and have some more fun.
EDIT: Okay, there it is: You have export() function (which is incomplete in your copypasting, BTW), with all the relevant part I've mentioned. There is a draw() call, a PNGEncoder.encode() call, and a BitmapData object. You should add another line of code after the first draw() call with something like this:
bmd.draw(yourGraphic);
YourGraphic is the name of the graphic you have manually added above the MovieClip, the one you can edit in its properties on stage. Should do.
REPLY: i have put bmd.draw(topLayer); under the first draw() call but then when i published a preview it says "Access of undefined property topLayer". i checked its property first it mentions this 'Instance of: topLayer' and it is a Graphic.

Slowing down looping animation as3

This is the first time I've ever posted in a forum, so thanks in advance for anyone who takes the time to read/answer this question.
What I'm trying to create is basically a flipping coin animation, which starts off turning very fast and then slows down to stop with a (randomly generated) side facing upwards after about 8 seconds.
I've done the animation of a complete flip, which lasts about half a second, and made it in to a movieclip... now I'm stuck!
Any ideas how I might go about doing this in actionscript3?
The fastest way around this would be to use some very basic actionscript. First, create 2 animations (One heads, one tails). Now, you only need a single frame for this and don't need to place the movieclips on the stage. Use the following or similar code:
var whichSide:int = 0;
var coin1:coinAnimation1 = new coinAnimation1();
var coin2:coinAnimation2 = new coinAnimation2();
whichSide = math.Round(math.Random(1));
if(whichSide == 1)
{
addChild(coin1);
}
else
{
addChild(coin2);
}
Just don't forget to right click the movieclip and export for actionscript, giving the movieclips the class of: coinAnimation1 and coinAnimation2.
Hope this helps.
I've accomplished such animation on ´Keyframes´ using the Tweener class. You can easily tween on the keyframe parameter with specific transition...
Basic example:
Tweener.addTween(myMovieClip, {_frame:10, time:2.5});
More information about Tweener here

Resources