hi guys, i got a project which im stuck with :p. firstly i’m kinda noob with flash >.< so forgive my messy codes
i have a project where i need to make a small game, im planning to make something that the characters move around and find object which on hitTest the object will stick to the player.
i have this script which i tested using mc that i made and works
if (this.hitTest(_root.player.hitter)) {
if ((playerLoaded === "nothing") || (playerLoaded == this.boxType)) {
this._x = _root.player._x;
this._y = _root.player._y+76;
playerLoaded = this.boxType;
itemHasBeenDragged = true
}
}
// when the player lose grip
if ((itemHasBeenDragged) && (not this.hitTest(_root.player.hitter)) ) {
playerLoaded = "nothing";
this._y += 25;
}
the basic idea is the box will “stick” because as long as hitTest true it follows the player’s position until the movement of the player (specifically the vertical movement when the player goes up) make the hitTest false and consider the object “dropped”
however my problem is i want to create the object dynamically using action script, so when i picked an object an interval is set to generate a new object 3 seconds after i picked the first one. these are what im trying to do with the AS generated mc
testSpawn = function() {
if (generatedBox < maximumBoxes){
trace("I MAKE A BOX")
var boxColor
i++
boxToGenerate = random(3)
switch(boxToGenerate){
case 0:
boxColor = "BlueBox"
break
case 1:
boxColor = "RedBox"
break
case 2:
boxColor = "YellowBox"
break
}
trace("BOX COLOR " + boxColor)
var newBox:MovieClip = _root.mc_spawnBox.attachMovie(boxColor, "box"+i, 100+i)
newBox._y -= 30
newBox.boxType = boxColor
generatedBox++
};
}
}
spawnerInterval = setInterval(this, "testSpawn", delay)
delay is set to 3000, as to “attach” the sticky script to the generated mc i tried using
**newBox.onEnterFrame = function()** {
if (this.hitTest(_root.player.hitter)) {
if ((playerLoaded === "nothing") || (playerLoaded == this.boxType)) {
this._x = _root.player._x;
this._y = _root.player._y+76;
playerLoaded = this.boxType;
itemHasBeenDragged = true
}
}
// when the player lose grip
if ((itemHasBeenDragged) && (not this.hitTest(_root.player.hitter)) ) {
playerLoaded = "nothing";
this._y += 25;
}
well it works… to some degree but with messy result my brain is kinda stuck trying to find how this kind of thing should be done, i’m very grateful if someone can come up with any help, suggestion or trick to solve this =)