Visa signatur
Intel Core i7-4710HQ || 16GB DDR3 || 256GB SSD || 1TB HDD || GeForce GTX980M 8GB
Tjenare, håller på med ett litet spel för skolan och får då detta error I klassen för mina små asteroider, koden ser ut som följande
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
namespace Asteroider
{
class asteroid
{
public Vector2 position;
public Vector2 direction;
public int speed;
public Texture2D texture;
public int height;
public int width;
public bool isVisible = true;
private Vector2 pos;
private Vector2 dir;
private int speed_2;
private asteroid asteroid_2;
public asteroid(Vector2 position, Vector2 direction, int speed, Texture2D texture)
{
this.position = position;
this.direction = direction;
this.speed = speed;
this.texture = texture;
height = texture.Height;
width = texture.Width;
}
public asteroid(Vector2 pos, Vector2 dir, int speed_2, asteroid asteroid_2)
{
// TODO: Complete member initialization
this.pos = pos;
this.dir = dir;
this.speed_2 = speed_2;
this.asteroid_2 = asteroid_2;
}
public void Update()
{
position.X = position.X + speed * direction.X;
position.Y = position.Y + speed * direction.Y;
}
public void Draw( SpriteBatch spriteBatch )
{
SpriteEffects spriteEffects = SpriteEffects.None;
if (isVisible == true)
{
spriteBatch.Draw(texture, position, new Rectangle(1, 1, width, height), Color.White, 0, Vector2.Zero, 1, spriteEffects, 1);
}
}
}
}
Hur löser jag detta, har försökt över en timme snart?
Tack på förhand
Edit: Stavfel
Intel Core i7-4710HQ || 16GB DDR3 || 256GB SSD || 1TB HDD || GeForce GTX980M 8GB
Använder du båda konstruktorerna? Endast den övre sätter ju texture till något.
Använder du båda konstruktorerna? Endast den övre sätter ju texture till något.
Hittade felet på problemet, trodde jag hade tilldelat dem texturerna i main klassen, men hade satt object namnet istället, vilket jag dumt nog döpt väldigt snarlika, tack så mycket i alla fall
Intel Core i7-4710HQ || 16GB DDR3 || 256GB SSD || 1TB HDD || GeForce GTX980M 8GB
Copyright © 1999–2024 Geeks AB. Allt innehåll tillhör Geeks AB.
Citering är tillåten om källan anges.