473,486 Members | 2,359 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Character Coin Collection Confusion

52 New Member
Hi I'm using AS2 to produce a simple platform game. So far so good I would like the character to collect coins or whatever. so what I have done is create a coin movie clip, I've run a hittest on the coin and my character and when this = true set the coin to _visible = false, move it way off screen and add 10 point to the _global.score. all is working fine but I haven't a clue about having more than one instance of the coin, or more precisely I do have a clue but I don't want to have to name all the instances differently and have reams of if statements (one for each instance). I'm sure that there is an easier way and I guess that I just need some direction.

I am new to AS2 so please go easy on me.
Mar 5 '09 #1
18 3282
Markus
6,050 Recognized Expert Expert
The duplicateMovieClip() method may help you here.
Mar 5 '09 #2
Chinde
52 New Member
am I right in thinking that the duplicate method requires you to rename each instance?? so if I wanted to refer to a particular instance I would need to still have a separate set of code for each hit test??
Mar 6 '09 #3
Chinde
52 New Member
I spoke to a some one I know about this, he suggested an array, which I can kind of see his point but I don't really know how to implement it, and he has not used flash before.
Mar 6 '09 #4
Markus
6,050 Recognized Expert Expert
My idea is that, you have your movieclip (with hitTest() in an event handler for it [1]) and then you duplicate that movie clip. You don't have to reference the instance name to work with it (just use this in your hitTest().

Does that make sense?

[1]
Expand|Select|Wrap|Line Numbers
  1. onClipEvent(mouseMove)
  2. {
  3.     if( this.hitTest( _root._xmouse, _root._ymouse, true ) )
  4.     {
  5.         this._visible = false;
  6.     }
  7. }
  8.  
Mar 6 '09 #5
Chinde
52 New Member
Yep, the light dawned this afternoon. I was putting the code into the character and not the object. so from my perspective I had to reference a different coin each time instead of as you suggest, get all the coins to ref the same character. A school boy error, thanks for your time it has helped me get there.
Mar 6 '09 #6
Markus
6,050 Recognized Expert Expert
@Chinde
No problem, friend. We all (in the words of JD, from Scrubs) "have a crystalizing moment when everything becomes clear." Unfortunately, we have the opposite a lot more often!

- Mark.
Mar 6 '09 #7
FollowingThefire
5 New Member
@Markus
I tried using this code to solve a similar gem problem. using the [this._visible = false;], I put it into my hero. When he hits the gem however, it removes my hero. I am using the arrow keys to move my hero instead of a mouse. My current code.

Expand|Select|Wrap|Line Numbers
  1. if (_root.levels.GemTotem.hitTest(_x, _y, true)) {
  2.          this._visible = false;
  3.     }
  4.  
GemTotem is the Gem, Levels is the symbol the gem is under. Along with the hero and exit. Any ideas?
May 13 '09 #8
Chinde
52 New Member
It sounds exactly like the problem I was having. I moved the code for the hit test from my hero and moved it onto the Coin/Gem type thing. When you use
Expand|Select|Wrap|Line Numbers
  1. this._dosomething
it is referring to the person/place where the code is so when you say
Expand|Select|Wrap|Line Numbers
  1. this._visible = false;
it would make the hero (where you put the code) invisible. Just move the code to the Gem and change all the references there and see what happens.

Another problem which I found is that just setting the visibility to false will still leave the item there so, if you are running a scoring system the hero could just stand on the spot and rack up a massive score. In the end I move the object off screen too and this solved that problem.
May 13 '09 #9
Chinde
52 New Member
In the end I move the object off screen too and this solved that problem.
Just realised I might be scolded of advising to do this for memory guzzling reasons.
May 13 '09 #10
FollowingThefire
5 New Member
@Chinde
I tried as you said, but for some reason it won't work now. I'm still going to experiment with some things, but at the moment switching it didn't help.

Changed and referenced. However, I am new to Flash. Only been learning at school for about 6 - 7 weeks now. I might be forgetting something.

Current (not working) code for my gem.

Expand|Select|Wrap|Line Numbers
  1. onClipEvent (enterFrame) {
  2.     if (_root.levels.hero.hitTest(_x, _y, true)) {
  3.          this._visible = false;
  4.     }
  5. }
  6.  
