MIDP1.0-based mimic Sprite class

xiaoxiao2021-03-06  45

I feel that the Sprite class in MIDP2 is very easy to use, and the current development of mobile phone programs or MIDP1 is mainstream, so doing this class, it is still more convenient, huh, huh, please pay attention to this site's latest version ----- ---------------------- Package theman; / ** *

Title: * *

description: * *

Copyright: Copyright (C) 2004

Company: * * @Author NOT Attributable * @version 1.0 * / import javax.microedition.lcdui. *; public class mysprite { private Image image; private int positionX; private int positionY; private int frameWidth; private int frameHeight; private int numFrames; private int currentFrame; public boolean visible = true; public int DX; public int DY; public int collideX = 0; // When two roles cross lateral distances exceeding collidex, it is considered that it has collided public int collidey = 0; // When two roles cross longitudinal distance exceed Collidey, it is considered that it has collided public int collideareA = 0; // When two roles are more intrusion area exceeded It has been considered collideArea collision (Note:! herein invasion area = area of ​​the cross) public MySprite (Image image, int frameWidth, int frameHeight, int numFrames) throws Exception {this.image = image; this.frameWidth = frameWidth; this.frameHeight = frameheight; this.numframes = Numframes; this.currentframe = 0; publicin T getX () {return this.positionX;} public void setx (int positionX) {this.positionX = positionX;} public int game () {return this.positiony;} public int getframewidth () {Return this.framewidth;} Public int getframeheight () {return this.frameheight;} public void sety {this.positiony = positiony;

} Public void setCurrentFrame (int current) {this.currentFrame = current;} public void draw (Graphics g, MainCanvas theCanvas) {if (visible) {g.clipRect (getX (), getY (), frameWidth, frameHeight); g .drawimage (image, getX () - currentframe * framewidth, gety (), g.top | g.left); g.setClip (0, 0, THECANVAS.GETWIDTH (), Thecanvas.getHeight ());}} public void step () {this.positionX = DX; this.positionY = DY;} public boolean collidesWith (MySprite sprite) {return this.collidesWith (sprite, false);} public boolean collidesWith (MySprite sprite, boolean CheckType) {if ( ! Visible ||! sprite.visible) {Return False;} If (checkty) {// When the two roles are more introcational, they think that they have collisted (note: the invasive area here! = intersection area) INT Inx = Sprite .GETX () sprite.framewidth-this.getx ()> this.getx () this.fraMewidth-sprite.getx ()? this.getx () this.framewidth-sprite.getx (): sprite.getx () sprite.frameWidth-this.getx (); int iny = sprite.gety () sprite.frameHeight-this.gety ()> this.gety () this.frameHeight-sprite.gety ()? this. Get () this.frameHeight-sprite.gety (): sprite.gety () sprite.frameHeight-this.gety (); if (Inx> 0 && Iny> 0 && Inx * iny> this.collidearea sprite. Collidearea) {Return True;} else {return false;}} else {if (sprite.getx () sprite.framewidth-sprite.collidex> this.Getx () &

& this.FrameWidth-this.collidex> sprite.getx () && sprite.getx () && sprite.Gety () sprite.frameHeight-sprite.collidey> this.gety () && this.gety () this.frameHeight -this.collidey> sprite.gety ()) {Return true;}}}} public boolean collideswith (Image Image, Int x, int y) {Return this.collideswith (Image, x, y, false } public Boolean Collideswith (Image Image, Int X, Int Y, Boolean CheckType) {if (! Visible) {Return False;} If (checktype) {// When the two roles are more accused, they think that they have collided when Collidearea (Note: Intrusion area here! = Cross-area) int Inx = x image.GetWidth () - this.getx ()> this.getx () this.framewidth-x? This.getx () this.framewidth -x: x image.getwidth () - this.getx (); int iny = y image.getHEight () - this.gety ()> this.gety () this.frameHeight-y? this.gety ( ) this.frameHeight-Y: Y i Mage.getHeight () - this.gety (); if (Inx> 0 && iny> 0 && Inx * iny> this.collidearea) {Return true;}} else {ix (x image.) getWidth ()> this.getx () && this.getx () this.framewidth-this.collidex> x && y image.getHEight ()> this.gety () && this.gety () this.frameHeight- {Return True;} else {return false;

}}}} ----------------------------------------- Why is it ? One sand gull in the world.

转载请注明原文地址:https://www.9cbs.com/read-75021.html

New Post(0)