Home Tutorials Forums Articles Blogs Movies Library Employment Press
Prev Previous Post   Next Post Next
Old 04-14-2012, 04:26 PM   #1
Registered User
Join Date: Apr 2012
Posts: 1
Default [AS3] game acting glitchy

Hi im just trying to make a simple platform game but the character keeps bouncing off the floor like its glitching, i can still move and jump he just keeps bouncing, and wen i go up to walls he go to the top of them how can i fix that, heres the code

import flash.events.KeyboardEvent;
import flash.events.Event;

//some variables to track the players speed

var speedX=0;
var speedY=0;

// loop through all platform objects to generate a level

var level:Array = new Array();
for (var i=0; i<numChildren; i++) {
if (getChildAt(i) is Platform) {

// make variables to store key states

var kUp = false;
var kDown = false;
var kLeft = false;
var kRight = false;

//listen for key presses and release

stage.addEventListener(KeyboardEvent.KEY_DOWN, kD);
stage.addEventListener(KeyboardEvent.KEY_UP, kU);

function kD(k:KeyboardEvent) {
if (k.keyCode==37) kLeft=true;
if (k.keyCode==38) kUp=true;
if (k.keyCode==39) kRight=true;
if (k.keyCode==40) kDown=true;
function kU(k:KeyboardEvent) {
if (k.keyCode==37) kLeft=false;
if (k.keyCode==38) kUp=false;
if (k.keyCode==39) kRight=false;
if (k.keyCode==40) kDown=false;

// Make a looping function

addEventListener(Event.ENTER_FRAME, loop);
function loop(e:Event) {

// Horizontal movement

if (kLeft) {
} else if (kRight) {
} else {
speedX*=0.5; // friction

//Horizontal hit tests

for (i=0; i<level.length; i++) {
if (player.getRect(this).intersects(level[i])) {
if (speedX > 0) { //moving right
player.x = level[i].left-player.width/2;
if (player.getRect(this).intersects(level[i])) {
if (speedX < 0) { //moving left
player.x = level[i].right+player.width/2;
speedX=0; // kill the speed

//Vertical checks

// Gravity

var jumpable=false;

//hit tests
for (i=0; i<level.length; i++) {
if (player.getRect(this).intersects(level[i])) {
if (speedY > 0) { //moving down
player.y = level[i].top-player.height/2;
if (speedY < 0) { //moving up
player.y = level[i].bottom+player.height/2;
speedY=0; // kill the speed

// jump if possible

if (kUp && jumpable) {
speedY=-20; // jump height

// move the camera with the player

this.x=-player.x+(stage.stageWidth/2); // center the player

//if (speedX >-0.5 && speedX < 0.5) {
//} else {

heavyartilary117 is offline   Reply With Quote

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT. The time now is 06:30 AM.

Follow actionscriptorg on Twitter


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.