-=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- (c) WidthPadding Industries 1987 0|579|0 -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=-
SoCoder -> Article Home -> Coding Basics


 
Jayenkai
Created : 10 May 2009
Edited : 10 May 2009
Language : D

MidletPascal : Cookie : Loading Images

Made for my cookie : It's good enough for me.

Note : These tutorials have been created for an "LG Cookie" centric forum, and as such are targetted at that phone.
They're also aimed at folk who may/may not be all that good at coding.
Only time will tell if folk are able to follow!!




So, you've finally (!) got MidletPascal up and running.
What's next?

Let's kick things off with some images.

Saving your image
This is step one!
Because I know a lot of you won't be set up as developers, you won't have half the stuff, onhand, that I do.
Your first step is getting a decent image editor.
I use an old copy of PaintShop Pro 7, from some time around 2000/2001. Yikes!
You might want to use something half-modern!

I've been told that GIMP is pretty decent, but I've never really tried.. I've stuck to my guns, and held onto my PSP7 for dear life! I'm comfortable with it!!

Whatever you have, create an image about 32x32 pixels.
Doodle something, and get ready to save.

When you save, this bit's important, save as a .png file.
This has three GOOD points.
1. The Cookie likes it!
2. The filesize is small.
3. The image format doesn't leave nasty bits, like jpg does.

Additionally, you can use transparency with .png files, to allow for "Non-Square" shapes.
ie, If you make a bullet, you can set the background of the bullet as transparent, so you don't end up with a black square, and a tiny bullet, flying through your screen!!

If you root around in your options, you might be able to find a way to save your image with "Alpha Transparency"

There's also an option to save with "Color Transparency", but DON'T DO THAT.. Color transparency does NOT work with Cookie!
(works on the emulator, but NOT on the hardware.)
But alpha transparency works fine.

So, with your image saved, let's load the sucker in!!


Loading the sucker in
New Project
Hit the big green + in the middle of the toolbar, and Import Resource File
Find your saved image.
This'll add the image into the "Resource File(s)" list on the left of the window.

For most of the tutorials, we'll use the following base code.



Copy and paste the basecode into your new project, ready for use..

Next, set up a variable to store the image.

var MyPicture:Image;
^ That bit goes into your Variables section.

In the "Load Bits" section, you need to load the image from the resources, into memory.
So, we use.
MyPicture:=LoadImage('/Image.png');

And within the main game loop, shove the simple drawing lines.
if mdown=1 then
begin
DrawImage(MyPicture,mx,my); // Draws the image where the Pen Touched
DrawImage(MyPicture,m2x,m2y); // Draws the image where the Pen "Currently" is.
end;

Which will only draw the picture at the stylus's co-ordinates, while the stylus is touching the screen.
Since CLS is now inside the main loop, the image will appear to move to the co-ordinates.
What's actually happening, is we're just clearing, and redrawing everything each time...

To put it another way, we're not "Moving" things, to make the animation.
In some languages, you'd give each sprite a set of co-ords, and then move them around.
We're not doing that..
We're, instead, redrawing everything from scratch.


Now, back to the code.
If you compile and run that in the emulator, you'll get two sprites on the screen.
One is where you clicked, and other is under the mouse.
Move the mouse, and you'll see the other sprite follow it.

This looks interesting, and is infact very very very very very very useful.
But here's the clincher.
That ain't working on the Cookie.

Get it on your cookie!

Head into your project's folder (probably c:\program files\midletpascal\projects\ThisProject\)
there should be a bin folder.
Pop in there, and you'll find your .jad and .jar file.
Cookie don't need no .jad, so you can happily ignore it.
The .jar file is the important one.
Grab your MicroSD card, shove the .jar file into the "Others" folder on the card, pop it into the cookie, find it, run it..
You know what you're doing!

Here's where we find "Cookie Cripple #1"
Run the thing on the cookie, and try to move the stylus around like you did before.
This time, you'll find that the second sprite tends to hop around.
It LOOKS like it's a really bad framerate issue, but in fact it isn't.
If you move it slowly, you get the same jumping space each time.
The jump space seems to be about 16-24 pixels in size.
Essentially, the cookie is only giving us "new co-ords", if the stylus has been moved a certain range from where it was.
This causes all manner of issues.
It "could" still be used, but you'd have to really be sure of what you're doing with it.

Basically, you can't do the following.
#1 Art of any sort. Since the pen won't follow the stylus. It's just jump around, as if you don't know how to code "Draw a line"
#2 Drag 'n' Drop. unless you want to drag things to an unspecified 20-odd pixels away.
#3 Block Swap. unless the blocks are really big, thus making your # of bricks really small.
and so on, and so forth.

One single disability, and you're REALLY amazingly limited.

Them's the breaks.


Have a play around with what you have, learn the ropes, and when you're ready we can carry on by making a whole new game!
Woot!

Something to try yourself.
Set up a couple of co-ordinate variables.
Set them to the pointer's co-ordinates, but as soon as you let go, let the Y co-ordinate move down the screen.
This'll give you the illusion of "Dropping" the object, when you let go.

Next up
Next tutorial, Tic-Tac-Toe, probably tomorrow, too tired to do it now!

 

Comments