Please login or register.

Login with username, password and session length
Advanced search  

News:

IRC channel - server: waelisch.de  channel: #wme (read more)

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Topics - warmblood

Pages: [1]
1
Technical forum / Need help with LeftRelease, please
« on: July 12, 2008, 04:17:33 AM »

I have a scene in an educational matching game where I drag and drop entities. (The approach I took was the same as TheDerman's Click and drag sprites topic here: http://forum.dead-code.org/index.php?topic=2269.0 -- the corrected code, of course.) It is slightly different in that If the entity is dropped close enough to the target location, it snaps into place. If it is too far away, it goes back to the original location.

Everything works beautifully EXCEPT sometimes (quite often) the LeftRelease event doesn't seem to trigger, and I'm left with the entity "stuck" to the mouse.  Sometimes I can get it unstuck if I click really fast, or if I go and pick up another entity (since they all use the same LeftButtonIsDown flag.) Sometimes after that the formerly stuck entity will correctly drag and position to the target location, but other times it just lies there, broken.

Has anyone else run into this problem? Any ideas on how I might try to resolve this? I'm not looking for code, just some ideas to try. Thanks!


2
Okay, I've lurked long enough, but I haven't been idle. I've read a lot of the forums, and gone through the tuts, and made my own little test games.

But now I'm stumped. I'm trying to create a mini-game -- essentially memory match (where you turn cards looking for matching pairs).  

 :D  I am able to dynamically create the "card" entities objects (thanks to metaphorium's Going dynamical - Learn by code example: http://forum.dead-code.org/index.php?topic=1821.0).

 :(  Sadly, I think I'm missing something/doing something dumb:

  • I can't control the sprite frames properly -- the first card should show frame 1 when it is turned over, the second should show frame 2, etc. When you click them again, they should show frame 0 (the card back,)  Instead, they start out properly showing frame 0, then end up showing frame 3 or frame 4.
     
  • The frames don't seem to change at all unless I have a Debug(); statement in my Card script so I can step through the code.


If anyone can figure out what I'm doing wrong, I'd really appreciate your help.  (I know I may have to create a seperate sprite for each card face and switch the sprite, but I was hoping to use the frame approach in the example.)

I've ripped out most of the logic in my code and reduced it down to just what is needed to recreate my problem(s). If it would be easier to have the actual example, I have zipped it up, and can email it to you.

1. Created a new game.
2. Created a new scene called MemoryMatch, and make it the starting scene.
3. In the scene, created a sprite called Card. Add five frames (each 60x60 or you have to change the spacing in scene_init). Frame 0 is the card back, and the other frames are the card fronts. Create a script for this sprite containing the following code:

Code: [Select]


#include "scripts\base.inc"


////////////////////////////////////////////////////////////////////////////////
// This is where I suspect the problems are

on "LeftClick"
{

//PROBLEM: if you don't step thru code in debugger, card frames don't appear to change at all.
Debug();  

var entCard = this;
if (entCard.Active == false) return;  // the card is not active, so don't change it

var sprCard = entCard.GetSpriteObject();

if (entCard.currentFrame==0)
{
//The card is face down, so turn it face up.  
//PROBLEM: Can't seem to control the frame of the sprite.
this.sprite = sprCard.Play();
this.sprite = sprCard.GetFrame(entCard.faceFrame);
this.sprite = sprCard.Pause();
entCard.currentFrame=entCard.faceFrame;
}
else
{
//The card is face up, so turn it face down.
//PROBLEM: Can't seem to control the frame of the sprite.
this.sprite = sprCard.Play();
this.sprite = sprCard.GetFrame(0);
this.sprite = sprCard.Pause();
entCard.currentFrame=0;
}
}


// This is called from scene_init to set up the sprite entities.
method InitCard(name, cardNo, posX, posY)
{

// Create dynamic sprite entity
this.Ent = Scene.CreateEntity(name);
var entCard = this.Ent;
entCard.AttachScript("scenes\MemoryMatch\scr\Card.script");

// load Card sprite into the dynamic sprite entity
entCard.SetSprite("scenes\MemoryMatch\Cards\Card.sprite");

// store the card number and face frame
entCard.cardNo=cardNo;
entCard.faceFrame=cardNo;
 
// make card iteractive and non-scalable
entCard.Scalable=false;
entCard.Interactive=true;

//set the current frame to card back (face down).
var sprCard = entCard.GetSpriteObject();
this.sprite = sprCard.GetFrame(0);
this.sprite = sprCard.Pause();
entCard.currentFrame=0;

// position the entity in the scene
entCard.X = posX;
entCard.Y = posY;

// Make sure the card is visible
entCard.Active = true;
}




4. Added the following code to the end of scene_init.script:


Code: [Select]
////////////////////////////////////////////////////////////////////////////////
// Add the cards...

var numCards = 4;  
var posX, posY;
var cardNo, faceFrame;

var cardDeckArray=new Array(numCards);

posY=100;
for (cardNo=0;cardNo<numCards;cardNo=cardNo+1)
{
posX=60 + cardNo*(61);  // change this line if your sprites are bigger than 60 pixels wide
faceFrame=cardNo;

cardDeckArray[cardNo] = new Object("scenes/MemoryMatch/scr/Card.script");  
var tmp = cardDeckArray[cardNo];  

tmp.InitCard("Card" + cardNo, cardNo, posX, posY);

cardDeckArray[cardNo]=tmp;
}


5. When you run the program, four "card" sprite entities will appear site by side, all "face down."  Click on one of the sprite entities and you'll hit the debugger (assuming you have debug turned on and are in window mode). Step through the code for the Left Click event, and the cards should flip face up. But then as you continue stepping the face keeps changing.  Click on the card again, and it is supposed to turn face down, but it doesn't...


Pages: [1]

Page created in 0.037 seconds with 22 queries.