TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Hector Rosario
NA
4
0
Having a little trouble with bitmaps...
Mar 2 2009 10:33 PM
Ok, here goes... I got my little rpg man walking around in a grass maze and everything. That's cool and all except for the fact that my little guy has a white border all around him from the original JPG. Any tips on how to get rid of that white border so I can just see the green grass tile under him the way it's supposed to be?
Here is the part of the program that concerns the Hero sprite.
Can someone please give me advice on what I should do?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Drawing.Imaging;
namespace WindowsFormsApplication6
{
public class Hero
{
public Point Position;
static Bitmap HeroImage = null;
static Bitmap HeroImage2 = null;
int inc = 3;
int LastPositionX = 0;
int LastPositionY = 0;
public Hero()
{
Position.X = 30;
Position.Y = 35;
if (HeroImage == null)
{
HeroImage = new Bitmap("Hero.jpg");
}
if (HeroImage2 == null)
{
HeroImage2 = new Bitmap("Hero2.jpg");
}
}
public Hero(int x, int y)
{
Position.X = x;
Position.Y = y;
if (HeroImage == null)
{
HeroImage = new Bitmap("Hero.jpg");
}
if (HeroImage2 == null)
{
HeroImage2 = new Bitmap("Hero2.jpg");
}
}
public Rectangle GetFrame()
{
Rectangle myRect = new Rectangle(Position.X, Position.Y, HeroImage.Width, HeroImage.Height);
return myRect;
}
public void Draw(Graphics g)
{
Rectangle destR = new Rectangle(Position.X, Position.Y, HeroImage.Width, HeroImage.Height);
Rectangle srcR = new Rectangle(0, 0, HeroImage.Width, HeroImage.Height);
// make it look like the legs are moving
if (((Position.X % 2 == 1) && ((Position.X - LastPositionX) != 0)) ||
((Position.Y % 2 == 1) && ((Position.Y - LastPositionY) != 0))
)
g.DrawImage(HeroImage, destR, srcR, GraphicsUnit.Pixel);
else
g.DrawImage(HeroImage2, destR, srcR, GraphicsUnit.Pixel);
LastPositionX = Position.X;
LastPositionY = Position.Y;
}
public void MoveLeft(Rectangle r)
{
if (Position.X <= 0)
return; // precondition
Position.X -= inc;
}
public void MoveRight(Rectangle r)
{
if (Position.X >= r.Width - HeroImage.Width)
return; // precondition
Position.X += inc;
}
public void MoveUp(Rectangle r)
{
if (Position.Y <= 0)
return; // precondition
Position.Y -= inc;
}
public void MoveDown(Rectangle r)
{
if (Position.Y >= r.Height - HeroImage.Height)
return; // precondition
Position.Y += inc;
}
}
}
Reply
Answers (
3
)
Memory Leak -- Array of Objects
Getting database records into an array