Click here to Skip to main content
15,885,757 members
Home / Discussions / C#
   

C#

 
AnswerRe: Looking for low-level C# Projects Examples Pin
Richard MacCutchan16-Sep-12 5:58
mveRichard MacCutchan16-Sep-12 5:58 
GeneralRe: Looking for low-level C# Projects Examples Pin
atoi_powered16-Sep-12 10:56
atoi_powered16-Sep-12 10:56 
GeneralRe: Looking for low-level C# Projects Examples Pin
Richard MacCutchan16-Sep-12 21:01
mveRichard MacCutchan16-Sep-12 21:01 
QuestionData compression Pin
Mubi, Nigeria16-Sep-12 2:04
Mubi, Nigeria16-Sep-12 2:04 
AnswerRe: Data compression Pin
Pete O'Hanlon16-Sep-12 2:07
mvePete O'Hanlon16-Sep-12 2:07 
GeneralRe: Data compression Pin
harold aptroot16-Sep-12 2:08
harold aptroot16-Sep-12 2:08 
AnswerRe: Data compression Pin
cmk16-Sep-12 8:37
cmk16-Sep-12 8:37 
QuestionXNA Sprite Frame Inconsistency Pin
Sasstraliss15-Sep-12 19:46
Sasstraliss15-Sep-12 19:46 
I have an explosion sprite, with 16 frames.


Everytime the player collides with an asteroid, the gamestate is set to loseScreen, and when the loseScreen is the gamestate, the lose() function is continually called until the gamestate changes.

Inside the lose() function, this code draws the animated spritesheet, which runs through the 16 frame animation. It should always start from frame 0, but it doesn't always. Sometimes it starts at frame 10, and only runs for 6 frames before finishing. That's the issue. The code inside the lose() function to draw the explosion animation is as follows:


C#
expFrameID = 0;
expFrameID += (int)(time * expFPS) % expFrameCount;
Rectangle expRect = new Rectangle(expFrameID * expFrameWidth, 0, 63, 63);
spriteBatch.Draw(explosion, shipLocation, expRect, Color.White, 0f, new Vector2(32, 32), 1.0f, pickupSpriteEffects, 0.1f);
if (expFrameID == 15)
    expIsDrawn = true;



The time variable is as follows, it gets the total elapsed game time.

C#
time = (float)gameTime.TotalGameTime.TotalSeconds;


I've tried changing TotalGameTime to ElapsedGameTime, nothing changed.
It's the following line from the lose() function that I believe is the issue, perhaps:

C#
expFrameID += (int)(time * expFPS) % expFrameCount;


It works, and it animates. However it doesn't always start at frame 0. it starts from random frames between 0 and 16, but it still runs correctly at 16 frames per second.

So, how do I get it to always start from frame 0?


Would I solve my issue by making a new time variable that starts a timer from 0 only when the lose() function is called? How do I do that?
QuestionC# working with xml Pin
rachel_m14-Sep-12 20:49
rachel_m14-Sep-12 20:49 
AnswerRe: C# working with xml Pin
Abhinav S14-Sep-12 21:34
Abhinav S14-Sep-12 21:34 
AnswerRe: C# working with xml Pin
PIEBALDconsult15-Sep-12 3:30
mvePIEBALDconsult15-Sep-12 3:30 
QuestionC# using stored procedure Pin
rachel_m14-Sep-12 20:46
rachel_m14-Sep-12 20:46 
AnswerRe: C# using stored procedure Pin
Wayne Gaylard14-Sep-12 21:20
professionalWayne Gaylard14-Sep-12 21:20 
AnswerRe: C# using stored procedure Pin
prashant patil 498714-Sep-12 22:31
prashant patil 498714-Sep-12 22:31 
QuestionDetection of an installed program Pin
Fred 3414-Sep-12 5:30
Fred 3414-Sep-12 5:30 
AnswerRe: Detection of an installed program Pin
Richard MacCutchan14-Sep-12 5:34
mveRichard MacCutchan14-Sep-12 5:34 
GeneralRe: Detection of an installed program Pin
Shameel14-Sep-12 5:46
professionalShameel14-Sep-12 5:46 
GeneralRe: Detection of an installed program Pin
Richard MacCutchan14-Sep-12 6:10
mveRichard MacCutchan14-Sep-12 6:10 
GeneralRe: Detection of an installed program Pin
Shameel14-Sep-12 9:01
professionalShameel14-Sep-12 9:01 
GeneralRe: Detection of an installed program Pin
Richard MacCutchan14-Sep-12 9:29
mveRichard MacCutchan14-Sep-12 9:29 
GeneralRe: Detection of an installed program Pin
Fred 3414-Sep-12 8:19
Fred 3414-Sep-12 8:19 
GeneralRe: Detection of an installed program Pin
Richard MacCutchan14-Sep-12 9:26
mveRichard MacCutchan14-Sep-12 9:26 
AnswerRe: Detection of an installed program Pin
OriginalGriff14-Sep-12 6:24
mveOriginalGriff14-Sep-12 6:24 
AnswerRe: Detection of an installed program Pin
Abhinav S14-Sep-12 8:17
Abhinav S14-Sep-12 8:17 
GeneralRe: Detection of an installed program Pin
Fred 3414-Sep-12 8:29
Fred 3414-Sep-12 8:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.