简体   繁体   中英

XNA C# How do I make my model blinking?

I'm quite new in XNA C# and I would like to know how do I create a model in XNA C# that will blink every second. I'm trying to make an invulnerability effect for my model.

Currently, my own idea is that I will set the visible of my model to false and true every second.

Thanks.

EDIT: I cannot find any model.visible = false in XNA C#??

Your idea is fine, but you'll need to track whether it should be visible or not yourself, and only draw it when it's visible . Every object gets explicitly redrawn by your code every frame; so simply don't draw it when it shouldn't be visible.

There is no built-in way to do this (that I know of); it wouldn't make much sense if there were, since you'd be calling a drawing function on invisible objects. Not drawing invisible objects in the first place makes more sense.

To get the blinking to work, you'll need to track how much time has elapsed since the last time the visibility was flipped, and toggle the visibility when that time exceeds one second. For example, in your Update() method, you'd have something like this:

if (gameTime.TotalGameTime.TotalMilliseconds >= nextBlinkTime) {
    modelVisibility = !modelVisibility;

    nextBlinkTime = gameTime.TotalGameTime.TotalMilliseconds + 1000;
}

For more complex scenarios (eg multiple models need visibility toggled, etc.), I suggest you abstract this behaviour away into a reusable class.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM