|
From: iggy21 on 31 Oct 2006 10:15 Im looking for a way to place a cast member by clicking the mouse button. (Everytime someone clicks the stage, a new cast member (or bitmapped dots) will be created-- in the future, those dots will contain information). Ideally, I want the user to click the stage and see a dot in the exact place he clicked, then he can click the same sprite again to get rid of it. (the user should be able to click multiple areas to create multiple dots.) Any thoughts or help would be greatly appreciated. Thank you
From: duckets on 31 Oct 2006 12:16 There's a number of ways of achieving this - 3 that spring to mind are: "Sprite pool" method: Decide on a maximum number of 'dots' that can be displayed. Put that number of sprites on to the frame, but offstage. Use a counter to determine which sprite to use next and position on-stage in the correct place each time the mouse is clicked. "Dynamic Sprite" method: Use dynamic sprite creation to create sprites on the fly. This is an 'unsupported' but often used technique which can be useful. The basic technique can be seen on this page: http://director-online.com/buildArticle.php?id=1133 about halfway down, in the "on wfsCreateSprite" handler listing. Below it are a few more related handlers. "Imaging Lingo" method: Use a single stage-sized bitmap cast member to display an image containing the dots. Write your code to use 'copypixels' to draw the dots & information to this image. You can either use an alpha channel on the image, or set the ink of the sprite displaying the image to 'background transparent' so that the dots appear over whatever you want behind. hope this helps, - Ben
From: FasterPastor on 31 Oct 2006 12:28 I am a self-taught hack programmer. So, the option I have used for this may not be the elegant, "best-practice" method. I have considered how to do what you're trying to do, because I needed sprites to appear on screen for "bullets" and then do their thing, and disappear, only to reappear later when more "bullets" were needed. Someone will surely be able to tell of a better way than I used. But in case not, here is how I did it. I decided how many bullets at a time I wanted to have in action. I manually created that many bullet sprites, and positioned them all off screen (off-stage coordinates of locH = -100 and locV = -100). Then, when one of them is needed in action (player presses fire), I do the following: In a repeat loop, I cycle through each of the spriteNums of all the manually-created sprites (potential bullets), checking each one for its location -- looking for the earliest one that is still off-screen (still at off-stage coordinates of locH = -100 and locV = -100). That means that the earliest discovered bullet-sprite (i.e. one still at that location), is /not/ currently being used for a bullet. I grab that spriteNum of the unused bullet sprite.... ...And then use that to aid me in adding an entry to a list ( LBullets[ ] ) that is to keep track of each bullet's spriteNum and its "life" as a bullet. The list entry tracks which one of the manually-added sprites is being used for the given bullet, as well as tracking that bullet's location, speed, direction, and lifespan. At each exitFrame event, I update that list, and move each bullet sprite accordingly. When a bullet either hits a target or outlives its lifespan, the update process involves deleting that bullet's entry in the list ( LBullets[ ] ) and moving the sprite that was being used for it.... back to the off-screen coordinates, so it can become a candidate for reuse. It is working fine for me. Probably not the best way, but it works.
From: FasterPastor on 31 Oct 2006 12:59 Wow, Ben. You are a pro in my book, and this means that the method I used "made it" into your list of options. I feel pleased to find that out. :)
|
Pages: 1 Prev: how to use in Lingo XML-RPC file Next: Annoying - Sounds Repeat! |