Remove Ads

Share on Facebook Share on Twitter

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Gaming Tutorial (How to Make Movable Items)
#1
Welcome back to the Continued Tutorial How to make Movable items

in this tutorial ill give 2 examples of moving items,

1 Moving a item by htting it(like in in RAX II)

2 Moving a item with the mouse by "dragging it" (just the basics)

we'll start with the first one

first of all you must of done the 2 previous tutorials
which can be found here:
first one:
http://graphicsfans.createmybb.com/showt...php?tid=23
Second one:
http://graphicsfans.createmybb.com/showt...php?tid=44

then (if u didnt do this yet) give the character a name (same as the wall thing)

lets call it "char" to keep things simple

then draw a box or something thats looks like an item
also give it a name, also to keep it simple name it: "box"

and now on the box: right click->actions

put in:
Code:
onClipEvent (enterFrame) {
    while (_root.char.hitTest(getBounds(_root).xMax, this._y, true)) {
        this._x--;
    }
    while (_root.char.hitTest(getBounds(_root).xMin, this._y, true)) {
        this._x++;
    }
    while (_root.char.hitTest(this._x, getBounds(_root).yMax, true)) {
        this._y--;
    }
    while (_root.char.hitTest(this._x, getBounds(_root).yMin, true)) {
        this._y++;
    }
}


now this is kindof buggy cause u can push your item out of a wall so we'll
handle that right now:
same as in the character, give these actions also to the box
under
Code:
    while (_root.char.hitTest(this._x, getBounds(_root).yMin, true)) {
        this._y++;
    }

and above
Code:
}

put this:
Code:
while (_root.wall.hitTest(getBounds(_root).xMax, this._y, true)) {
this._x--;
}
while (_root.wall.hitTest(getBounds(_root).xMin, this._y, true)) {
this._x++;
}
while (_root.wall.hitTest(this._x, getBounds(_root).yMax, true)) {
this._y--;
}
while (_root.wall.hitTest(this._x, getBounds(_root).yMin, true)) {
this._y++;
}

so the complete code of the box will be:
Code:
onClipEvent (enterFrame) {
    while (_root.char.hitTest(getBounds(_root).xMax, this._y, true)) {
        this._x--;
    }
    while (_root.char.hitTest(getBounds(_root).xMin, this._y, true)) {
        this._x++;
    }
    while (_root.char.hitTest(this._x, getBounds(_root).yMax, true)) {
        this._y--;
    }
    while (_root.char.hitTest(this._x, getBounds(_root).yMin, true)) {
        this._y++;
    }
    while (_root.wall.hitTest(getBounds(_root).xMax, this._y, true)) {
        this._x--;
    }
    while (_root.wall.hitTest(getBounds(_root).xMin, this._y, true)) {
        this._x++;
    }
    while (_root.wall.hitTest(this._x, getBounds(_root).yMax, true)) {
        this._y--;
    }
    while (_root.wall.hitTest(this._x, getBounds(_root).yMin, true)) {
        this._y++;
    }
}


thats Tutorial 1


Will be continiued, have to eat for a sec(ill edit the post)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Gaming Tutorial (how to walk) Ghettobird 12 2,108 06-23-2006, 07:17 PM
Last Post: Ghettobird
  Gaming Tutorial (how to make Walls) Ghettobird 2 702 06-21-2006, 06:58 AM
Last Post: Ghettobird
  Basic tutorial [make a button] Ghettobird 0 496 06-20-2006, 05:00 AM
Last Post: Ghettobird

Forum Jump:


Users browsing this thread: 1 Guest(s)