so Here's a piece of void draw code that I can't figure out. Please explain to me what I'm doing wrong.
void draw() {
loadPixels();
int x,y,offs,u,v;
offs=0;
for (y=0;y<988;y++) {
for (x=0;x<554;x++) {
u=(utab[x][y]+voffs)&255;
v=(vtab[x][y]+uoffs)&255;
pixels[offs++]=tex.pixels[(u<<8)+v];
}
}
updatePixels();
uoffs++;
voffs++;
}
I don't get how to make the '&255' value for 'u' and 'v' random. Could somebody please explain? Cause u=(utab[x][y]+voffs)&random(0,255) or something won't work.
You can try something like this:
u=(utab[random(554)][random(988)]+voffs)&255;
which should probably safe, although we could help you a lot more if you posted some more code...
Related
I have a particle system explosion that I want to play when the player dies. The idea that is that everything else pauses but the explosion continues, like the Pacman animation when you die (everything freezes and the pacman death animation plays).
Trouble is, it won't work. I know Time.timeScale = 0 pauses everything, and I've tried using this script to combat that, but it doesn't seem to be working:
void Update()
{
if (Time.timeScale < 0.01f)
{
particleSystem.Simulate(Time.deltaTime, true, false);
}
}
I have also tried this, but it doesn't work either:
private ParticleSystem pSystem;
public void Awake()
{
pSystem = gameObject.GetComponent<ParticleSystem>();
}
public void Play()
{
pSystem.Simulate(Time.unscaledDeltaTime,true,true);
}
public void Update()
{
pSystem.Simulate(Time.unscaledDeltaTime,true,false);
}
I have tried this code with a script that is attached to my explosion particle system prefab, which is instantiated at the player's position when you die.
Thanks!
UPDATE:
Turns out I had tried using particleSystem.Simulate(Time.unscaledDeltaTime, true, false);, but I was calling it in FixedUpdate() rather than Update().
However, the Asteroid Base post below posted by Garfty is really interesting and is probably worth doing in the long run!
One way you could do it is by using Time.unscaledDeltaTime
Another way you could approach something like this is by creating your own time manager, but it requires some discipline to stick to. The people at Asteroid Base wrote a nice article on something like this here.
I hope this helps!
I am trying to display ads from pubcetner in XNA game for WP. I am using DrawableAd class as it is written here:
http://msdn.microsoft.com/en-us/library/advertising-mobile-windows-phone-xna-silverlight-hybrid-walkthrough-ads%28v=msads.20%29.aspx
But I can't see any ads rendering. Is it works? Or is there any other way to display ads? I wanted to try Adrotator, but I can't
get NuGet Package for this
Ok, I had a lot of problems with this in my game.
Without seeing your code, it's hard to actually diagnose, so without posting that from your Game.cs (assuming it's in Game.cs), you will need to make sure to test the following things.
//Global variable area
DrawableAd bannerAd;
string applicationID = "test_client"; //Or insert your actual ID. I recommend you first do with test client
//ie. 1234567-d123-1234-a12b-1a23b4567890
string adUnitID = "Image480_80"; //Or the actual unit ID. ie. 123456
//Initialization
protected override void Initialize(){
AdGameComponent.Initialize(this, applicationId);
AdGameComponent.Current.CountryOrRegion = System.Globalization.RegionInfo.CurrentRegion.TwoLetterISORegionName;
bannerAd = AdGameComponent.Current.CreateAd(adUnitId, new Rectangle(0,400, 480, 80), true);
AdGameComponent.Current.Enabled = true;
AdGameComponent.Current.Visible = true;
base.Initialize();
}
The part that got me by surprise was that I got rid of my base.Update(...) and base.Draw(...) calls and it actually prevented anything from ever being updated or called with the Ad. I also remember through my endeavor that the region was apparently important in some cases. Can't find the source for that. You might be able to get rid of it.
protected override void Update(GameTime gameTime)
{
//Your code here...
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
//Your code here...
base.Draw(gameTime);
}
Hope that helps! Good luck. I know I had a pretty nasty time figuring out why mine didn't work. Make sure your render order is correct to. I'm not sure, but perhaps you might be drawing everything ON the ad. I haven't looked into whether you could actually do that or if the depth field of the ad was always on top. I just leave my base.Draw(gameTime) at the bottom of everything else.
so I'm developing a game for android in LibGDX and I've stumbled upon a problem: I have a scene with an image in it and I want to be able to click/touch the image and make stuff happen after doing so.
I've been trying to google a solution for the past day but I keep on missing something vital. Here's my code:
public class ScreenSplash implements Screen {
private Texture textureGlobe = new Texture(Gdx.files.internal("graphics/splash.png"));
private Image imageGlobe = new Image((new TextureRegion(textureGlobe)));
public ScreenSplash() {
imageGlobe.addListener(new InputListener() {
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
Gdx.app.log(Game.LOG, "image clicked");
return true;
}
});
stageGame.addActor(imageGlobe);
}
...
}
I've also heard that I'm supposed to put this somewhere:
Gdx.input.setInputProcessor(inputProcessor);
But I don't really know what to do with it.
Your Stage is your InputProcessor so do something like Gdx.input.setInputProcessor(stageGame);. The Stage will route the events to the actors.
Ah, I've found out what the problem was.
I imported java.awt.event.InputEvent instead of com.badlogic.gdx.scenes.scene2d.InputEvent and the touchDown function wasn't properly overriden because of this.
I see a lot of legacy .Net 1.1-style code at work like in example below, which I would like to shrink with the help of an auto-property. This will help many classes shrink by 30-40%, which I think would be good.
public int MyIntThingy
{
get
{
return _myIntThingy;
}
set
{
_myIntThingy = value;
}
} private int _myIntThingy = -1;
This would become:
public int MyIntThingy
{
get;
set;
}
And the only question is - where do I set MyIntThingy = -1;?
If I wrote the class from the start, then I would have a better idea, but I did not. An obvious answer would be: put it in the constructor. Trouble is: there are many constructors in this class. Watching the initialization to -1 in the debugger, I see it happen (I believe) before the constructor gets called. It is almost as if I need to use a static constructor as described here:
http://www.c-sharpcorner.com/uploadfile/cupadhyay/staticconstructors11092005061428am/staticconstructors.aspx
except that my variables are not static. Java's static initializer comes to mind, but again - my variables are not static. http://www.glenmccl.com/tip_003.htm
I want to make stylistic but not functional changes to this class. As crappy as it is, it has been tested and working for a few years now. breaking the functionality would be bad. So ... I am looking for shorter, sweeter, cuter, and yet EQUIVALENT code. Let me know if you have questions.
I'm afraid that you have no option.
If you want to use an auto-property with an initial value that differs from the type's default value then you'll need to set the initial value in the constructor(s).
If you just need a stylistic, non-breaking change, consider changing the format a little:
public int MyIntThingy
{
get { return _myIntThingy; }
set { _myIntThingy = value; }
}
private int _myIntThingy = -1;
Isn't that prettier?
And consider using auto-properties for future code only. It sounds too risky to use them on existing code, unless there are no default values.
Which of these 2 programming styles do you prefer? Why? Are there particular advantages to one over the other?
// Style 1
if (doBorder)
doTheBorder();
if (doFrame)
doTheFrame();
if (doDraw)
doTheDraw();
void doTheBorder()
{
// ...
}
void doTheFrame()
{
// ...
}
void doTheDraw()
{
// ...
}
// Style 2
doTheBorder();
doTheFrame();
doTheDraw();
void doTheBorder()
{
if (!doBorder)
return;
// ...
}
void doTheFrame()
{
if (!doFrame)
return;
// ...
}
void doTheDraw()
{
if (!doDraw)
return;
// ...
}
The first. The second seems to be... lacking in confidence. Why call doTheBorder() if you don't even know if you want the border to be done? IMO, you should assert that the border really needs doing, and then call doTheBorder() with confidence!
...Also, from a more technical point of view: if doTheBorder() is in a closed API, a developer in the distant future might call it and if the second style is employed, they may wonder why the border didn't get done, despite their call to doTheBorder(). Of course, sometimes certain circumstances or restrictions or limitations may dictate that the second style be used, but I'd avoid it when possible.