May 13 '09 #11
Chinde
52 New Member
It's been a while since I looked at any AS2 Code (Been up to my neck in VBA) so I am maybe a little rusty and I wasn't 100% even when I was doing a lot of AS2 code.

I would try

Expand|Select|Wrap|Line Numbers
  1. if (this.hitTest(_root.levels.Hero._x, _root.levels.Hero._y, true)) {
  2.          this._visible = false;
  3.     }
I guess that the only difference is that I'm being clear on whose _x and _y it should be looking at and I'm switching the hittest to the Gem
May 14 '09 #12
Markus
6,050 Recognized Expert Expert
How strange that you're originally from York. I live in York :)
May 14 '09 #13
Chinde
52 New Member
I noticed that and I wondered what the with Wolves bit was about, if you mean you live in or near Tanghall I could understand.
May 14 '09 #14
Markus
6,050 Recognized Expert Expert
@Chinde
I cannot remember whether I was calling my family wolves, or...

No not Tanghall, thank god! Strensall, on the outer area of York, near Haxby.
May 14 '09 #15
Chinde
52 New Member
It's a small world wide web.

Does the code I placed look Ok??
May 14 '09 #16
FollowingThefire
5 New Member
@Chinde
Yeah, I has a friend of mine come help me fix it. We attached the code to the hero stating.

Expand|Select|Wrap|Line Numbers
  1. if (_root.levels.GemTotem.hitTest(this._x, this._y, true)) {
  2.         _root.levels.GemTotem._visible = false;
  3.     }
  4.  
Had to add the workspace and declare this. Also had to link it to AS3.
May 14 '09 #17
Chinde
52 New Member
I might be wrong but if you intend to have many gems on one level you will have to have different code for each gem (as they should all have different instance names, otherwise if they all had the same name they would all vanish at the same time.). But I haven't done much AS3 yet so who am I to talk.
May 15 '09 #18
FollowingThefire
5 New Member
@Chinde
Nah, Just one gem per level for now. I'll get into more advanced coding like that over the summer. :]
May 15 '09 #19

Sign in to post your reply or Sign up for a free account.

Similar topics

7
4208
by: Pete Davis | last post by:
A different question this time. I have a DataGrid bound to a collection. Is there any way for me to allow sorting? The DataGrid.AllowSorting=true doesn't work, but that's probably because it can't...
12
2831
by: DannyB | last post by:
I'm just learning Python. I've created a simple coin flipper program - here is the code: #Coin flipper import random heads = 0 tails = 0 counter = 0
52
5305
by: celerysoup16 | last post by:
I've written this coin toss program, and can't figure out why it isn't giving accurate results... cheers, Ben #include <stdlib.h> #include <stdio.h> #define H 1 #define T 0 #define SENTINEL...
0
1531
by: coolindienc | last post by:
Honestly, I am totally lost about this program. I don't even know where to start. At first I thought I can ask a user to flip a coin. But then again one will get bored flipping coin fot 100 times....
14
4042
by: Shhnwz.a | last post by:
Hi, I am in confusion regarding jargons. When it is technically correct to say.. String or Character Array.in c. just give me your perspectives in this issue. Thanx in Advance.
5
3829
by: sallyk57 | last post by:
I have to make a program that would ask a user for their guess (heads or tails) and tells them if its correct or not then it has to ask the user if they want to play again. I figured out how to do...
6
6059
blackstormdragon
by: blackstormdragon | last post by:
I just started a C++ class and now we're doing loops and have to make a coin flipping program. Well here's mine: #include<iostream> #include<cstdlib> using namespace std; int flip(); void main...
8
24888
by: PAK11 | last post by:
This is what i have so far.......I need to add a function named coin to simulate a coin toss where heads is represented by a 1 and tails a 2. The outcome of the toss should be printed and the result...
0
1158
Chuncatty
by: Chuncatty | last post by:
How much does a Draped Bust coin fabricate cost? (Sorry for my Eng) I ask a beau to see if it's genuine he said it is, down repay a collage professor i met said so. It's in virtue word,...
0
7105
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6967
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7132
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6846
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7341
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4870
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3076
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1381
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
266
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.