You Are Here:

Community: Developer Discussion Boards

#1 Old different layers - 2003-03-21, 14:34

Join Date: Mar 2003
Posts: 37
nodevelop
Offline
Registered User
hi
some question to you:
1) I want to display a background graphics and a sprite image over it using MIDP 1.0. which method have I to use?
2) I lernt how to animate the sprite image. it simple can be moved over the screen, but how can I put a limit to the sprite position so it can't go in a nondisplayable area?
I tried to use getWidth and getHight with bad resoult.
is there a standard procedure to do that?
3) in gaming is very important the joypad.I used getKeyCode() to know if a key is pressed (left,fire,up etc...).but there is a frustrating limitation in that: I need 2 instance from a key:when it is pressed(and still pressed "ON"), and when it become not pressed"OFF".
somenthing like the midi message: when I press a key on the keyboard the generated midi message will be :note on,note off.
why I need this? if a player want to move the sprite to the left he press the left button on the device, that move the sprite one unit to the left. but if the player keep the left button pressed the sprite move again one unit to the left instead of more unit to the left basing on the pressing time.am I wrong?


(sorry for my english)hope someone can help me.
eml
Reply With Quote

#2 Old 2003-03-21, 15:40

Join Date: Mar 2003
Posts: 2,280
Location: Israel
shmoove
Offline
Forum Nokia Champion
1. You can use a simple drawImage, just make sure your sprite is a png with transparent background. Also you will have to clear the area the sprite is leaving (repaint the background on it), again using drawImage and also setClip. These are all methods of the Graphics class of course.
2. Are you making sure to subtract the size of the sprite. If a sprite can't leave the screen then it's top left coordinate should be smaller than (getWidth - sprite.width) and (getHeight - sprite.height).
3. There are exactly the methods you need. They are called keyPressed and keyReleased (in the Canvas class). Set up a boolean flag on keyPressed and reset it on keyReleased:
Code:
private boolean goingLeft;

protected void keyPressed(int keyCode) {
    if (getGameAction(keyCode) == Canvas.LEFT) 
        goingLeft = true;
}

protected void keyReleased(int keyCode) {
    if (getGameAction(keyCode) == Canvas.LEFT) 
        goingLeft = false;
}

// and use some timed method where you check the flag and
// move the sprite according:
private void someTimedMethod() {
    if (goingLeft)
        sprite.left--;
}
Reply With Quote

#3 Old 2003-03-21, 16:03

Join Date: Mar 2003
Posts: 37
nodevelop
Offline
Registered User
thanks shmoove
your answer is really usefull
eml
Reply With Quote
Reply « Previous Thread | Next Thread »
Display Modes
Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules

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

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Forum Jump

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia 
RDF Facets: qdcZidentifierQSxhttpE3aE2fE2fdiscussionE2eforumE2enokiaE2ecomhttpE3aE2fE2fdiscussionE2eforumE2enokiaE2ecomE2fforumE2fshowthreadE2ephpE3ftE3d18645X qdcZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qdcZtypeQUqfntypeZCommunityContentQ qdcZtypeQUqfntypeZE44iscussionQ qdcZtypeQUqfntypeZE44iscussionContentQ qdcZtypeQUqfntypeZE52esourceQ qdcZtypeQUqfntypeZWebpageQ qdcZtypeQUqmarsZManagedE52esourceQ qdcZtypeQUqwebZInformationE52esourceQ qdcZtypeQUqwebZPageQ qdcZtypeQUqwebZE52esourceQ qdcZtypeQUqrdfsZE52esourceQ qfnZtopicQUqfnTopicZentertainmentQ qfnZtopicQUqfnTopicZj2meQ qfnZtopicQUqfnTopicZjavaQ qfnZtopicQUqfnTopicZmediaQ qfnZtypeQUqfntypeZCommunityContentQ qfnZtypeQUqfntypeZE44iscussionQ qfnZtypeQUqfntypeZE44iscussionContentQ qfnZtypeQUqfntypeZE52esourceQ qfnZtypeQUqfntypeZWebpageQ qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX qrdfZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qrdfZtypeQUqfntypeZCommunityContentQ qrdfZtypeQUqfntypeZE44iscussionQ qrdfZtypeQUqfntypeZE44iscussionContentQ qrdfZtypeQUqfntypeZE52esourceQ qrdfZtypeQUqfntypeZWebpageQ qrdfZtypeQUqmarsZManagedE52esourceQ qrdfZtypeQUqwebZInformationE52esourceQ qrdfZtypeQUqwebZPageQ qrdfZtypeQUqwebZE52esourceQ qrdfZtypeQUqrdfsZE52esourceQ