Jump to content


Photo

Need Help Optimizing This Code. :)


  • Please log in to reply
2 replies to this topic

#1 Arthur Yarbrough

Arthur Yarbrough

    GMC Member

  • New Member
  • 14 posts

Posted 26 February 2012 - 06:24 PM

I am making a card game similar to the Pokemon/Yu-Gi-Oh TCGs and I have a question I would like to ask. As of right now, all the cards in the hand and on the field are shown very small, as to all fit on the screen and leave room for other essentials, but when the mouse hovers over them they show as the full-sized version of their card on the right side of the screen. I know how to accomplish this, but my problem is that I worry once many cards are created that my way of doing this will cause major lag in the game.

Right now I have one object for the small card, changing it's sprite according to the sprite value listed in a ds_list deck. I then have a script in the step event that changes the big card's sprite depending on the sprite of the smaller one.

if position_meeting(mouse_x,mouse_y,self)
    {
    if sprite_index = spr_card1
    obj_cardview.sprite_index = spv_card1

Then the last 2 lines repeat for every card, changing each sprite from the small version (with the spr beginning) to the big version (with the spv beginning) It works flawless, but I worry once hundreds if not possibly thousands of cards are added that this code in the step event for the hand slots, and the cards on the field for both players will cause major lag due to all the checks that will have to be done each step.

My plan was to change the cards names where the small card is something like
"spr_card"
and the big card is something like
"bspr_card"
and then somehow program a script that would detect the current sprite_index, and change the big card to be that value with an added b in front so that it changes into the big card instead of the smaller one. Kind of like a "b+sprite_index" (I know that wouldn't work, it was just an example for those who may still not understand.)

Is something like this possible in Game Maker? Does anyone have any suggestions? Am I getting worried for nothing about my original code?
I'd love to hear some input. :)
  • 0

#2 Carcas769

Carcas769

    GMC Member

  • GMC Member
  • 20 posts

Posted 26 February 2012 - 11:56 PM

I needed a system similar to this in making a custom build of solitaire. Try creating an object to follow the mouse and move your check list to a collision event
with mouse_obj. Add a variable to your cards 'enlarge' and change the code in the step event to...

if ( position_meeting(mouse_x,mouse_y,self))
{
enlarge = 1;
exit;
}
else
{
enlarge = 0;
exit;
}

Then set 'if( enlarge = 1 )' as the condition to run the check list in the collision event.
I hope this helps and if there is any conflict with the collision event and step event, you might try 'if ( distance_to_object( mouse_obj) < 1 )' instead of 'position_meeting'
and make sure your FPS are not too low.

Edited by Carcas769, 27 February 2012 - 12:03 AM.

  • 0

#3 Arthur Yarbrough

Arthur Yarbrough

    GMC Member

  • New Member
  • 14 posts

Posted 28 February 2012 - 04:25 AM

I just figured out a way around my huge code if anyone is interested. :D Instead of having 2 sprites per card, a small and a large, I simply changed it to where I now have one large sprite per card. Then the hand and cards on the field are scaled to 1/3 of the size of the large card while the display still remains fully scaled at 1. Then my script is simply a matter of changing the big card display to be the same sprite as used on the card or

if position_meeting(mouse_x,mouse_y,self)
obj_carddisplay.image_single = image_single

and this works for every card. :D Cutting down not only a humongous script into 2 lines, but also cutting out an enormous amount of sprites that are no longer needed.
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users