00:00
00:00
Newgrounds Background Image Theme

TheADHX just joined the crew!

We need you on the team, too.

Support Newgrounds and get tons of perks for just $2.99!

Create a Free Account and then..

Become a Supporter!

Need little help

661 Views | 15 Replies
New Topic Respond to this Topic

Need little help 2014-03-07 09:27:24


Ok I have this code here and I want to be able to hit the zombie and have the GreenBlood stay and have another GreenBlood on the screen the same time as the last one insted of just adding it back to the stage with its position. How would I do this ? would I put it into an array?

var zombiespeed:Number = 2;
stage.addEventListener(Event.ENTER_FRAME,GetZombie3);

function GetZombie3(e:Event):void
{
	for (var r:int = ZombieOnstage3.length-1; r > -1; r--)
	{
		var currentZombie3:MovieClip = ZombieOnstage3[r];
		if (currentZombie3.hitTestObject(char2_mc))
		{  
			ZombieKilled3++;
			/*removeChild(currentZombie);*/
			
			ZombieOnstage3.splice(r,1);
			stage.removeEventListener(Event.ENTER_FRAME,GetZombie3);
			textfield.text = score.toString();
		    score+=1;
			currentZombie3.parent.removeChild(currentZombie3);
			
			addChild(GreenBlood_mc);
			GreenBlood_mc.x = currentZombie3.x;
			GreenBlood_mc.y = currentZombie3.y;
			GreenBlood_mc.gotoAndPlay(2);
			stage.addEventListener(Event.ENTER_FRAME,GetZombie3);

Something about art?

lol excuse the hand

Response to Need little help 2014-03-07 09:30:38


sorry ignore that code here is all of it .

var zombiespeed:Number = 2;
stage.addEventListener(Event.ENTER_FRAME,GetZombie3);

function GetZombie3(e:Event):void
{
	for (var r:int = ZombieOnstage3.length-1; r > -1; r--)
	{
		var currentZombie3:MovieClip = ZombieOnstage3[r];
		if (currentZombie3.hitTestObject(char2_mc))
		{  
			ZombieKilled3++;
			/*removeChild(currentZombie);*/
			
			ZombieOnstage3.splice(r,1);
			stage.removeEventListener(Event.ENTER_FRAME,GetZombie3);
			textfield.text = score.toString();
		    score+=1;
			currentZombie3.parent.removeChild(currentZombie3);
			
			addChild(GreenBlood_mc);
			GreenBlood_mc.x = currentZombie3.x;
			GreenBlood_mc.y = currentZombie3.y;
			GreenBlood_mc.gotoAndPlay(2);
			stage.addEventListener(Event.ENTER_FRAME,GetZombie3);
			
		}if (currentZombie3.hitTestPoint(char_mc.x, char_mc.y)){
			Energy_mc.width -= 5;
			if (Energy_mc.width <= 5)
			{
			char_mc.parent.removeChild(char_mc);
			addChild(blood_mc);
			blood_mc.x = char_mc.x
			blood_mc.y = char_mc.y
			blood_mc.gotoAndPlay(2);
			/*removeChild(char_mc);*/
			
			char_mc.x = 1000;
			char_mc.y = 1000;
			spawnChar2();
			}
		}
	}
}

stage.addEventListener(Event.ENTER_FRAME,GetZombie3);

function GetZombie31(e:Event):void
{
	for (var r:int = ZombieOnstage3.length-1; r > -1; r--)
	{
		var currentZombie3:MovieClip = ZombieOnstage3[r];
		if (currentZombie3.hitTestObject(special_mc))
		{  
			ZombieKilled3++;
			/*removeChild(currentZombie);*/
			
			ZombieOnstage3.splice(r,1);
			textfield.text = score.toString();
		    score+=1;
			currentZombie3.parent.removeChild(currentZombie3);
			stage.removeEventListener(Event.ENTER_FRAME,GetZombie31);
			GreenBlood_mc.x = currentZombie3.x;
			GreenBlood_mc.y = currentZombie3.y;
			GreenBlood_mc.gotoAndPlay(2);
			stage.addEventListener(Event.ENTER_FRAME,GetZombie31);
}
	}
	
	
}

Something about art?

lol excuse the hand

Response to Need little help 2014-03-07 09:33:41


So what you're doing is: every time a zombie dies, move the blood movieclip to it's position.

This causes the blood movieclip to be moved instead of there being a new blood image.

What you need to do is create a new blood movieclip every time a zombie dies:

function createBlood(x:int, y:int):void {
   var blood:GreenBlood = new GreenBlood();
   blood.x = x;
   blood.y = y;
   addChild(blood);
}

Response to Need little help 2014-03-07 09:57:54


ok i did this

function createBlood(x:int, y:int):void {
            var blood:GreenBlood = new GreenBlood();
            blood.x = currentZombie3.x;
            blood.y = currentZombie3.y;
            addChild(blood);
}

and it dose not show the blood at all ?


Something about art?

lol excuse the hand

Response to Need little help 2014-03-07 10:22:24


At 3/7/14 09:57 AM, evowolfdemon wrote: and it dose not show the blood at all ?

Calling the function helps.

Response to Need little help 2014-03-07 11:20:18


ok i put in this and when i hit a zombie it gos haywire and just adds tones of blood and moves across the screen and almost crashed flash X.x

ZombieOnstage3.splice(r,1);
			stage.removeEventListener(Event.ENTER_FRAME,GetZombie3);
			textfield.text = score.toString();
		    score+=1;
			currentZombie3.parent.removeChild(currentZombie3);
			stage.addEventListener(Event.ENTER_FRAME,GetBlood);
			function GetBlood(GreenBlood_mc):void  {
            var blood:GreenBlood = new GreenBlood();
            blood.x = currentZombie3.x;
            blood.y = currentZombie3.y;
            addChild(blood);

Something about art?

lol excuse the hand

Response to Need little help 2014-03-07 12:00:57


At 3/7/14 11:20 AM, evowolfdemon wrote: ok i put in this and when i hit a zombie it gos haywire and just adds tones of blood and moves across the screen and almost crashed flash X.x
stage.addEventListener(Event.ENTER_FRAME,GetBlood);
function GetBlood(GreenBlood_mc):void {
var blood:GreenBlood = new GreenBlood();
blood.x = currentZombie3.x;
blood.y = currentZombie3.y;
addChild(blood);

You are calling it when the ENTER_FRAME Event occurs, which happens to be 30 times a second (or whatever your framerate is)
As suggested in another thread, try to understand the code that you are writing.
If you tell it to add tons of movieclips, it's no surprise it actually does just that.
Just call the function, nobody said anything about ENTER_FRAME.

I recommend understanding the basics of programming As3.
Here's a link you can read.
http://code.tutsplus.com/series/as3-101--active-7395

Response to Need little help 2014-03-08 19:34:42


function createBlood(GreenBlood_mc):void {
var blood:GreenBlood = new GreenBlood();
blood.x = currentZombie3.x;
blood.y = currentZombie3.y;
addChild(blood);
}
createBlood(1);

it was so simple omg LMAO im so stupid X.x
thanks for the help guys


Something about art?

lol excuse the hand

Response to Need little help 2014-03-09 06:59:32


At 3/8/14 07:34 PM, evowolfdemon wrote: function createBlood(GreenBlood_mc):void {
var blood:GreenBlood = new GreenBlood();
blood.x = currentZombie3.x;
blood.y = currentZombie3.y;
addChild(blood);
}
createBlood(1);

it was so simple omg LMAO im so stupid X.x

Simple indeed, you could have just taken the function as it is and use it.
But for some strange reason you had to modify it, introducing a useless parameter, that's never used and narrowing the possible use of the function down.

Take a look at sandremss suggestion again and compare it to what you have now. I agree with you that the introduced changes are stupid, but why did you apply them then?

Response to Need little help 2014-03-09 12:39:58


i had to change it so that it would appear where the zombies were.


Something about art?

lol excuse the hand

Response to Need little help 2014-03-09 12:50:47


now if I can only get the zombies to follow my character around screen XD yeah still suck with this one X.x


Something about art?

lol excuse the hand

Response to Need little help 2014-03-09 13:15:33


At 3/9/14 12:39 PM, evowolfdemon wrote: i had to change it so that it would appear where the zombies were.

Again, that's what the two parameters were for.

Response to Need little help 2014-03-09 14:19:15


At 3/9/14 01:15 PM, milchreis wrote:
At 3/9/14 12:39 PM, evowolfdemon wrote: i had to change it so that it would appear where the zombies were.
Again, that's what the two parameters were for.

ok i tied it like this

function createBlood(x:int, y:int):void {
   var blood:GreenBlood = new GreenBlood();
   blood.x = x;
   blood.y = y;
   addChild(blood);
}

createBlood(1);


Something about art?

lol excuse the hand

Response to Need little help 2014-03-09 14:27:45


At 3/9/14 02:19 PM, evowolfdemon wrote: ok i tied it like this

function createBlood(x:int, y:int):void {
var blood:GreenBlood = new GreenBlood();
blood.x = x;
blood.y = y;
addChild(blood);
}

createBlood(1);

Which is obviously nonsense.
Do you even think about this stuff or do you just make it up?

Response to Need little help 2014-03-09 16:49:56


At 3/9/14 02:19 PM, evowolfdemon wrote:
At 3/9/14 01:15 PM, milchreis wrote:
At 3/9/14 12:39 PM, evowolfdemon wrote: i had to change it so that it would appear where the zombies were.
Again, that's what the two parameters were for.
ok i tied it like this

function createBlood(x:int, y:int):void {
var blood:GreenBlood = new GreenBlood();
blood.x = x;
blood.y = y;
addChild(blood);
}

createBlood(1);

Your createBlood method takes the position that the blood should be created as X and Y co-ordinates, yet when you call it, you pass it a single parameter of 1. Do you see the problem here?

It seems you don't understand scope, I'd really suggest you revisit the basics - but good luck with your game anyway.

Response to Need little help 2014-03-10 03:03:47


well not knowing much of what i'm doing i sure have an alright game. It takes me a while to grasp things. Thanks for the help and support. Try to be little nicer with me i promise im not trying to be annoying with the code. By the way I have the zombies following my character now and here is the code that I have for it .

zombie3.addEventListener(Event.ENTER_FRAME,movezombie3);
		function movezombie3(e:Event):void
		{
			if (e.target.x < char_mc.x)
			{
				e.target.x +=  2.6;
			}
			if (e.target.y < char_mc.y)
			{
				e.target.y +=  2.6;
			}
			if (e.target.x > char_mc.x)
			{
				e.target.x -=  2.6;
			}
			if (e.target.y > char_mc.y)
			{
				e.target.y -=  2.6;
			}
			if (e.target <= -3)
			{

Something about art?

lol excuse the hand