I'm making a game blah blah blah, but I have an issue that I hope is simple to solve.
There is the main character, and lining the screen are four graphics of walls within one symbol. The problem is, because it is in one symbol, the whole screen is technically this symbol and the four directional hitTests trigger all the time, so the character can't move.
Is there some way to make hitTest only register for graphical hits, and not empty space created by the symbol's box?
And I want to avoid clunky code which has a separate hitTest for every wall.
Actionscript: HitTest with one symbol
Started by: Bonk | Replies: 16 | Views: 1,604
Apr 26, 2008 10:29 AM #123724
Apr 26, 2008 11:56 AM #123738
the seperate wall parts is the only way I can think of. You should just make them all the same instance name then put in the frame the code for the hero hitting the wall or whatever.
Apr 26, 2008 2:35 PM #123792
You can't give more than one symbol the same instance name...
Apr 26, 2008 3:01 PM #123798
If the frame isn't moving, you can make the character appear on the other side of the frame, by using this code
You could also use AS to draw the boundaries in but that is a lot of work. >_>
If(this._x > stagex){
//stagex is a global variable on the frame and is equal to the maximum x value of the frame
this._x = 0;
}
ElseIf(this._x < 0){
this._x = stagex;
};
You could also use AS to draw the boundaries in but that is a lot of work. >_>
Apr 26, 2008 3:16 PM #123813
Quote from bonkYou can't give more than one symbol the same instance name...
I can, dunno why you can't.
Apr 27, 2008 12:47 AM #124142
Quote from SteinerIf the frame isn't moving, you can make the character appear on the other side of the frame, by using this code
If(this._x > stagex){
//stagex is a global variable on the frame and is equal to the maximum x value of the frame
this._x = 0;
}
ElseIf(this._x < 0){
this._x = stagex;
};
You could also use AS to draw the boundaries in but that is a lot of work. >_>
Nah, I'm planning a bigger game where there is a scrolling landscape with more walls, so that wouldn't work.
Hmm, maybe I'll try "drawing the boundaries". I'll have to look it up though.
Quote from ScorpioxxxI can, dunno why you can't.
You can give them the same instance name, but only the original registers in code.
Apr 27, 2008 1:52 AM #124210
The easiest way to to make 4 different walls and put the code on the wall. So if the code on the character is like this
onClipEvent(enterFram){
If(this.hittest(wall1)){
_x = 10
}
}
Change it to smoething like this and put it on the wall
onClipEvent(enterFram){
If(this.hittest(player)){
_x = 10
}
}
I just chose _x = 10 as a random movement code, you can make it whatever you want.
EDIT:
The plus side of putting the hittest on the wall is that you don't have to give instance names to them all, once you make one you can copy and paste the rest. with only having to give one instance name to the player.
onClipEvent(enterFram){
If(this.hittest(wall1)){
_x = 10
}
}
Change it to smoething like this and put it on the wall
onClipEvent(enterFram){
If(this.hittest(player)){
_x = 10
}
}
I just chose _x = 10 as a random movement code, you can make it whatever you want.
EDIT:
The plus side of putting the hittest on the wall is that you don't have to give instance names to them all, once you make one you can copy and paste the rest. with only having to give one instance name to the player.
Apr 27, 2008 2:22 AM #124231
Steiner's solution would work even if you had a bigger game. Just set the stagex and shit variables on each frame the boundaries change.
Apr 27, 2008 2:47 AM #124257
Quote from KitsuneSteiner's solution would work even if you had a bigger game. Just set the stagex and shit variables on each frame the boundaries change.
The rooms aren't all going to be square...
Quote from Rather CheesyThe easiest way to to make 4 different walls and put the code on the wall. So if the code on the character is like this
onClipEvent(enterFram){
If(this.hittest(wall1)){
_x = 10
}
}
Change it to smoething like this and put it on the wall
onClipEvent(enterFram){
If(this.hittest(player)){
_x = 10
}
}
I just chose _x = 10 as a random movement code, you can make it whatever you want.
EDIT:
The plus side of putting the hittest on the wall is that you don't have to give instance names to them all, once you make one you can copy and paste the rest. with only having to give one instance name to the player.
I was hoping to avoid that. I'm trying to code most of it from the frame and not use separate code for each object.
But that might be the only way. Thanks.
Apr 27, 2008 2:56 AM #124266
Quote from bonkThe rooms aren't all going to be square...
But that might be the only way.
It doesn't matter if they all aren't going to be square. This is where you come in with the programming logic you were CLEARLY given. You program the walls you want in their own codes individually.
The only way? There is no "Only Way" in actionscript, or any other programming for that matter. There is only a vocabulary and a sense of logic that you need.
Apr 27, 2008 3:04 AM #124278
Wait, what?
Explain what Steiner's code does. I though it just made it so you cannot leave the stage.
Explain what Steiner's code does. I though it just made it so you cannot leave the stage.
Apr 27, 2008 3:21 AM #124290
You set a variable boundry called stagex that doesn't allow you to leave through that variable. If you have like a wall in the middle of a room that goes through the center and reaches to the middle, just make variables for that wall too. xstage and ystage would set the variables to not leave the room (if you can code with logic, cannot leave the room except through a door), but you can make more for more obstacles.
Makes sense?
Makes sense?
Apr 27, 2008 4:05 AM #124339
I see. But what if I wanted to make a wall that covered half the screen on one edge?
And this would be hard for a scrolling landscape...
And this would be hard for a scrolling landscape...
Apr 27, 2008 4:50 AM #124382
Quote from bonkI see. But what if I wanted to make a wall that covered half the screen on one edge?
And this would be hard for a scrolling landscape...
try this shit then. Use a vcam that follows your guy in the code's _x variable assigning, and do this:
if(this.hitTest(_root.wallmc and _x>=_root.wallmc._x)
_x=_root.wallmc._x-2
Left of a jutting wall. Getting it?
Apr 27, 2008 6:44 AM #124526
_root.wallmc
I'm trying to stay away from specific instance names for every single wall and matching code.
But, yeah I've done it so thanks anyway.
I'm trying to stay away from specific instance names for every single wall and matching code.
But, yeah I've done it so thanks anyway.