Copy link to clipboard
Copied
I'm mainly working with an older version. I tried to get the character touch an item which goes to an inventory slot. I got the code off of youtube. For some reason the character won't touch the item as the character just passes it, is something wrong with the code?
the symbol and instance of this code is: item
onClipEvent(enterFrame) {
if(_root.char.hitTest(this)) {
_root.addToSlot(this);
}
}
----------------------
the symbol and instance of this code is: itemslot
Inventory Code (Put In Frame):
currentslotnum = 1;
stop();
function addToSlot(item){
if(!item.found){
item._x = eval ("itemslot" + currentslotnum)._x;
item._y = eval ("itemslot" + currentslotnum)._y;
item.found = true;
currentslotnum++;
}
}
-----------------------
the symbol of this code is: character
the instance of this code is: char
character code:
onClipEvent (load) {
var ground:MovieClip = _root.ground;
var grav:Number = 0;
var gravity:Number = 2;
var maxspeed:Number = 10;
var xspeed:Number = 0;
var acceleration:Number = 2;
var maxJump:Number = -15;
var friction:Number = 0.9;
var yspeed:Number = 0;
var bounce:Number = -0.9;
var touchingGround:Boolean = false;
}
onClipEvent (enterFrame) {
xspeed *= friction;
if (Math.abs(speed) < 0.3) {
xspeed = 0;
}
_y += grav;
grav += gravity;
while (ground.hitTest(_x, _y, true)) {
_y -= gravity;
grav = 0;
}
if (ground.hitTest(_x, _y+5, true)) {
touchingGround = true;
} else {
touchingGround = false;
}
if (Key.isDown(Key.RIGHT)) {
if ( xspeed < maxspeed ) {
xspeed += acceleration;
}
}
if (Key.isDown(Key.LEFT)) {
if ( Math.abs(xspeed) < maxspeed ) {
xspeed -= acceleration;
}
}
if (Key.isDown(Key.UP) && touchingGround) {
grav = maxJump;
}
if (ground.hitTest(_x+(_width/2), _y-(_height/2), true)) {
acceleration = -2;
xspeed = 0;
xspeed += acceleration;
_x += xspeed ;
}else{
acceleration = 2;
}
if (ground.hitTest(_x-(_width/2), _y-(_height/2), true)) {
acceleration = -2;
xspeed = 0;
xspeed -= acceleration;
_x += xspeed ;
}else{
acceleration = 2;
}
if (ground.hitTest(_x-(_width/2), _y-(_height/2), true)) {
_x += xspeed;
}
if (ground.hitTest(_x, _y-(height), true)) {
grav = 3;
}
_x += xspeed;
}
Copy link to clipboard
Copied
1. that's as2. are you using an old version of flash (not animate)?
2. do you know how to use the trace function to debug as2?
Copy link to clipboard
Copied
I heard flash 8 was more basic the animate. I tried to use animate some but it was a little confusing so I tried flash 8 because of the tutorials there.
Unless theres tutorials here on animate I don't know what to do.
Copy link to clipboard
Copied
there are lots of animate tutorials. do you have animate (and a current subscription)?
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more