Reputation: 1
I'm attempting to create a top-down TRON light-cycle style game in Flash CS5, working in AS3. I've been looking into having a player-controlled sprite (a UIComponent) leave a trail as it moves across the screen, avoiding other lines and trying to get to the "exit". The player-controlled sprite will be controlled by the keyboard.
I've looked at "snake" games to try to sort out the best way to do this, but I'm not sure that it's the best base to start from.
Does anyone have a source for an AS3 tutorial for something like this, or an idea of how the actionscript would work?
I appreciate any suggestions and/or tips! Let me know if this needs some clarification.
Upvotes: 0
Views: 534
Reputation: 66622
The last time I wrote a game of this sort was in 1985 on a BBC micro. Just draw the trail separately. Keep a record of the last X/Y coordinate and draw the trail as a line of appropriate thickness to the new coordinates, then render the sprite on top.
If moving the sprite will erase the picture underneath it, then you may need to draw the lines on a separate context and render them together for each frame. You might need double buffering to make this work without flickering.
(For the astute, the latter would of course never have worked on a BBC Micro due to limited CPU speed and memory, but it should work on any modern system).
Upvotes: 1
Reputation: 2678
Well, there is no generic solution here, it all depends on how your game is designed. If you've some sort of matrix or tilemap, though, it shouldn't be too difficult. I could see two solutions :
1°) If you have a matrix with very small sprites, just color the areas the sprite went through with a color. You'd want to have a bidimensional array, and actualize it as soon the sprite leave the tile.
2°) If you have a matrix with large sprites, and the trail should be smaller than the sprites, then you need to draw a serie of picture showing the trail going in all possible direction. Then, when the sprite is leaving a tile, you need to compute the direction, and put the right trail image on the tile it just left.
Upvotes: 0