PDA

View Full Version : RPG: drag&drop problem



marcogiannini
September 13th, 2008, 12:27 PM
hi all,
I've built this simple engine for Roleplaying game; it's an engine that permits to store a coin in a backpack and retrieve it as soon as needed.
It is fully usable, but the retrieveCoin function doesn't go, maybe because of a targeting problem (???); I'm struggling on it since a few days, can any expert coder help me please? I'm full of endless gratitude to anyone will gimme a hint

Functions are scattered through different layers in order to make them recognizable and have the attachCoin function well separated... this introduce the second problem: it comes at the beginnig, I'm not sure how to handle the initial function that scatters coins all over the screen. I need to make them appear many time, in some different position, so I guess I need an array to drive each one at its position, via the attachCoin function

fla in attachment (CS3, but AS 2.0)

thank a lot you all in advance

Smee
September 13th, 2008, 01:11 PM
You're assigning 'coinRelease' to the onRelease of 'coin2_mc' at a time when coin2_mc doesn't exist. I think that should be inside of your 'retrievecoin' function, after the 'coin2_mc' instance is created.

But then you have another problem; the onRelease function won't run unless that's the button you pressed down. What you're doing is using the onPress function of the backpack to create the 'coin2_mc', and then you use 'startDrag' to drag it; so you've pressed down on the backpack, not the 'coin2_mc', which means the onRelease of 'coin2_mc' will not run when you release. You may want to use onMouseDown and onMouseUp.

marcogiannini
September 13th, 2008, 02:38 PM
Ok, thanks for response. Sorry I'm a newbie in Flash, not so good in coding. Anyway this coin engine can be a great enhancement to a game I'm developing, so I'm ready to clean my mind and send all I've done till now to the trash :td:
My issue are:
1) Reuse the coins I've picked up to spend them in a shop, more than one say 2 or 3 coins to buy an object; obviously the instance name MUST NOT BE the reference I point to in an array or whichever method I use to buy objects, 'cause it's not important WHICH coin I use but HOW MANY, right?. Have you some clues? :beam:
2) I have place ALWAYS THE SAME COIN SYMBOL in different scenes: I thought I can use a single function, say attachCoin.
This can be the code:

function attachCoin():Void {
var mc:MovieClip = attachMovie(symbol, symbol+nCoins++, initialDepth+nCoins, {id:nCoins, _x: 300, _y: 200});
}

I think I have to specify _x and _y position EVERYtime I call it... or I have to use an array?

3) Talking about onMouseDown and onMouseUp, can I use hitTest with it in the same way I used in the engine you analyzed?

thanks a lot for help, I'm struggling with it from two weeks....