×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    Mar 2003
    Location
    United Kingdom
    Posts
    49

    Scrolling an image and fast screen access

    Hi,

    I am experimenting with a few things at the moment:

    a. Implementing texture mapping
    b. Scrolling an image

    but finding it difficult to find relevant info. Could anyone offer any advice on how to:

    1. Fastest screen access in MIDP 1.0 with and without Nokia extensions. For MIDP 1.0, I had thought of defining textures as a series of vertical lines and then scaling them onto walls using drawLine() , but surely there is a better method?
    2. I am basically wanting to copy the pixels in an image a few pixels to the left or right, then fill in the empty space with new tiles. I want to try and make the scroller work on phones with small heaps though, so I need to use as little heap space as possible.

    Thanks for any help

    Mat
    Last edited by mrmop; 2003-12-31 at 11:26.

  2. #2
    Registered User
    Join Date
    Mar 2003
    Location
    United Kingdom
    Posts
    49

    Getting somewhere

    I appear to be getting somewhere with scrolling.

    Graphics g2 = offScreenBuffer.getGraphics();
    g2.drawImage(offScreenBuffer, -1, 0, Graphics.LEFT | Graphics.TOP);

    This will scroll the image smoothly to the left. The same can be done with upwards by replacing x with 0 and y with -1. However a major problem arises when attempting to scroll to the right or downwards. Basically, the screen just turns white. I believe that the implementation of drawImage() does not take into account that one may be drawing part of an image back onto the same image, thus the data in the image has already been written over before it is copied. Fine for games that only ever scroll left or upwards

    A solution would be to copy single pixel wide portions of the image starting from the right and moving to the left when scrolling right, but I can imagine this being very slow. I suppose that if I have a constant scroll step of say 8 pixels then it wont be too bad.

    Does anyone have any better ideas?
    Last edited by mrmop; 2003-12-31 at 14:49.

  3. #3
    Registered User
    Join Date
    Mar 2003
    Location
    United Kingdom
    Posts
    49
    Got the left and right scroller working with MIDP 1.0, so I thought that I would post the code for others:

    Code:
    	public final	static int	COLUMN_WIDTH	= 8;
    	private int	num_columns	= (width + (COLUMN_WIDTH - 1)) * COLUMN_WIDTH;
    
    	public void GAME_ProcessScroller()
    	{
    		Graphics	g2 = offScreenBuffer.getGraphics();
    		int	t, sx, sy = 0, dx, dy = 0;
    		
    		if (nXScroll != 0)
    		{
    			int	step_x;
    			
    			if (nXScroll > 0)	// Scroll right
    			{
    				sx = num_columns * COLUMN_WIDTH;
    				dx = COLUMN_WIDTH;
    				step_x = -COLUMN_WIDTH;
    				
    			}
    			else		// Scroll left
    			{
    				sx = 0;
    				dx = -COLUMN_WIDTH;
    				step_x = COLUMN_WIDTH;
    			}
    			
    			for (t = 0; t < num_columns; t++)
    			{
    				g2.setClip(sx, sy, COLUMN_WIDTH, height);
    				g2.drawImage(offScreenBuffer, dx, dy, Graphics.LEFT | Graphics.TOP);
    				sx += step_x;
    			}
    		}
    	}
    Note that this only scrolls an image left / right, to turn this into a full scroller you will need to draw columns of new tiles to fill in the space. If anyone can do this quicker then please let me know.
    Last edited by mrmop; 2003-12-31 at 17:14.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×