View Full Version : Bite, Bite, Bite the Pizza!! [help]
AlexanderW
March 29th, 2010, 07:35 PM
Hi guys! I'm new to the forum, so, Hello! :kir:
So I'm trying to do this interactive ad where you "eat" a pizza with the mouse.
Basically, click and it "stamps" a bite mark wherever on the pizza you clicked.
I really don't know how to approach this and I'm fairly new to AS3, so I'm in your hands.
I already know how to change the mouse cursor, which I want it to be a bite mark. All I need help is on how to "bite" the pizza.
I attached a few pics to illustrate my idea.
Thank you very much guys, really!
Alexander
pardoner
March 29th, 2010, 08:54 PM
Try breaking the piece of pizza up into a bunch of little bits and covert each bit into a MoveClip. Then piece the bites back together like a puzzle. Give each piece an instance name (bite1, bite2, etc) and apply a MouseEvent.CLICK event listener to it. Then when they user clicks on one of the pieces (or takes a bite) remove it.
// add an Click event to all the bites
bite1.addEventListener(MouseEvent.CLICK, onBiteClick);
bite2.addEventListener(MouseEvent.CLICK, onBiteClick);
bite3.addEventListener(MouseEvent.CLICK, onBiteClick);
function onBiteClick(event:MouseEvent):void
{
var biteToRemove = event.target;
removeChild(bitToRemove);
}
AlexanderW
March 29th, 2010, 09:43 PM
Try breaking the piece of pizza up into a bunch of little bits and covert each bit into a MoveClip. Then piece the bites back together like a puzzle. Give each piece an instance name (bite1, bite2, etc) and apply a MouseEvent.CLICK event listener to it. Then when they user clicks on one of the pieces (or takes a bite) remove it.
// add an Click event to all the bites
bite1.addEventListener(MouseEvent.CLICK, onBiteClick);
bite2.addEventListener(MouseEvent.CLICK, onBiteClick);
bite3.addEventListener(MouseEvent.CLICK, onBiteClick);
function onBiteClick(event:MouseEvent):void
{
var biteToRemove = event.target;
removeChild(bitToRemove);
}
Oh man, you're awesome! It'll take a while to cut up the pieces, it's a large pizza, but I've started allready! The code works like a charm..
any Ideas on how to make it reset? :rambo:
Pardone, you are awesome!
guys, if you have any other methods on making this work, please, by all means.
theCodeBot
March 29th, 2010, 10:18 PM
Masking would be significantly more dynamic and significantly less work, but you'd first have to figure out just how those work.
I'll post more on this tomorrow. Basically, you need an inverted mask and one of my personal favorite methods of AS3, DisplayObject.graphics.beginBitmapFill();
Using an inverted mask in this way, you will be able to "hide" parts of the pizza (or ANY image, for that matter!) just by drawing a picture of that stamp (the bite mark) on the mask.
AlexanderW
March 29th, 2010, 10:44 PM
Masking would be significantly more dynamic and significantly less work, but you'd first have to figure out just how those work.
I'll post more on this tomorrow. Basically, you need an inverted mask and one of my personal favorite methods of AS3, DisplayObject.graphics.beginBitmapFill();
Using an inverted mask in this way, you will be able to "hide" parts of the pizza (or ANY image, for that matter!) just by drawing a picture of that stamp (the bite mark) on the mask.
OMG! CodeBot, could you help me on coding that? That would make my life so much easier! :love:
Thank you guys! I love this forum!! I'll post the end result once I'm done!
TheCanadian
March 30th, 2010, 01:54 AM
I think the best way would be to just copyPixels from a bite shaped BitmapData to the BitmapData for the pizza.
theCodeBot
March 30th, 2010, 03:11 PM
I think the best way would be to just copyPixels from a bite shaped BitmapData to the BitmapData for the pizza.
That would work too, but what if there is a (dynamically changing) background beneath the pizza? If there were a static background, you could just copyPixels that background onto the pizza, but I kind of like the idea of a masked mask, using copyPixels or beginBitmapFill.
Though if you have a solid color background that is the same color as the brush, theCanadian's idea is a whole lot less complex to work with. Masking masks is a little bit of a bad practice anyways :P
TheCanadian
March 30th, 2010, 03:22 PM
That would work too, but what if there is a (dynamically changing) background beneath the pizza? If there were a static background, you could just copyPixels that background onto the pizza, but I kind of like the idea of a masked mask, using copyPixels or beginBitmapFill.
Though if you have a solid color background that is the same color as the brush, theCanadian's idea is a whole lot less complex to work with. Masking masks is a little bit of a bad practice anyways :P
Or you could just put the background, you know, in the back . . . ;) copyPixels can do transparency.
theCodeBot
March 30th, 2010, 04:52 PM
Or you could just put the background, you know, in the back . . . ;) copyPixels can do transparency.
:doh: I forgot about that flag :) If you do that, you have to keep a "hidden" bitmap separate from the mouse cursor that will be copied, but that's trivially simple to do. I knew I was missing something here lol
AlexanderW
March 30th, 2010, 07:16 PM
Yea, the background is static, white or black, whatever... it's static.
So how do I do this, 'copyPixel' thing? I'm really a newbie in Flash, so I need your help here guys. Thank you so much! This thing is going to look awesome!
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.