BackDoor- Door 1
You find yourself in a strange house with only a man on the phone as a guide.
4.08 / 5.00 28,326 ViewsMini Commando
Action adventure game with nazi enemies in the second world war.
3.89 / 5.00 24,752 Viewshey. I'm trying to make a platformer in which the entire world is supposed to move around the player as well as the player being in control of a character.
right now I'm battling with the rotation function in actionscript.
here's my code:
function rotateStage(e:Event){
if(leftKeyPush && rightKeyPush) return;
if(leftKeyPush) World.rotation = 90;
if(rightKeyPush) World.rotation = -90;
}
'leftKeyPush' and 'rightKeyPush' are what detect if the arrow keys are being pressed
My intended function is that when you hit left, the world turns 90 degrees to the left, and vice versa. but it's not doing it, and I'm not sure why
there are no compiler errors (yay. -.-) and the keys have been assigned correctly
thanks for reading
Elephants only come out at night, for they are nocturnal. If they go out during the daylight, they melt.
At 3/14/13 11:47 AM, voter96 wrote: My intended function is that when you hit left, the world turns 90 degrees to the left, and vice versa. but it's not doing it, and I'm not sure why
there are no compiler errors (yay. -.-) and the keys have been assigned correctly
thanks for reading
Have you tried putting trace statements in the conditionals to make sure they work? What exactly is World, like what class is it and all?
Look no further: http://msghero.newgrounds.com/
At 3/14/13 12:03 PM, MSGhero wrote: Have you tried putting trace statements in the conditionals to make sure they work? What exactly is World, like what class is it and all?
World is the instance name of a movieclip which sits on my stage. It's been exported for actionscript.
I'm looking up what trace statements and conditionals are right now, but I'm not entirely sure what you mean by those. the fact I'm having to look them up probably means that I haven't
Elephants only come out at night, for they are nocturnal. If they go out during the daylight, they melt.
At 3/14/13 12:24 PM, voter96 wrote:At 3/14/13 12:03 PM, MSGhero wrote: Have you tried putting trace statements in the conditionals to make sure they work? What exactly is World, like what class is it and all?World is the instance name of a movieclip which sits on my stage. It's been exported for actionscript.
I'm looking up what trace statements and conditionals are right now, but I'm not entirely sure what you mean by those. the fact I'm having to look them up probably means that I haven't
if (leftKeyPush) { // conditional
trace("K"); // trace: if "K" gets output, the line below will run; if not, the line below will not run
World.rotation = 90;
} Look no further: http://msghero.newgrounds.com/
At 3/14/13 12:33 PM, MSGhero wrote: if (leftKeyPush) { // conditional
trace("K"); // trace: if "K" gets output, the line below will run; if not, the line below will not run
World.rotation = 90;
}
thanks very much, and it turns out that the line isn't being run at all. my only guess right now is that there's something wrong with the key recognition
Elephants only come out at night, for they are nocturnal. If they go out during the daylight, they melt.
if anyone is still reading this, I could still do with some help.
I know that it's not finding any errors in my code, and that it's not detecting when I press keys or release them. I can't see anything wrong with my code
here's the code I have for detecting key presses:
function pressKey(k:KeyboardEvent){
switch (k.keyCode){
case(37) : leftKeyPush = true; break;
case(39) : rightKeyPush = true;
}
}//end of pressKey
function releaseKey(k:KeyboardEvent){
switch(k.keyCode){
case(37) : leftKeyPush = false; break;
case(39) : rightKeyPush = false;
}
}//end of releaseKey
Elephants only come out at night, for they are nocturnal. If they go out during the daylight, they melt.
package {
import flash.events.*;
import flash.display.MovieClip;
import flash.media.*;
import fl.motion.easing.Back;
public class Rotating extends MovieClip{
//class variables
var leftKeyPush, rightKeyPush: Boolean = false;
public function Rotating() {
// constructor code
stage.addEventListener(KeyboardEvent.KEY_DOWN, pressKey);
stage.addEventListener(KeyboardEvent.KEY_UP, releaseKey);
}
public function pressKey(k:KeyboardEvent){
switch (k.keyCode){
case(37) : leftKeyPush = true; break;
case(39) : rightKeyPush = true;
}
}//end of pressKey
public function releaseKey(k:KeyboardEvent){
switch(k.keyCode){
case(37) : leftKeyPush = false; break;
case(39) : rightKeyPush = false;
}
}//end of releaseKey
public function rotateStage(e:Event){
trace("k");
if(leftKeyPush) World.rotation = 90;
if(rightKeyPush) World.rotation = -90;
}
}
}
changed rotate to Rotating, which is actually the constructor of the class, I removed the listeners from the constructor and made them a class method.
At 3/14/13 03:09 PM, GeoKureli wrote: changed rotate to Rotating, which is actually the constructor of the class, I removed the listeners from the constructor and made them a class method.
tried this, same result. no errors, and nothing happened :c
Elephants only come out at night, for they are nocturnal. If they go out during the daylight, they melt.
At 3/14/13 04:06 PM, voter96 wrote:At 3/14/13 03:09 PM, GeoKureli wrote: changed rotate to Rotating, which is actually the constructor of the class, I removed the listeners from the constructor and made them a class method.tried this, same result. no errors, and nothing happened :c
Probably because you are adding the listeners in the constructor, before it gets added to the stage. Give it an event listener for ADDED_TO_STAGE, and add the keyboard listeners there. I seem to recall that stage is only accessible to a mc on the display list.
At 3/14/13 04:14 PM, Mattster wrote: Probably because you are adding the listeners in the constructor, before it gets added to the stage. Give it an event listener for ADDED_TO_STAGE, and add the keyboard listeners there. I seem to recall that stage is only accessible to a mc on the display list.
sorry, I'm not sure what you mean. what kind of listener would that be?
If I'm reading what you just said right, I should point out that nothing is being put on the stage by coding - World is there already.
Elephants only come out at night, for they are nocturnal. If they go out during the daylight, they melt.
At 3/14/13 04:14 PM, Mattster wrote:At 3/14/13 04:06 PM, voter96 wrote:Probably because you are adding the listeners in the constructor, before it gets added to the stage. Give it an event listener for ADDED_TO_STAGE, and add the keyboard listeners there. I seem to recall that stage is only accessible to a mc on the display list.At 3/14/13 03:09 PM, GeoKureli wrote: changed rotate to Rotating, which is actually the constructor of the class, I removed the listeners from the constructor and made them a class method.tried this, same result. no errors, and nothing happened :c
blah how did I miss this
addEventListener(Event.ADDED_TO_STAGE, init);
then you can reference the stage in init.
also if you got no errors then you're never instantiated your Rotating class (new Rotating())
At 3/14/13 04:30 PM, GeoKureli wrote: blah how did I miss this
addEventListener(Event.ADDED_TO_STAGE, init);
then you can reference the stage in init.
also if you got no errors then you're never instantiated your Rotating class (new Rotating())
like this:
stage.addEventListener(Event.ADDED_TO_STAGE, rotateStage);
or like this?:
stage.addEventListener(Event.ADDED_TO_STAGE, pressKey, releaseKey);
Elephants only come out at night, for they are nocturnal. If they go out during the daylight, they melt.
At 3/14/13 04:42 PM, voter96 wrote:At 3/14/13 04:30 PM, GeoKureli wrote:like this:
stage.addEventListener(Event.ADDED_TO_STAGE, rotateStage);
only if you want roatateStage to be called once. it seems like you want it to be called every frame
or like this?:
stage.addEventListener(Event.ADDED_TO_STAGE, pressKey, releaseKey);
those functions are key listeners, and you can't pass 2 at once
You're confusing events, here's a reference guide to events
Event.ADDED_TO_STAGE: gets called when the object gets added to the display list so this would be called if you said
addChild(myObj); if myObj has an ADDED_TO_STAGE event, this would trigger it.
Event.ENTER_FRAME: gets called every frame, commonly used for an update function
KeyboardEvent.KEY_DOWN: usually applied like so: stage.addEventListener(KeyboardEvent.KEY_DOWN, myFunc), so that myFunc() gets called whenever a key is pressed
KeybooardEvent.KEY_UP: same as key down, but when a key is released.
these are your tools, use them wisely, and seriously try googling "as3 events for beginners"
At 3/14/13 06:18 PM, GeoKureli wrote:
You're confusing events, here's a reference guide to events
Event.ADDED_TO_STAGE: gets called when the object gets added to the display list so this would be called if you said
addChild(myObj); if myObj has an ADDED_TO_STAGE event, this would trigger it.
Event.ENTER_FRAME: gets called every frame, commonly used for an update function
KeyboardEvent.KEY_DOWN: usually applied like so: stage.addEventListener(KeyboardEvent.KEY_DOWN, myFunc), so that myFunc() gets called whenever a key is pressed
KeybooardEvent.KEY_UP: same as key down, but when a key is released.
these are your tools, use them wisely, and seriously try googling "as3 events for beginners"
okay, I'll google some tut's.
my tutor has not taught me well enough. either that or I just jumped the shark. I probably jumped the shark. I do that a lot.
I do have a question though, I said that nothing is being added to the stage using code, and yet you told me to put in a listener for when something is added to the stage? why?
Elephants only come out at night, for they are nocturnal. If they go out during the daylight, they melt.
At 3/14/13 06:42 PM, voter96 wrote: I do have a question though, I said that nothing is being added to the stage using code, and yet you told me to put in a listener for when something is added to the stage? why?
if your just drag things onto the stage in flash, they are still being added to the stage, and you can't call stageAddEventListener until the ADDED_TO_STAGE event is dispatched, which will get called whether you add them in code or not.