Copy link to clipboard
Copied
I know Ive been posting a lot of questions, but its only because this forum has been so helpful with solving my problems. So I have the right code for movement and collision, but my items on stage are arranged in a way that make it difficult for the code to access. The moving object is on the base level, but the walls are part of the background so they have to be in the background MovieClip. (Otherwise they wont scroll when the background does) So how can I call the child movie clips, which all have the same instance name, without confusing the program? Ive tried MovieClip(getChildByName("wall")) but although the program runs with no errors, it ignores all code after that. Heres the full line for reference: Collision.block(character, MovieClip(getChildByName("wall"))); And if you need it the Collision class I'm using is found here: [ActionScript 3] Collision Class - Pastebin.com
I see that Collision works differently to how I thought it worked. You call it like:
Collision.block(pseudocharacter,wallmc);
and then look at Collision.collisionSide to find out which direction was hit.
When I've told you to set the fake wall x value, you would also need to be setting its y value if the character can move up and down.
You would name the real walls with the same name, and then your fake wall moving code could look like this:
var i;
var realwallmc: MovieClip;
var fakewallmc: MovieClip;
f
...Copy link to clipboard
Copied
You could put alpha zero versions of the walls at the same level as the character. Those copies x value ought to be the same as the real wall x value minus the background movieclip's x value.
The Collision class is reading the width of the symbol, and so may have the same issue you've had before. A way around that would be to have a rectangle that is a representative width for the character, perhaps the average of all the widths the character goes through. Again, that rectangle could be alpha zero, so the user doesn't see it, and its x value would always be set to match the character's x value.
With those three invisible things at the same level it would be easier to use the block function.
Copy link to clipboard
Copied
i think I understand the concept, but I'm having trouble figuring out how create alpha zero versions of my wall movie clip. (Its actually calling the wall movie clip multiple times and I transformed it in width to fit each border.) I pulled a copy of the frame with the movie clips up to the main level, but if I edit the alpha in the movie clip, it will effect the ones in background. So I Clicked color effect and set it to alpha, and then 0%. The code works, but still ignores the walls.
Copy link to clipboard
Copied
Try setting the alpha to 50 in properties, then you can see if your dummy walls are moving.
Also, they should each have a unique name. Like, leftwall, rightwall.
Copy link to clipboard
Copied
Hum... Not sure how to go about naming all of them, (theres 10, but I guess I can do that) but for now, let me see if I have this, because right now the walls aren't moving. I originally set them at the same point as the visible copies, but rereading your first comment, it should be minus the background clips x too... but, I'm not sure how I find that location? I know theres a code for this huh...
Copy link to clipboard
Copied
You're going to be moving them with code, so you don't need to look at where the background is when you're not testing. You don't even need to set the location of the fake walls at all, that will get set every frame. If you've added that part to your enterframe function.
Not sure why you have 10 walls, but one approach would be:
var i;
var wallmc:MovieClip;
var hitwall:Boolean;
var wallnumber:int = 0;
for(i=0;i<10;i++){
wallmc = this["wall"+(i+1)];
hitwall = Collision.block(pseudocharacter,wallmc);
if(hitwall){
wallnumber=i+1;
break;
}
}
If you get past that and wallnumber is not 0, you hit something. The wallnumber value would tell you which wall you hit.
The above assumes that you named the 10 fake walls as wall1, wall2, etc.
Copy link to clipboard
Copied
Well I have a lot of walls since Im doing a big maze type level, I actually want to be able to flip the gravity and view of background at some point. At this point, here is the current playable product: LV one Demo - mars714's Sta.sh (I'll work on gravity more once the collision works) At any rate, your code returned one warning, void used where a Boolean value was expected. The expression will be type corrected as Boolean. I have the walls numbered, but I'm not sure what to put as the instance name for the original walls.
Copy link to clipboard
Copied
I see that Collision works differently to how I thought it worked. You call it like:
Collision.block(pseudocharacter,wallmc);
and then look at Collision.collisionSide to find out which direction was hit.
When I've told you to set the fake wall x value, you would also need to be setting its y value if the character can move up and down.
You would name the real walls with the same name, and then your fake wall moving code could look like this:
var i;
var realwallmc: MovieClip;
var fakewallmc: MovieClip;
for (i = 0; i < 10; i++) {
realwallmc = backgroundmc["wall" + (i + 1)];
fakewallmc = this["wall" + (i+1)];
fakewallmc.x = realwallmc.x - backgroundmc.x;
fakewallmc.y = realwallmc.y - backgroundmc.y;
}
Copy link to clipboard
Copied
Okay I feel like Im really close now, every export it loads no errors but the code fails to work. I now have two movie clips for wall, fakewall and realwall, the ones inside background have the instance name wall, the ones on base level have instance names, wall1, wall2, etc. I believe my problem is, which do I put in collision class? Fakewall? I tried that, but it seems not not work...
Copy link to clipboard
Copied
The real walls should have matching names, wall1, wall2, etc. Being inside a movieclip they won't get confused with the higher level fake ones.
My last code was for getting fake walls of the same name to follow the real walls.
Copy link to clipboard
Copied
Your code goes in the enterFrame function, but in what order do I list it with the existing code? That is code controls the background, mostly if statements. Also I assume that all var properties go at the top. As of now upon export, the enterFrame function seems to be ignored. The character moves but the background doesn't. Here's my full code right now: [ActionScript 3] demo code - Pastebin.com
Copy link to clipboard
Copied
I would put my variables in the enterframe function. They're not needed outside of that.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now